Home » DevOps » Terraform » Terraform Providers

About Yatin

Avatar photo
An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).

Terraform Providers

Hello. In this tutorial, we will learn about Terraform providers.

You can also check this tutorial in the following video:

Terraform Tutorial – video

1. Introduction

Terraform is an open-source tool developed by HashiCorp for building, changing, and versioning the infrastructure safely and efficiently. It is used to manage the infrastructure of the popular cloud service providers and custom in-house solutions. It helps manage both low-level (Compute, Storage, Networking, etc.) and high-level components (such as SaaS, DNS, etc.) Terraform deployment automation is divided into different sections i.e. –

  • IaaC – IaaC is popularly known as the Infrastructure as a Code, describing the infrastructure using a high-level configuration syntax. This allows a blueprint of the infrastructure which can be deployed, versioned, and shared for re-use
  • Execution Plans – Terraform has a planning step where it generates an execution plan. The execution plan tells the administrator what Terraform will do once applied and helps to avoid any surprises when it creates the infrastructure
  • Resource Graph – Terraform builds a graph of all the resources and parallelizes the creation and modification of non-dependent resources. This offers insights into learning the dependencies in their infrastructure
  • Change Automation – Terraform allows to apply of complex changesets to the infrastructure with minimal human intervention

1.1 Steps

To create the infrastructure via the Terraform scripts following commands need to be executed in a sequence. However, details and actions may differ between workflows.

  • terraform init – Initializing the new or existing terraform configuration
  • terraform plan – Generate the execution plan from the resources specified in the file
  • terraform apply – Create the infrastructure from the resources specified in the file
  • terraform destroy – Destroy the created infrastructure
Fig. 1: Terraform workflow

1.2 What is a Terraform provider and what do they do?

A provider in terraform is an executable plugin responsible for understanding API interactions of the services and exposing the resources. It interacts with various api’s required to create, update, and delete various resources. Each provider in terraform adds a set of resources to the configuration file that terraform can manage.

The different types of available providers are –

  • AWS terraform provider
  • Azure terraform provider
  • Oracle cloud infrastructure terraform provider
  • Google cloud terraform provider

Without a provider block in the configuration file terraform cannot manage any infrastructure.

1.2.1 What is a provider block in Terraform?

A provider in terraform is defined by the provider block where the actual arguments of the block vary from provider to provider. A sample aws provider code snippet is given below –

Sample snippet of AWS cloud provider

provider "aws" {
  region     = var.region
  access_key = var.aws_access_key
  secret_key = var.aws_secret_key
}

1.2.2 What is provider workflow?

When the terraform init command is executed the specified provider is downloaded from the Terraform registry and installed into the project’s working directory. The workflow steps are explained below –

  • Initialize the terraform configuration when the terraform init is executed
  • Looks for the used provider and download the provider plug-in from the Terraform registry
  • Retrieves the provider plug-in
  • Stores them in the .terraform subdirectory inside the project’s root directory
  • Check for the default or the specified version

1.3 How to use providers?

Creating a terraform is a simple step where one creates a provider.tf file and adds the required details to it. Let us take a look at the simple provider.tf file I created for an example.

Sample snippet of AWS cloud provider

provider "aws" {
  region     = var.region
  access_key = var.aws_access_key
  secret_key = var.aws_secret_key
}

The values for the provider block fields will be read from a separate variable.tf file. The variables.tf file is used in terraform to provide input variables at runtime for customizing the deployment.

1.4 How to find providers?

Providers are distributed by Terraform and have their release cadence/versioning. Any information about the providers can be obtained from the official terraform documentation available here.

That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!

2. Summary

In this tutorial, we show an introduction to providers in Terraform.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments