github.com/ves/terraform@v0.8.0-beta2/website/source/docs/providers/aws/index.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "Provider: AWS" 4 sidebar_current: "docs-aws-index" 5 description: |- 6 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. 7 --- 8 9 # AWS Provider 10 11 The Amazon Web Services (AWS) provider is used to interact with the 12 many resources supported by AWS. The provider needs to be configured 13 with the proper credentials before it can be used. 14 15 Use the navigation to the left to read about the available resources. 16 17 ## Example Usage 18 19 ``` 20 # Configure the AWS Provider 21 provider "aws" { 22 access_key = "${var.aws_access_key}" 23 secret_key = "${var.aws_secret_key}" 24 region = "us-east-1" 25 } 26 27 # Create a web server 28 resource "aws_instance" "web" { 29 ... 30 } 31 ``` 32 33 ## Authentication 34 35 The AWS provider offers flexible means of providing credentials for 36 authentication. The following methods are supported, in this order, and 37 explained below: 38 39 - Static credentials 40 - Environment variables 41 - Shared credentials file 42 - EC2 Role 43 44 ### Static credentials ### 45 46 Static credentials can be provided by adding an `access_key` and `secret_key` in-line in the 47 aws provider block: 48 49 Usage: 50 51 ``` 52 provider "aws" { 53 region = "us-west-2" 54 access_key = "anaccesskey" 55 secret_key = "asecretkey" 56 } 57 ``` 58 59 ###Environment variables 60 61 You can provide your credentials via `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, 62 environment variables, representing your AWS Access Key and AWS Secret Key, respectively. 63 `AWS_DEFAULT_REGION` and `AWS_SESSION_TOKEN` are also used, if applicable: 64 65 ``` 66 provider "aws" {} 67 ``` 68 69 Usage: 70 71 ``` 72 $ export AWS_ACCESS_KEY_ID="anaccesskey" 73 $ export AWS_SECRET_ACCESS_KEY="asecretkey" 74 $ export AWS_DEFAULT_REGION="us-west-2" 75 $ terraform plan 76 ``` 77 78 ###Shared Credentials file 79 80 You can use an AWS credentials file to specify your credentials. The default 81 location is `$HOME/.aws/credentials` on Linux and OSX, or `"%USERPROFILE%\.aws\credentials"` 82 for Windows users. If we fail to detect credentials inline, or in the 83 environment, Terraform will check this location. You can optionally specify a 84 different location in the configuration by providing `shared_credentials_file`, 85 or in the environment with the `AWS_SHARED_CREDENTIALS_FILE` variable. This 86 method also supports a `profile` configuration and matching `AWS_PROFILE` 87 environment variable: 88 89 Usage: 90 91 ``` 92 provider "aws" { 93 region = "us-west-2" 94 shared_credentials_file = "/Users/tf_user/.aws/creds" 95 profile = "customprofile" 96 } 97 ``` 98 99 ###EC2 Role 100 101 If you're running Terraform from an EC2 instance with IAM Instance Profile 102 using IAM Role, Terraform will just ask 103 [the metadata API](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials) 104 endpoint for credentials. 105 106 This is a preferred approach over any other when running in EC2 as you can avoid 107 hardcoding credentials. Instead these are leased on-the-fly by Terraform 108 which reduces the chance of leakage. 109 110 You can provide custom metadata API endpoint via `AWS_METADATA_ENDPOINT` variable 111 which expects the endpoint URL including the version 112 and defaults to `http://169.254.169.254:80/latest`. 113 114 ###Assume role 115 116 If provided with a role ARN, Terraform will attempt to assume this role 117 using the supplied credentials. 118 119 Usage: 120 121 ``` 122 provider "aws" { 123 assume_role { 124 role_arn = "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME" 125 session_name = "SESSION_NAME" 126 external_id = "EXTERNAL_ID" 127 } 128 } 129 ``` 130 131 ## Argument Reference 132 133 The following arguments are supported in the `provider` block: 134 135 * `access_key` - (Optional) This is the AWS access key. It must be provided, but 136 it can also be sourced from the `AWS_ACCESS_KEY_ID` environment variable, or via 137 a shared credentials file if `profile` is specified. 138 139 * `secret_key` - (Optional) This is the AWS secret key. It must be provided, but 140 it can also be sourced from the `AWS_SECRET_ACCESS_KEY` environment variable, or 141 via a shared credentials file if `profile` is specified. 142 143 * `region` - (Required) This is the AWS region. It must be provided, but 144 it can also be sourced from the `AWS_DEFAULT_REGION` environment variables, or 145 via a shared credentials file if `profile` is specified. 146 147 * `profile` - (Optional) This is the AWS profile name as set in the shared credentials 148 file. 149 150 * `assume_role` - (Optional) An `assume_role` block (documented below). Only one 151 `assume_role` block may be in the configuration. 152 153 * `shared_credentials_file` = (Optional) This is the path to the shared credentials file. 154 If this is not set and a profile is specified, ~/.aws/credentials will be used. 155 156 * `token` - (Optional) Use this to set an MFA token. It can also be sourced 157 from the `AWS_SESSION_TOKEN` environment variable. 158 159 * `max_retries` - (Optional) This is the maximum number of times an API call is 160 being retried in case requests are being throttled or experience transient failures. 161 The delay between the subsequent API calls increases exponentially. 162 163 * `allowed_account_ids` - (Optional) List of allowed AWS account IDs (whitelist) 164 to prevent you mistakenly using a wrong one (and end up destroying live environment). 165 Conflicts with `forbidden_account_ids`. 166 167 * `forbidden_account_ids` - (Optional) List of forbidden AWS account IDs (blacklist) 168 to prevent you mistakenly using a wrong one (and end up destroying live environment). 169 Conflicts with `allowed_account_ids`. 170 171 * `insecure` - (Optional) Optional) Explicitly allow the provider to 172 perform "insecure" SSL requests. If omitted, default value is `false` 173 174 * `dynamodb_endpoint` - (Optional) Use this to override the default endpoint 175 URL constructed from the `region`. It's typically used to connect to 176 dynamodb-local. 177 178 * `kinesis_endpoint` - (Optional) Use this to override the default endpoint 179 URL constructed from the `region`. It's typically used to connect to 180 kinesalite. 181 182 * `skip_credentials_validation` - (Optional) Skip the credentials validation via STS API. 183 Useful for AWS API implementations that do not have STS available/implemented. 184 185 * `skip_requesting_account_id` - (Optional) Skip requesting the account ID. 186 Useful for AWS API implementations that do not have IAM/STS API and/or metadata API. 187 `true` (enabling this option) prevents you from managing any resource that requires Account ID to construct an ARN, e.g. 188 - `aws_db_instance` 189 - `aws_db_option_group` 190 - `aws_db_parameter_group` 191 - `aws_db_security_group` 192 - `aws_db_subnet_group` 193 - `aws_elasticache_cluster` 194 - `aws_glacier_vault` 195 - `aws_rds_cluster` 196 - `aws_rds_cluster_instance` 197 - `aws_rds_cluster_parameter_group` 198 - `aws_redshift_cluster` 199 200 * `skip_metadata_api_check` - (Optional) Skip the AWS Metadata API check. 201 Useful for AWS API implementations that do not have a metadata API endpoint. 202 `true` prevents Terraform from authenticating via Metadata API - i.e. you may need to use other auth methods 203 (static credentials set as ENV vars or config) 204 205 * `s3_force_path_style` - (Optional) set this to true to force the request to use 206 path-style addressing, i.e., http://s3.amazonaws.com/BUCKET/KEY. By default, the 207 S3 client will use virtual hosted bucket addressing when possible 208 (http://BUCKET.s3.amazonaws.com/KEY). Specific to the Amazon S3 service. 209 210 The nested `assume_role` block supports the following: 211 212 * `role_arn` - (Required) The ARN of the role to assume. 213 214 * `session_name` - (Optional) The session name to use when making the 215 AssumeRole call. 216 217 * `external_id` - (Optional) The external ID to use when making the 218 AssumeRole call. 219 220 Nested `endpoints` block supports the following: 221 222 * `iam` - (Optional) Use this to override the default endpoint 223 URL constructed from the `region`. It's typically used to connect to 224 custom iam endpoints. 225 226 * `ec2` - (Optional) Use this to override the default endpoint 227 URL constructed from the `region`. It's typically used to connect to 228 custom ec2 endpoints. 229 230 * `elb` - (Optional) Use this to override the default endpoint 231 URL constructed from the `region`. It's typically used to connect to 232 custom elb endpoints. 233 234 * `s3` - (Optional) Use this to override the default endpoint 235 URL constructed from the `region`. It's typically used to connect to 236 custom s3 endpoints. 237 238 ## Getting the Account ID 239 240 If you use either `allowed_account_ids` or `forbidden_account_ids`, 241 Terraform uses several approaches to get the actual account ID 242 in order to compare it with allowed/forbidden ones. 243 244 Approaches differ per auth providers: 245 246 * EC2 instance w/ IAM Instance Profile - [Metadata API](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) 247 is always used. Introduced in Terraform `0.6.16`. 248 * All other providers (ENV vars, shared creds file, ...) 249 will try two approaches in the following order 250 * `iam:GetUser` - typically useful for IAM Users. It also means 251 that each user needs to be privileged to call `iam:GetUser` for themselves. 252 * `sts:GetCallerIdentity` - _Should_ work for both IAM Users and federated IAM Roles, 253 introduced in Terraform `0.6.16`. 254 * `iam:ListRoles` - this is specifically useful for IdP-federated profiles 255 which cannot use `iam:GetUser`. It also means that each federated user 256 need to be _assuming_ an IAM role which allows `iam:ListRoles`. 257 Used in Terraform `0.6.16+`. 258 There used to be no better way to get account ID out of the API 259 when using federated account until `sts:GetCallerIdentity` was introduced.