To make Terraform to read the AWS credential file, you can follow these steps:
1. Create an AWS credential file:
On a Linux or macOS system, create the file at ~/.aws/credentials.
On a Windows system, create the file at C:\Users\USERNAME\.aws\credentials.
In the file, add the following lines, replacing the ACCESS_KEY and SECRET_KEY with your AWS access key and secret key:
[default]
aws_access_key_id = ACCESS_KEY
aws_secret_access_key = SECRET_KEY
aws_access_key_id = ACCESS_KEY
aws_secret_access_key = SECRET_KEY
2. Set the AWS_REGION environment variable to the region you want to use. You can do this by running the following command in your terminal:
export AWS_REGION=us-west-2
3. In your Terraform configuration file, add the following code to read the AWS credentials from the file:
provider "aws" {
region = "${var.region}"
shared_credentials_file = "/Users/USERNAME/.aws/credentials"
profile = "default"
}
region = "${var.region}"
shared_credentials_file = "/Users/USERNAME/.aws/credentials"
profile = "default"
}
This assumes that the credential file is located at /Users/USERNAME/.aws/credentials. If you have placed the file in a different location, replace the file path accordingly.
Note that the profile parameter in the provider block corresponds to the section name in the AWS credential file. In the example above, the section name is [default].
Once you have completed these steps, Terraform should be able to read your AWS credentials from the credential file and use them to authenticate with AWS.
Comments (0)