TerraWeek Day 6: Terraform Providers
Aashish R.
????System Engineer at Tata Consultancy Services | DevOps | Terraform | Kubernetes | Ansible | Jenkins | CI/CD | ??AWS | Docker | Grafana | GitHub | Linux |
Introduction
In this blog, we will explore the concept of Terraform providers, compare major cloud providers such as AWS, Azure, and Google Cloud, delve into provider configuration and authentication, and provide insights on working with each provider.
Terraform Providers
Terraform providers are plugins that enable Terraform to interact with various cloud platforms, infrastructure services, and APIs. Providers are responsible for understanding API interactions and exposing resources that can be managed using Terraform. Some popular providers include AWS, Azure, Google Cloud, and others.
To use a provider, you need to declare it in your Terraform configuration file (usually a .tf file). Here's an example of the AWS provider:
provider "aws" {
region = "ap-south-1"
}
Comparing Providers
Terraform providers are plugins that allow Terraform to interact with various cloud platforms and infrastructure services. They are responsible for understanding API interactions and exposing resources to be managed by Terraform. Some popular Terraform cloud providers include:
Azure: Terraform Azure Provider
Google Cloud: Terraform Google Cloud Provider
Each provider has its own set of supported resources and features. To compare them, visit the respective provider's documentation and explore the available resources and data sources.
Provider Configuration and Authentication
Each provider has its own set of configuration options, which are used to authenticate and interact with the respective cloud platform or service. These options can include API keys, access tokens, or other credentials required for authentication.
For example, the AWS provider necessitates an access key and secret key for authentication. You can provide these credentials through various means, including environment variables, a shared credentials file, or directly within the provider configuration block:
provider "aws" {
region = "ap-south-1"
access_key = "your_access_key"
secret_key = "your_secret_key"
}
Use environment variables or shared credentials files to avoid exposing sensitive information in your Terraform configuration files.
Working with AWS Provider
The AWS provider allows you to manage resources in your AWS account. declare the AWS provider in your Terraform configuration file:
provider "aws" {
region = "ap-south-1"
}
create an Amazon S3 bucket using the AWS provider:
领英推荐
resource "aws_s3_bucket" "mera_balati" {
bucket = "my-exp_2023-bucket"
acl = "private"
}
Run terraform init to initialize your Terraform working directory and download the required provider plugins. Then, run terraform plan, terraform apply to generate a plan of action and then create the S3 bucket.
Working with Azure Provider
The Azure provider allows you to manage resources in your Azure account. To get started, declare the Azure provider in your Terraform configuration file:
provider "azurerm" {
features {}
}
Let's create a resource group utilizing the Azure provider.
resource "azurerm_resource_group" "example" {
name = "my-resource-group"
location = "West US"
}
After defining resources run below commands:
terraform init
terraform plan
terraform apply
Working with Google Cloud Provider
The Google Cloud provider allows you to manage resources in your Google Cloud account. To get started, declare the Google Cloud provider in your Terraform configuration file:
provider "google" {
project = "my-terra-project"
region = "us-central1"
zone = "us-central1-a"
}
Let's create a Google Cloud Storage bucket using the Google Cloud provider:
resource "google_storage_bucket" "terraweek-bucket" {
name = "my-terra-bucket"
location = "us-central1"
storage_class = "STANDARD"
}
To defining the resources run below commands to create the storage bucket.:
terraform init
terraform plan
terraform apply
Happy Learning!!
Data Governance | Snowflake | Microsoft PowerApps | Microsoft Power Automate | Microsoft PowerBI | Alation | Immuta | Airflow | SQL | Python | AWS | Terraform | Docker
1 年Hey Aashish R. , Glad to hear that you have started working on terraform; I would like to share with you everything you need to know about the terraform. You can access my GitHub repo and all the resources I have covered in terraform from basic to advanced and I hope that would help you to prep for the certification journey as well in your enhancing the skills. Link: https://github.com/sahdevgrover