[DevOps]Infrastructure Provisioning (IaC)Terraform Providers— Deep Dive

Tonytruong
4 min readDec 31, 2022

--

Welcome Back! To another post on Infrastructure Provisioning — with Terraform! If you’ve stumbled across my recent posts I’ve started covering Terraform — at the beginning of the Infrastructure Provisioning Series, following up with our first deep dive into Terraform Basics — Resources. I’m now back with our next deep dive topic:

Terraform Providers

Which by this point, I’m starting to feel a lot like a Terraform Sales Rep but I promise, I love the tool too much to be selling you any snake oil.

In my typical fashion — following our format for the deep dive series, we will be doing a deep dive into Terraform Providers specifically:

  • What is it?
  • Key Concepts
  • Code Examples

What are Terraform Providers?

Terraform providers are plugins that allow Terraform to interact with specific infrastructure platforms or tools. Providers translate the abstract configuration language used by Terraform into API calls and other interactions with the platform, allowing users to manage infrastructure as code.

To use a provider in a Terraform configuration, you must specify the provider block in your code and configure it with the necessary credentials or other information required to authenticate and communicate with the platform. The provider block includes the name of the provider and any required configuration options.

For example, to use the AWS provider, you might specify the following in your configuration:

provider "aws" {
access_key = "ACCESS_KEY"
secret_key = "SECRET_KEY"
region = "us-east-1"
}

Once a provider is configured, you can use it to create, read, update, and delete resources within the platform.

For example, using the AWS provider, you can create EC2 instances, S3 buckets, and other AWS resources.

Terraform comes with a number of built-in providers for popular infrastructure platforms, such as AWS, Azure, Google Cloud, and more. In addition to the built-in providers, you can also create custom providers for interacting with other platforms or tools that are not natively supported by Terraform.

What are some Key Concepts

When working with providers, it is recommended that you begin to familiarize yourself with the following key concepts when you’re beginning to integrate with different providers, setting up provider blocks, or just general knowledge surrounding constructing the YAML file.

Provider blocks
In a Terraform configuration, a provider block specifies the provider to be used and any required configuration options.

Provider configuration
To use a provider, you must configure it with the necessary credentials or other information required to authenticate and communicate with the platform.

Built-in providers:
Terraform comes with a number of built-in providers for popular infrastructure platforms, such as AWS, Azure, and Google Cloud.

Custom providers
In addition to the built-in providers, you can also create custom providers for interacting with other platforms or tools that are not natively supported by Terraform.

Provider-specific configuration options:
The provider an attribute in resource blocks allows you to specify provider-specific options for a particular resource.

Provider version constraints:
You can specify a version constraint in your provider block to ensure that you are using a compatible version of the provider.

Provider initialization
When you run terraform init, Terraform will download and install the necessary plugins for any providers specified in your configuration.

Provider dependencies
Some resources may depend on other resources managed by the same provider, in which case the provider must be able to track these dependencies in order to create and manage the resources in the correct order.

Code Examples

Below are a few quick examples of how you can start constructing your own Terraform Provider Code Blocks!

AWS Provider

provider "aws" {
access_key = "ACCESS_KEY"
secret_key = "SECRET_KEY"
region = "us-east-1"
}

Azure Provider

provider "azurerm" {
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
tenant_id = "TENANT_ID"
subscription_id = "SUBSCRIPTION_ID"
}

GCP Provider

provider "google" {
credentials = file("service-account.json")
project = "my-project"
region = "us-central1"
}

Custom Provider

provider "my-provider" {
api_key = "API_KEY"
}

Overall, Terraform providers are a key component of the Terraform ecosystem, allowing users to manage infrastructure as code across a wide range of platforms and tools. That finalizes our deep dive into Terraform Providers.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author, consider giving me a follow to keep up with this series. 👇

--

--

Tonytruong

DevOps Fanatic with a penchant to automate anything and everything — Terraform Nerd, Docker practitioner and self proclaimed AWS guru.