Terraform on AWS¶
Configure Terraform's plugin cache and the AWS provider's standard environment variables from local AWS configuration files, without placing credentials in the definition file.
Example¶
env-alias:
TF_PLUGIN_CACHE_DIR:
exec: 'mkdir -p "$HOME/.terraform.d/plugin-cache" && printf "%s/.terraform.d/plugin-cache" "$HOME"'
AWS_ACCESS_KEY_ID:
source: '~/.aws/credentials'
parser: 'ini'
selector: 'account_name.aws_access_key_id'
AWS_SECRET_ACCESS_KEY:
source: '~/.aws/credentials'
parser: 'ini'
selector: 'account_name.aws_secret_access_key'
AWS_DEFAULT_REGION:
source: '~/.aws/config'
parser: 'ini'
selector: 'profile account_name.region'
Walkthrough:
TF_PLUGIN_CACHE_DIRcreates the directory and prints its fully expanded path.execuses that stdout value for the export, avoiding a literal unexpanded~path.AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_DEFAULT_REGIONare the standard names read by the AWS provider. Each is selected from the relevant AWS INI file.- Replace
account_namewith an existing profile. This example configures provider credentials; a Terraform input variable would require a matchingvariabledeclaration in your Terraform code.