本記事ではTerraformでAWSのAccess KeyとSecret Keyを環境変数から取得する方法を紹介します。



Provider: AWS - Terraform by HashiCorp
The Amazon Web Services (AWS) provider is used to interact with the many resources supported by AWS. The provider needs to be configured with the proper credent...

Environment variables
You can provide your credentials via the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, environment variables, representing your AWS Access Key and AWS Secret Key, respectively. Note that setting your AWS credentials using either these (or legacy) environment variables will override the use of AWS_SHARED_CREDENTIALS_FILE and AWS_PROFILE. The AWS_DEFAULT_REGION and AWS_SESSION_TOKEN environment variables are also used, if applicable:

$ export AWS_ACCESS_KEY_ID="anaccesskey"
$ export AWS_SECRET_ACCESS_KEY="asecretkey"
$ export AWS_DEFAULT_REGION="us-west-2"

ドキュメントに記載されているように、 AWS_ACCESS_KEY_IDとAWS_SECRET_ACCESS_KEYの名前で環境変数を設定します。


provider "aws" {}