3 Ways to Configure Terraform to use your AWS Account
<p>There are basically 3 different approaches you can use to allow Terraform to connect and authenticate successfully to AWS.</p>
<p><strong>For your consideration:</strong></p>
<p>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.</p>
<h1>Approach #1: Embed credentials directly into the Terraform template file</h1>
<pre>
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"
}</pre>
<p>In the above <code>main.tf</code> file, you can simply add your AWS account’s credentials in the <code>access_key</code> and <code>secret_key</code> properties which Terraform would use when connecting to your AWS account.</p>
<p><a href="https://banhawy.medium.com/3-ways-to-configure-terraform-to-use-your-aws-account-fb00a08ded5"><strong>Learn More</strong></a></p>