Skip to main content
Stores the state as a given key in a given bucket on Amazon S3. This backend also supports state locking and consistency checking via Dynamo DB, which can be enabled by setting the dynamodb_table field to an existing DynamoDB table name. A single DynamoDB table can be used to lock multiple remote state files. Terraform generates key names that include the values of the bucket and key variables. Warning! It is highly recommended that you enable Bucket Versioning on the S3 bucket to allow for state recovery in the case of accidental deletions and human error. Read more about this backend in the Terraform docs: https://developer.hashicorp.com/terraform/language/settings/backends/s3

Initializer

import { S3BackendConfig } from 'cdktn'

const s3BackendConfig: S3BackendConfig = { ... }

Properties

NameTypeDescription
bucketstringName of the S3 Bucket.
keystringPath to the state file inside the S3 Bucket.
accessKeystring(Optional) AWS access key.
aclstring(Optional) Canned ACL to be applied to the state file.
allowedAccountIdsstring[](Optional) List of allowed AWS account IDs to prevent potential destruction of a live environment.
assumeRoleS3BackendAssumeRoleConfigAssuming an IAM Role can be configured in two ways.
assumeRolePolicystring(Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.
assumeRolePolicyArnsstring[](Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.
assumeRoleTags{[ key: string ]: string}(Optional) Map of assume role session tags.
assumeRoleTransitiveTagKeysstring[](Optional) Set of assume role session tag keys to pass to any subsequent sessions.
assumeRoleWithWebIdentityS3BackendAssumeRoleWithWebIdentityConfigAssume Role With Web Identity Configuration.
customCaBundlestring(Optional) File containing custom root and intermediate certificates.
dynamodbEndpointstring(Optional) Custom endpoint for the AWS DynamoDB API.
dynamodbTablestring(Optional) Name of DynamoDB Table to use for state locking and consistency.
ec2MetadataServiceEndpointstringOptional) Custom endpoint URL for the EC2 Instance Metadata Service (IMDS) API.
ec2MetadataServiceEndpointModestring(Optional) Mode to use in communicating with the metadata service.
encryptboolean(Optional) Enable server side encryption of the state file.
endpointstring(Optional) Custom endpoint for the AWS S3 API.
endpointsS3BackendEndpointConfig(Optional) The endpoint configuration block.
externalIdstring(Optional) External identifier to use when assuming the role.
forbiddenAccountIdsstring[](Optional) List of forbidden AWS account IDs to prevent potential destruction of a live environment.
forcePathStyleboolean(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).
httpProxystring(Optional) URL of a proxy to use for HTTP requests when accessing the AWS API.
httpsProxystring(Optional) URL of a proxy to use for HTTPS requests when accessing the AWS API.
iamEndpointstring(Optional) Custom endpoint for the AWS Identity and Access Management (IAM) API.
insecurebooleanOptional) Whether to explicitly allow the backend to perform “insecure” SSL requests.
kmsKeyIdstring(Optional) Amazon Resource Name (ARN) of a Key Management Service (KMS) Key to use for encrypting the state.
maxRetriesnumber(Optional) The maximum number of times an AWS API request is retried on retryable failure.
noProxystring(Optional) Comma-separated list of hosts that should not use HTTP or HTTPS proxies.
profilestring(Optional) Name of AWS profile in AWS shared credentials file (e.g. ~/.aws/credentials) or AWS shared configuration file (e.g. ~/.aws/config) to use for credentials and/or configuration. This can also be sourced from the AWS_PROFILE environment variable.
regionstringAWS Region of the S3 Bucket and DynamoDB Table (if used).
retryModestring(Optional) Specifies how retries are attempted.
roleArnstring(Optional) Amazon Resource Name (ARN) of the IAM Role to assume.
secretKeystring(Optional) AWS secret access key.
sessionNamestring(Optional) Session name to use when assuming the role.
sharedConfigFilesstring[](Optional) List of paths to AWS shared configuration files.
sharedCredentialsFilestring(Optional) Path to the AWS shared credentials file.
sharedCredentialsFilesstring[](Optional) List of paths to AWS shared credentials files.
skipCredentialsValidationboolean(Optional) Skip credentials validation via the STS API.
skipMetadataApiCheckboolean(Optional) Skip usage of EC2 Metadata API.
skipRegionValidationboolean(Optional) Skip validation of provided region name.
skipRequestingAccountIdboolean(Optional) Whether to skip requesting the account ID.
skipS3Checksumboolean(Optional) Do not include checksum when uploading S3 Objects.
sseCustomerKeystring(Optional) The key to use for encrypting state with Server-Side Encryption with Customer-Provided Keys (SSE-C).
stsEndpointstring(Optional) Custom endpoint for the AWS Security Token Service (STS) API.
stsRegionstring(Optional) AWS region for STS.
tokenstring(Optional) Multi-Factor Authentication (MFA) token.
useLegacyWorkflowboolean(Optional) Use the legacy authentication workflow, preferring environment variables over backend configuration.
usePathStyleboolean(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).
workspaceKeyPrefixstring(Optional) Prefix applied to the state path inside the bucket.

bucketRequired

public readonly bucket: string;
  • Type: string
Name of the S3 Bucket.

keyRequired

public readonly key: string;
  • Type: string
Path to the state file inside the S3 Bucket. When using a non-default workspace, the state path will be /workspace_key_prefix/workspace_name/key

accessKeyOptional

public readonly accessKey: string;
  • Type: string
(Optional) AWS access key. If configured, must also configure secret_key. This can also be sourced from the AWS_ACCESS_KEY_ID environment variable, AWS shared credentials file (e.g. ~/.aws/credentials), or AWS shared configuration file (e.g. ~/.aws/config).

aclOptional

public readonly acl: string;
  • Type: string
(Optional) Canned ACL to be applied to the state file.

allowedAccountIdsOptional

public readonly allowedAccountIds: string[];
  • Type: string[]
(Optional) List of allowed AWS account IDs to prevent potential destruction of a live environment. Conflicts with forbidden_account_ids.

assumeRoleOptional

public readonly assumeRole: S3BackendAssumeRoleConfig;
Assuming an IAM Role can be configured in two ways. The preferred way is to use the argument assume_role, the other, which is deprecated, is with arguments at the top level.

assumeRolePolicyOptional

  • Deprecated: Use assumeRole.policy instead.
public readonly assumeRolePolicy: string;
  • Type: string
(Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.

assumeRolePolicyArnsOptional

  • Deprecated: Use assumeRole.policyArns instead.
public readonly assumeRolePolicyArns: string[];
  • Type: string[]
(Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.

assumeRoleTagsOptional

  • Deprecated: Use assumeRole.tags instead.
public readonly assumeRoleTags: {[ key: string ]: string};
  • Type: {[ key: string ]: string}
(Optional) Map of assume role session tags.

assumeRoleTransitiveTagKeysOptional

  • Deprecated: Use assumeRole.transitiveTagKeys instead.
public readonly assumeRoleTransitiveTagKeys: string[];
  • Type: string[]
(Optional) Set of assume role session tag keys to pass to any subsequent sessions.

assumeRoleWithWebIdentityOptional

public readonly assumeRoleWithWebIdentity: S3BackendAssumeRoleWithWebIdentityConfig;
Assume Role With Web Identity Configuration.

customCaBundleOptional

public readonly customCaBundle: string;
  • Type: string
(Optional) File containing custom root and intermediate certificates. Can also be set using the AWS_CA_BUNDLE environment variable. Setting ca_bundle in the shared config file is not supported.

dynamodbEndpointOptional

  • Deprecated: Use endpoints.dynamodb instead
public readonly dynamodbEndpoint: string;
  • Type: string
(Optional) Custom endpoint for the AWS DynamoDB API. This can also be sourced from the AWS_DYNAMODB_ENDPOINT environment variable.

dynamodbTableOptional

public readonly dynamodbTable: string;
  • Type: string
(Optional) Name of DynamoDB Table to use for state locking and consistency. The table must have a partition key named LockID with type of String. If not configured, state locking will be disabled.

ec2MetadataServiceEndpointOptional

public readonly ec2MetadataServiceEndpoint: string;
  • Type: string
Optional) Custom endpoint URL for the EC2 Instance Metadata Service (IMDS) API. Can also be set with the AWS_EC2_METADATA_SERVICE_ENDPOINT environment variable.

ec2MetadataServiceEndpointModeOptional

public readonly ec2MetadataServiceEndpointMode: string;
  • Type: string
(Optional) Mode to use in communicating with the metadata service. Valid values are IPv4 and IPv6. Can also be set with the AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE environment variable.

encryptOptional

public readonly encrypt: boolean;
  • Type: boolean
(Optional) Enable server side encryption of the state file.

endpointOptional

  • Deprecated: Use endpoints.s3 instead
public readonly endpoint: string;
  • Type: string
(Optional) Custom endpoint for the AWS S3 API. This can also be sourced from the AWS_S3_ENDPOINT environment variable.

endpointsOptional

public readonly endpoints: S3BackendEndpointConfig;
(Optional) The endpoint configuration block.

externalIdOptional

  • Deprecated: Use assume_role.external_id instead.
public readonly externalId: string;
  • Type: string
(Optional) External identifier to use when assuming the role.

forbiddenAccountIdsOptional

public readonly forbiddenAccountIds: string[];
  • Type: string[]
(Optional) List of forbidden AWS account IDs to prevent potential destruction of a live environment. Conflicts with allowed_account_ids.

forcePathStyleOptional

  • Deprecated: Use usePathStyle instead
public readonly forcePathStyle: boolean;
  • Type: boolean
(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).

httpProxyOptional

public readonly httpProxy: string;
  • Type: string
(Optional) URL of a proxy to use for HTTP requests when accessing the AWS API. Can also be set using the HTTP_PROXY or http_proxy environment variables.

httpsProxyOptional

public readonly httpsProxy: string;
  • Type: string
(Optional) URL of a proxy to use for HTTPS requests when accessing the AWS API. Can also be set using the HTTPS_PROXY or https_proxy environment variables.

iamEndpointOptional

  • Deprecated: Use endpoints.iam instead
public readonly iamEndpoint: string;
  • Type: string
(Optional) Custom endpoint for the AWS Identity and Access Management (IAM) API. This can also be sourced from the AWS_IAM_ENDPOINT environment variable.

insecureOptional

public readonly insecure: boolean;
  • Type: boolean
Optional) Whether to explicitly allow the backend to perform “insecure” SSL requests. If omitted, the default value is false.

kmsKeyIdOptional

public readonly kmsKeyId: string;
  • Type: string
(Optional) Amazon Resource Name (ARN) of a Key Management Service (KMS) Key to use for encrypting the state. Note that if this value is specified, Terraform will need kms:Encrypt, kms:Decrypt and kms:GenerateDataKey permissions on this KMS key.

maxRetriesOptional

public readonly maxRetries: number;
  • Type: number
(Optional) The maximum number of times an AWS API request is retried on retryable failure. Defaults to 5.

noProxyOptional

public readonly noProxy: string;
  • Type: string
(Optional) Comma-separated list of hosts that should not use HTTP or HTTPS proxies. Each value can be one of:
  • A domain name
  • An IP address
  • A CIDR address
  • An asterisk (*), to indicate that no proxying should be performed Domain name and IP address values can also include a port number. Can also be set using the NO_PROXY or no_proxy environment variables.

profileOptional

public readonly profile: string;
  • Type: string
(Optional) Name of AWS profile in AWS shared credentials file (e.g. ~/.aws/credentials) or AWS shared configuration file (e.g. ~/.aws/config) to use for credentials and/or configuration. This can also be sourced from the AWS_PROFILE environment variable.

regionOptional

public readonly region: string;
  • Type: string
AWS Region of the S3 Bucket and DynamoDB Table (if used). This can also be sourced from the AWS_DEFAULT_REGION and AWS_REGION environment variables.

retryModeOptional

public readonly retryMode: string;
  • Type: string
(Optional) Specifies how retries are attempted. Valid values are standard and adaptive. Can also be configured using the AWS_RETRY_MODE environment variable or the shared config file parameter retry_mode.

roleArnOptional

  • Deprecated: Use assumeRole.roleArn instead.
public readonly roleArn: string;
  • Type: string
(Optional) Amazon Resource Name (ARN) of the IAM Role to assume.

secretKeyOptional

public readonly secretKey: string;
  • Type: string
(Optional) AWS secret access key. If configured, must also configure access_key. This can also be sourced from the AWS_SECRET_ACCESS_KEY environment variable, AWS shared credentials file (e.g. ~/.aws/credentials), or AWS shared configuration file (e.g. ~/.aws/config)

sessionNameOptional

  • Deprecated: Use assumeRole.sessionName instead.
public readonly sessionName: string;
  • Type: string
(Optional) Session name to use when assuming the role.

sharedConfigFilesOptional

public readonly sharedConfigFiles: string[];
  • Type: string[]
(Optional) List of paths to AWS shared configuration files. Defaults to ~/.aws/config.

sharedCredentialsFileOptional

public readonly sharedCredentialsFile: string;
  • Type: string
(Optional) Path to the AWS shared credentials file. Defaults to ~/.aws/credentials.

sharedCredentialsFilesOptional

public readonly sharedCredentialsFiles: string[];
  • Type: string[]
(Optional) List of paths to AWS shared credentials files. Defaults to ~/.aws/credentials.

skipCredentialsValidationOptional

public readonly skipCredentialsValidation: boolean;
  • Type: boolean
(Optional) Skip credentials validation via the STS API.

skipMetadataApiCheckOptional

public readonly skipMetadataApiCheck: boolean;
  • Type: boolean
(Optional) Skip usage of EC2 Metadata API.

skipRegionValidationOptional

public readonly skipRegionValidation: boolean;
  • Type: boolean
(Optional) Skip validation of provided region name.

skipRequestingAccountIdOptional

public readonly skipRequestingAccountId: boolean;
  • Type: boolean
(Optional) Whether to skip requesting the account ID. Useful for AWS API implementations that do not have the IAM, STS API, or metadata API.

skipS3ChecksumOptional

public readonly skipS3Checksum: boolean;
  • Type: boolean
(Optional) Do not include checksum when uploading S3 Objects. Useful for some S3-Compatible APIs.

sseCustomerKeyOptional

public readonly sseCustomerKey: string;
  • Type: string
(Optional) The key to use for encrypting state with Server-Side Encryption with Customer-Provided Keys (SSE-C). This is the base64-encoded value of the key, which must decode to 256 bits. This can also be sourced from the AWS_SSE_CUSTOMER_KEY environment variable, which is recommended due to the sensitivity of the value. Setting it inside a terraform file will cause it to be persisted to disk in terraform.tfstate.

stsEndpointOptional

  • Deprecated: Use endpoints.sts instead
public readonly stsEndpoint: string;
  • Type: string
(Optional) Custom endpoint for the AWS Security Token Service (STS) API. This can also be sourced from the AWS_STS_ENDPOINT environment variable.

stsRegionOptional

public readonly stsRegion: string;
  • Type: string
(Optional) AWS region for STS. If unset, AWS will use the same region for STS as other non-STS operations.

tokenOptional

public readonly token: string;
  • Type: string
(Optional) Multi-Factor Authentication (MFA) token. This can also be sourced from the AWS_SESSION_TOKEN environment variable.

useLegacyWorkflowOptional

public readonly useLegacyWorkflow: boolean;
  • Type: boolean
(Optional) Use the legacy authentication workflow, preferring environment variables over backend configuration. Defaults to true. This behavior does not align with the authentication flow of the AWS CLI or SDK’s, and will be removed in the future.

usePathStyleOptional

public readonly usePathStyle: boolean;
  • Type: boolean
(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).

workspaceKeyPrefixOptional

public readonly workspaceKeyPrefix: string;
  • Type: string
(Optional) Prefix applied to the state path inside the bucket. This is only relevant when using a non-default workspace. Defaults to env: