AWS CLI credentials¶
Using the AWS CLI ~/.aws/credentials file.
The Shared Credentials method involves using the AWS CLI’s credentials file, typically located at ~/.aws/credentials
(or C:\Users\USERNAME\.aws\credentials
on Windows). This method is useful when you're already using AWS CLI and it helps you avoid hardcoding sensitive data in your scripts.
Example
First, set up your credentials file using the AWS CLI. Open the command prompt and run the following command:
Enter your AWS Access Key ID and Secret Access Key when prompted. The AWS CLI will save these credentials in a file.
Next, define the AWS provider in your Terraform script. Terraform will automatically source your credentials from the AWS CLI configuration files:
If you've set up multiple profiles for AWS CLI, you can specify which profile to use in your Terraform scripts like this:
In this example, replace "customprofile"
with the name of the profile you want to use from your AWS CLI configuration.