layout | page_title | description |
---|---|---|
aws |
Provider: Appflow for AWS |
AWS provider for Appflow, introducing several improvements compared to the official AWS provider by Hashicorp.
Use this provider with SAP OData and S3 connectors. |
AWS provider for Appflow, introducing several improvements compared to the official AWS provider by Hashicorp.
Use this provider with SAP OData and S3 connectors.
🇮🇱 We Stand with Israel! 🇮🇱
Terraform 0.13 and later:
terraform {
required_providers {
aws = {
source = "cloudbuzzbyone/appflow"
version = "~> 0.1"
}
}
}
# Configure the AWS Provider
provider "aws" {
region = "eu-west-1"
}
# Create a flow
resource "aws_flow" "example" {
flow_name = "example
}
Configuration for the AWS Provider can be derived from several sources, which are applied in the following order:
- Parameters in the provider configuration
- Environment variables
- Shared credentials files
- Shared configuration files
- Container credentials
- Instance profile credentials and region
This order matches the precedence used by the AWS CLI and the AWS SDKs.
The AWS Provider supports assuming an IAM role, either in
the provider configuration block parameter assume_role
or in a named profile.
The AWS Provider supports assuming an IAM role using web identity federation and OpenID Connect (OIDC). This can be configured either using environment variables or in a named profile.
When using a named profile, the AWS Provider also supports sourcing credentials from an external process.
!> Warning: Hard-coded credentials are not recommended in any Terraform configuration and risks secret leakage should this file ever be committed to a public version control system.
Credentials can be provided by adding an access_key
, secret_key
, and optionally token
, to the aws
provider block.
Usage:
provider "aws" {
region = "us-west-2"
access_key = "my-access-key"
secret_key = "my-secret-key"
}
Other settings related to authorization can be configured, such as:
profile
shared_config_files
shared_credentials_files
Credentials can be provided by using the AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
, and optionally AWS_SESSION_TOKEN
environment variables.
The region can be set using the AWS_REGION
or AWS_DEFAULT_REGION
environment variables.
For example:
provider "aws" {}
% export AWS_ACCESS_KEY_ID="anaccesskey"
% export AWS_SECRET_ACCESS_KEY="asecretkey"
% export AWS_REGION="us-west-2"
% terraform plan
Other environment variables related to authorization are:
AWS_PROFILE
AWS_CONFIG_FILE
AWS_SHARED_CREDENTIALS_FILE
The AWS Provider can source credentials and other settings from the shared configuration and credentials files.
By default, these files are located at $HOME/.aws/config
and $HOME/.aws/credentials
on Linux and macOS,
and "%USERPROFILE%\.aws\config"
and "%USERPROFILE%\.aws\credentials"
on Windows.
If no named profile is specified, the default
profile is used.
Use the profile
parameter or AWS_PROFILE
environment variable to specify a named profile.
The locations of the shared configuration and credentials files can be configured using either
the parameters shared_config_files
and shared_credentials_files
or the environment variables AWS_CONFIG_FILE
and AWS_SHARED_CREDENTIALS_FILE
.
For example:
provider "aws" {
shared_config_files = ["/Users/tf_user/.aws/conf"]
shared_credentials_files = ["/Users/tf_user/.aws/creds"]
profile = "customprofile"
}
If you're running Terraform on CodeBuild or ECS and have configured an IAM Task Role, Terraform can use the container's Task Role. This support is based on the underlying AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
and AWS_CONTAINER_CREDENTIALS_FULL_URI
environment variables being automatically set by those services or manually for advanced usage.
If you're running Terraform on EKS and have configured IAM Roles for Service Accounts (IRSA), Terraform can use the pod's role. This support is based on the underlying AWS_ROLE_ARN
and AWS_WEB_IDENTITY_TOKEN_FILE
environment variables being automatically set by Kubernetes or manually for advanced usage.
When the AWS Provider is running on an EC2 instance with an IAM Instance Profile set, the provider can source credentials from the EC2 Instance Metadata Service. Both IMDS v1 and IMDS v2 are supported.
A custom endpoint for the metadata service can be provided using the ec2_metadata_service_endpoint
parameter or the AWS_EC2_METADATA_SERVICE_ENDPOINT
environment variable.
If provided with a role ARN, the AWS Provider will attempt to assume this role using the supplied credentials.
Usage:
provider "aws" {
assume_role {
role_arn = "arn:aws:iam::123456789012:role/ROLE_NAME"
session_name = "SESSION_NAME"
external_id = "EXTERNAL_ID"
}
}
Hands-on: Try the Use AssumeRole to Provision AWS Resources Across Accounts tutorial.
If provided with a role ARN and a token from a web identity provider, the AWS Provider will attempt to assume this role using the supplied credentials.
Usage:
provider "aws" {
assume_role_with_web_identity {
role_arn = "arn:aws:iam::123456789012:role/ROLE_NAME"
session_name = "SESSION_NAME"
web_identity_token_file = "/Users/tf_user/secrets/web-identity-token"
}
}
To use an external process to source credentials,
the process must be configured in a named profile, including the default
profile.
The profile is configured in a shared configuration file.
For example:
provider "aws" {
profile = "customprofile"
}
[profile customprofile]
credential_process = custom-process --username jdoe
Setting | Provider | Environment Variable | Shared Config |
---|---|---|---|
Access Key ID | access_key |
AWS_ACCESS_KEY_ID |
aws_access_key_id |
Secret Access Key | secret_key |
AWS_SECRET_ACCESS_KEY |
aws_secret_access_key |
Session Token | token |
AWS_SESSION_TOKEN |
aws_session_token |
Region | region |
AWS_REGION or AWS_DEFAULT_REGION |
region |
Custom CA Bundle | custom_ca_bundle |
AWS_CA_BUNDLE |
ca_bundle |
EC2 IMDS Endpoint | ec2_metadata_service_endpoint |
AWS_EC2_METADATA_SERVICE_ENDPOINT |
N/A |
EC2 IMDS Endpoint Mode | ec2_metadata_service_endpoint_mode |
AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE |
N/A |
Disable EC2 IMDS | skip_metadata_api_check |
AWS_EC2_METADATA_DISABLED |
N/A |
HTTP Proxy | http_proxy |
HTTP_PROXY or HTTPS_PROXY |
N/A |
Max Retries | max_retries |
AWS_MAX_ATTEMPTS |
max_attempts |
Profile | profile |
AWS_PROFILE or AWS_DEFAULT_PROFILE |
N/A |
Retry Mode | retry_mode |
AWS_RETRY_MODE |
retry_mode |
Shared Config Files | shared_config_files |
AWS_CONFIG_FILE |
N/A |
Shared Credentials Files | shared_credentials_files |
AWS_SHARED_CREDENTIALS_FILE |
N/A |
S3 Use Regional Endpoint for eu-west-1 |
s3_eu_west_1_regional_endpoint |
AWS_S3_eu_west_1_REGIONAL_ENDPOINT |
s3_eu_west_1_regional_endpoint |
Use DualStack Endpoints | use_dualstack_endpoint |
AWS_USE_DUALSTACK_ENDPOINT |
use_dualstack_endpoint |
Use FIPS Endpoints | use_fips_endpoint |
AWS_USE_FIPS_ENDPOINT |
use_fips_endpoint |
Configuation for assuming an IAM role can be done using provider configuration or a named profile in shared configuration files.
In the provider, all parameters for assuming an IAM role are set in the assume_role
block.
Note that environment variables are not supported for assuming IAM roles.
See the assume role documentation for more information.
Setting | Provider | Shared Config |
---|---|---|
Role ARN | role_arn |
role_arn |
Duration | duration |
duration_seconds |
External ID | external_id |
external_id |
Policy | policy |
N/A |
Policy ARNs | policy_arns |
N/A |
Session Name | session_name |
role_session_name |
Source Identity | source_identity |
N/A |
Tags | tags |
N/A |
Transitive Tag Keys | transitive_tag_keys |
N/A |
Configuration for assuming an IAM role using web identify federation can be done using provider configuration, environment variables, or a named profile in shared configuration files.
In the provider, all parameters for assuming an IAM role are set in the assume_role_with_web_identity
block.
See the assume role documentation section on web identities for more information.
Setting | Provider | Environment Variable | Shared Config |
---|---|---|---|
Role ARN | role_arn |
AWS_ROLE_ARN |
role_arn |
Web Identity Token | web_identity_token |
N/A | N/A |
Web Identity Token File | web_identity_token_file |
AWS_WEB_IDENTITY_TOKEN_FILE |
web_identity_token_file |
Duration | duration |
N/A | duration_seconds |
Policy | policy |
N/A | policy |
Policy ARNs | policy_arns |
N/A | policy_arns |
Session Name | session_name |
AWS_ROLE_SESSION_NAME |
role_session_name |
By default, the underlying AWS client used by the Terraform AWS Provider creates requests with User-Agent headers including information about Terraform and AWS SDK for Go versions. To provide additional information in the User-Agent headers, the TF_APPEND_USER_AGENT
environment variable can be set and its value will be directly added to HTTP requests. E.g.,
% export TF_APPEND_USER_AGENT="JenkinsAgent/i-12345678 BuildID/1234 (Optional Extra Information)"
In addition to generic provider
arguments
(e.g., alias
and version
), the following arguments are supported in the AWS
provider
block:
access_key
- (Optional) AWS access key. Can also be set with theAWS_ACCESS_KEY_ID
environment variable, or via a shared credentials file ifprofile
is specified. See alsosecret_key
.allowed_account_ids
- (Optional) List of allowed AWS account IDs to prevent you from mistakenly using an incorrect one (and potentially end up destroying a live environment). Conflicts withforbidden_account_ids
.assume_role
- (Optional) Configuration block for assuming an IAM role. See theassume_role
Configuration Block section below. Only oneassume_role
block may be in the configuration.assume_role_with_web_identity
- (Optional) Configuration block for assuming an IAM role using a web identity. See theassume_role_with_web_identity
Configuration Block section below. Only oneassume_role_with_web_identity
block may be in the configuration.custom_ca_bundle
- (Optional) File containing custom root and intermediate certificates. Can also be set using theAWS_CA_BUNDLE
environment variable. Settingca_bundle
in the shared config file is not supported.default_tags
- (Optional) Configuration block with resource tag settings to apply across all resources handled by this provider (see the Terraform multiple provider instances documentation for more information about additional provider configurations). This is designed to replace redundant per-resourcetags
configurations. Provider tags can be overridden with new values, but not excluded from specific resources. To override provider tag values, use thetags
argument within a resource to configure new tag values for matching keys. See thedefault_tags
Configuration Block section below for example usage and available arguments. This functionality is supported in all resources that implementtags
, with the exception of theaws_autoscaling_group
resource.ec2_metadata_service_endpoint
- (Optional) Address of the EC2 metadata service (IMDS) endpoint to use. Can also be set with theAWS_EC2_METADATA_SERVICE_ENDPOINT
environment variable.ec2_metadata_service_endpoint_mode
- (Optional) Mode to use in communicating with the metadata service. Valid values areIPv4
andIPv6
. Can also be set with theAWS_EC2_METADATA_SERVICE_ENDPOINT_MODE
environment variable.endpoints
- (Optional) Configuration block for customizing service endpoints. See the Custom Service Endpoints Guide for more information about connecting to alternate AWS endpoints or AWS compatible solutions. See alsouse_fips_endpoint
.forbidden_account_ids
- (Optional) List of forbidden AWS account IDs to prevent you from mistakenly using the wrong one (and potentially end up destroying a live environment). Conflicts withallowed_account_ids
.http_proxy
- (Optional) Address of an HTTP proxy to use when accessing the AWS API. Can also be set using theHTTP_PROXY
orHTTPS_PROXY
environment variables.ignore_tags
- (Optional) Configuration block with resource tag settings to ignore across all resources handled by this provider (except any individual service tag resources such asaws_ec2_tag
) for situations where external systems are managing certain resource tags. Arguments to the configuration block are described below in theignore_tags
Configuration Block section. See the Terraform multiple provider instances documentation for more information about additional provider configurations.insecure
- (Optional) Whether to explicitly allow the provider to perform "insecure" SSL requests. If omitted, the default value isfalse
.max_retries
- (Optional) Maximum number of times an API call is retried when AWS throttles requests or you experience transient failures. The delay between the subsequent API calls increases exponentially. If omitted, the default value is25
. Can also be set using the environment variableAWS_MAX_ATTEMPTS
and the shared configuration parametermax_attempts
.profile
- (Optional) AWS profile name as set in the shared configuration and credentials files. Can also be set using either the environment variablesAWS_PROFILE
orAWS_DEFAULT_PROFILE
.region
- (Optional) AWS region where the provider will operate. The region must be set. Can also be set with either theAWS_REGION
orAWS_DEFAULT_REGION
environment variables, or via a shared config file parameterregion
ifprofile
is used. If credentials are retrieved from the EC2 Instance Metadata Service, the region can also be retrieved from the metadata.retry_mode
- (Optional) Specifies how retries are attempted. Valid values arestandard
andadaptive
. Can also be configured using theAWS_RETRY_MODE
environment variable or the shared config file parameterretry_mode
.s3_use_path_style
- (Optional) Whether to enable the request to use path-style addressing, i.e.,https://s3.amazonaws.com/BUCKET/KEY
. By default, the S3 client will use virtual hosted bucket addressing,https://BUCKET.s3.amazonaws.com/KEY
, when possible. Specific to the Amazon S3 service.s3_eu_west_1_regional_endpoint
- (Optional) Specifies whether S3 API calls in theeu-west-1
region use the legacy global endpoint or a regional endpoint. Valid values arelegacy
orregional
. Can also be configured using theAWS_S3_eu_west_1_REGIONAL_ENDPOINT
environment variable or thes3_eu_west_1_regional_endpoint
shared config file parameter. Specific to the Amazon S3 service.secret_key
- (Optional) AWS secret key. Can also be set with theAWS_SECRET_ACCESS_KEY
environment variable, or via a shared configuration and credentials files ifprofile
is used. See alsoaccess_key
.shared_config_files
- (Optional) List of paths to AWS shared config files. If not set, the default is[~/.aws/config]
. A single value can also be set with theAWS_CONFIG_FILE
environment variable.shared_credentials_files
- (Optional) List of paths to the shared credentials file. If not set and a profile is used, the default value is[~/.aws/credentials]
. A single value can also be set with theAWS_SHARED_CREDENTIALS_FILE
environment variable.skip_credentials_validation
- (Optional) Whether to skip credentials validation via the STS API. This can be useful for testing and for AWS API implementations that do not have STS available.skip_metadata_api_check
- (Optional) Whether to skip the AWS Metadata API check. Useful for AWS API implementations that do not have a metadata API endpoint. Setting totrue
prevents Terraform from authenticating via the Metadata API. You may need to use other authentication methods like static credentials, configuration variables, or environment variables.skip_region_validation
- (Optional) Whether to skip validating the region. Useful for AWS-like implementations that use their own region names or to bypass the validation for regions that aren't publicly available yet.skip_requesting_account_id
- (Optional) Whether to skip requesting the account ID. Useful for AWS API implementations that do not have the IAM, STS API, or metadata API. When set totrue
and not determined previously, returns an empty account ID when manually constructing ARN attributes with the following:token
- (Optional) Session token for validating temporary credentials. Typically provided after successful identity federation or Multi-Factor Authentication (MFA) login. With MFA login, this is the session token provided afterward, not the 6 digit MFA code used to get temporary credentials. Can also be set with theAWS_SESSION_TOKEN
environment variable.use_dualstack_endpoint
- (Optional) Force the provider to resolve endpoints with DualStack capability. Can also be set with theAWS_USE_DUALSTACK_ENDPOINT
environment variable or in a shared config file (use_dualstack_endpoint
).use_fips_endpoint
- (Optional) Force the provider to resolve endpoints with FIPS capability. Can also be set with theAWS_USE_FIPS_ENDPOINT
environment variable or in a shared config file (use_fips_endpoint
).
The assume_role
configuration block supports the following arguments:
duration
- (Optional) Duration of the assume role session. You can provide a value from 15 minutes up to the maximum session duration setting for the role. Represented by a string such as1h
,2h45m
, or30m15s
.external_id
- (Optional) External identifier to use when assuming the role.policy
- (Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.policy_arns
- (Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.role_arn
- (Required) ARN of the IAM Role to assume.session_name
- (Optional) Session name to use when assuming the role.source_identity
- (Optional) Source identity specified by the principal assuming the role.tags
- (Optional) Map of assume role session tags.transitive_tag_keys
- (Optional) Set of assume role session tag keys to pass to any subsequent sessions.
The assume_role_with_web_identity
configuration block supports the following arguments:
duration
- (Optional) Duration of the assume role session. You can provide a value from 15 minutes up to the maximum session duration setting for the role. Represented by a string such as1h
,2h45m
, or30m15s
.policy
- (Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.policy_arns
- (Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.role_arn
- (Required) ARN of the IAM Role to assume. Can also be set with theAWS_ROLE_ARN
environment variable.session_name
- (Optional) Session name to use when assuming the role. Can also be set with theAWS_ROLE_SESSION_NAME
environment variable.web_identity_token
- (Optional) Value of a web identity token from an OpenID Connect (OIDC) or OAuth provider. One ofweb_identity_token
orweb_identity_token_file
is required.web_identity_token_file
- (Optional) File containing a web identity token from an OpenID Connect (OIDC) or OAuth provider. One ofweb_identity_token_file
orweb_identity_token
is required. Can also be set with theAWS_WEB_IDENTITY_TOKEN_FILE
environment variable.
Hands-on: Try the Configure Default Tags for AWS Resources tutorial.
Example: Resource with provider default tags
provider "aws" {
default_tags {
tags = {
Environment = "Test"
Name = "Provider Tag"
}
}
}
resource "aws_vpc" "example" {
# ..other configuration...
}
output "vpc_resource_level_tags" {
value = aws_vpc.example.tags
}
output "vpc_all_tags" {
value = aws_vpc.example.tags_all
}
Outputs:
$ terraform apply
...
Outputs:
vpc_all_tags = tomap({
"Environment" = "Test"
"Name" = "Provider Tag"
})
Example: Resource with tags and provider default tags
provider "aws" {
default_tags {
tags = {
Environment = "Test"
Name = "Provider Tag"
}
}
}
resource "aws_vpc" "example" {
# ..other configuration...
tags = {
Owner = "example"
}
}
output "vpc_resource_level_tags" {
value = aws_vpc.example.tags
}
output "vpc_all_tags" {
value = aws_vpc.example.tags_all
}
Outputs:
$ terraform apply
...
Outputs:
vpc_all_tags = tomap({
"Environment" = "Test"
"Name" = "Provider Tag"
"Owner" = "example"
})
vpc_resource_level_tags = tomap({
"Owner" = "example"
})
Example: Resource overriding provider default tags
provider "aws" {
default_tags {
tags = {
Environment = "Test"
Name = "Provider Tag"
}
}
}
resource "aws_vpc" "example" {
# ..other configuration...
tags = {
Environment = "Production"
}
}
output "vpc_resource_level_tags" {
value = aws_vpc.example.tags
}
output "vpc_all_tags" {
value = aws_vpc.example.tags_all
}
Outputs:
$ terraform apply
...
Outputs:
vpc_all_tags = tomap({
"Environment" = "Production"
"Name" = "Provider Tag"
})
vpc_resource_level_tags = tomap({
"Environment" = "Production"
})
The default_tags
configuration block supports the following argument:
tags
- (Optional) Key-value map of tags to apply to all resources.
Example:
provider "aws" {
ignore_tags {
keys = ["TagKey1"]
}
}
The ignore_tags
configuration block supports the following arguments:
keys
- (Optional) List of exact resource tag keys to ignore across all resources handled by this provider. This configuration prevents Terraform from returning the tag in anytags
attributes and displaying any configuration difference for the tag value. If any resource configuration still has this tag key configured in thetags
argument, it will display a perpetual difference until the tag is removed from the argument orignore_changes
is also used.key_prefixes
- (Optional) List of resource tag key prefixes to ignore across all resources handled by this provider. This configuration prevents Terraform from returning any tag key matching the prefixes in anytags
attributes and displaying any configuration difference for those tag values. If any resource configuration still has a tag matching one of the prefixes configured in thetags
argument, it will display a perpetual difference until the tag is removed from the argument orignore_changes
is also used.
If you use either allowed_account_ids
or forbidden_account_ids
,
Terraform uses several approaches to get the actual account ID
in order to compare it with allowed or forbidden IDs.
Approaches differ per authentication providers:
- EC2 instance w/ IAM Instance Profile - Metadata API
is always used. Introduced in Terraform
0.6.16
. - All other providers (environment variable, shared credentials file, ...)
will try three approaches in the following order
iam:GetUser
- Typically useful for IAM Users. It also means that each user needs to be privileged to calliam:GetUser
for themselves.sts:GetCallerIdentity
- Should work for both IAM Users and federated IAM Roles, introduced in Terraform0.6.16
.iam:ListRoles
- This is specifically useful for IdP-federated profiles which cannot useiam:GetUser
. It also means that each federated user need to be assuming an IAM role which allowsiam:ListRoles
. Used in Terraform0.6.16+
. There used to be no better way to get account ID out of the API when using the federated account untilsts:GetCallerIdentity
was introduced.