SIVA 99

Terraform Providers

What are the terraform providers ?

Provider Configuration

When you use Terraform, you need to tell it which cloud providers you want to use. This information is called the "provider configuration." You can put this information in any file that ends in .tf, but it's best to put it in a file called main.tf, providers.tf, or versions.tf. This way, all the other parts of your Terraform project can use the same provider information. And you have to make sure the provider configuration is in the main or root module of your Terraform project.

When you use the AWS provider in Terraform, you can add extra information to tell Terraform how to connect to your AWS account. This information is called the "provider block." You don't have to include this information, but it can help Terraform work better. Some of the things you can include in the provider block are your AWS login information, the region where you want to create resources, and an IAM role. These options are specific to AWS and are optional.

From the Terraform docs, there are a number of ways to authenticate using the AWS provider. Configuration for the AWS Provider can be derived from several sources, which are applied in the following order:

We will show different ways to give information to Terraform, like using parameters or environment variables, when you set up the provider configuration. These are the most common methods people use.

However, before we can authenticate, we will need to create an access key for use with Terraform. Browse to the IAM section in the AWS console and ‘create new access key’.

Check How to create user in the AWS IAM Blog. (Click Here -->)

Note : A better way to give login information to Terraform when you use AWS is to use the AWS Command Line Interface (CLI) instead of the provider options. First, you have to install the AWS CLI on your computer. Then, you can type "aws configure" to set up your login information. This is the usual and recommended way to do it.

Check How to install AWs CLI. (Click Here -->) & configure it In Git Bash.

You can then enter your access key ID, secret access key, and default region.

Parameters in the provider configuration

To specify parameters in the provider configuration, we can set an access key and secret key as follows:

provider "aws" {
  region     = "us-west-2"
  access_key = "my-access-key"
  secret_key = "my-secret-key"
}

It's not safe to include sensitive information like login details directly in the Terraform configuration files and then upload them to a source control. If someone gets access to those files, they will also get access to your secret information. So, it's not recommended.

Best Pratices For AWS Provider :

terraform {
    version  = 0.13 
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "4.47.0"
    }
  }
}

provider "aws" {
  region = "us-east-2"
  profile = "sivakrishna"
  
}

Key points about Version :

Liked This Article?

Conclusion:

You will learn in this blog what are providers, what it do & best pratices of providers.

Leave a Reply

Your email address will not be published. Required fields are marked *