This is an old revision of the document!
Terraform
Automation of infrastructure via code.
Provider Configuration
Generic Provider
AWS
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 credentials before it can be used.
# Configure the AWS Provider provider "aws" { version = "~> 2.0" region = "us-east-1" } # Create a VPC resource "aws_vpc" "example" { cidr_block = "10.0.0.0/16" }
Static Credentials
You can provide static credentials by adding an access_key
and secret_key
in-line in the AWS provider block:
provider "aws" { region = "us-west-2" access_key = "my-access-key" secret_key = "my-secret-key" }
Environment Variables
You can also 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:
provider "aws" {}
To create the environment variables, enter into shell:
$ export AWS_ACCESS_KEY_ID="anaccesskey" $ export AWS_SECRET_ACCESS_KEY="asecretkey" $ export AWS_DEFAULT_REGION="us-west-2" $ terraform plan
Shared Credentials File
You can use an AWS credentials file to specify your credentials. The default location is $HOME/.aws/credentials
on Linux and OS X, or “%USERPROFILE%\.aws\credentials”
for Windows users. If we fail to detect credentials inline, or in the environment, Terraform will check this location. You can optionally specify a different location in the configuration by providing the shared_credentials_file
attribute, or in the environment with the AWS_SHARED_CREDENTIALS_FILE
variable. This method also supports a profile configuration and matching AWS_PROFILE
environment variable:
provider "aws" { region = "us-west-2" shared_credentials_file = "/Users/tf_user/.aws/creds" profile = "customprofile" }
If specifying the profile through the AWS_PROFILE
environment variable, you may also need to set AWS_SDK_LOAD_CONFIG
to a truthy value (e.g. AWS_SDK_LOAD_CONFIG=1
) for advanced AWS client configurations, such as profiles that use the source_profile
or role_arn
configurations.
Selected Documentation
- Provider: AWS - Argument Reference - These arguments, along with the generic provider arguments, are supported in the AWS Provider block