For system, network and cloud administrators
Terraform is a wonderful IaaC software. We can login into AWS in a couple of ways:
provider "aws" {
region = "us-west-2"
access_key = "your-access-key-from-the-AWS-account"
secret_key = "your-secret-key-from-the-AWS-account"
}
Basically, what happens in the above example is that Terraform will log you into AWS using the provider plugin which require your access and secret keys – these are part of a different story.
During the execution of the terraform init command, there is also a possibility to get logged in AWS during that Terraform project initialization. One straightforward code example can just use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY:
AWS_ACCESS_KEY_ID="this-is-your-access-key" AWS_SECRET_ACCESS_KEY="this-is-your-secret-key" terraform init
Or you can export your AWS credentials before executing any terraform plan or terraform apply commands like so:
export AWS_ACCESS_KEY_ID="AKIAXSKLCRINE3TY5FIZ"
export AWS_SECRET_ACCESS_KEY="uH9bQZ2tyD8b/chYxY52emJp036HBMwww6d6eaun"
Another format used to log in AWS during the project initialization is by using the -backend-config option:
terraform init -backend-config="access_key=this-is-your-access-key" -backend-config="secret_key=this-is-your-secret-key"