3 Ways to Configure Terraform to use your AWS Account

There are basically 3 different approaches you can use to allow Terraform to connect and authenticate successfully to AWS.

For your consideration:

It is advisable that you create a dedicated set of AWS credentials from the IAM console with programmatic access for your Terraform CLI. Make sure you grant least privileged based permissions, instead of full admin access, to limit the potential blast radius of Terraform.

Approach #1: Embed credentials directly into the Terraform template file

terraform {
    required_providers {
      aws = {
        source = "hashicorp/aws"
        version = "~> 4.0.0"
      }
    }
}

provider "aws" {
    region = "us-east-1"
    access_key = "your_aws_access_key"
    secret_key = "your_aws_secret_access_key"
}

In the above main.tf file, you can simply add your AWS account’s credentials in the access_key and secret_key properties which Terraform would use when connecting to your AWS account.

Learn More

Tags: Account AWS