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 io.cdktn.cdktn.S3BackendConfig;

S3BackendConfig.builder()
    .bucket(java.lang.String)
    .key(java.lang.String)
//  .accessKey(java.lang.String)
//  .acl(java.lang.String)
//  .allowedAccountIds(java.util.List<java.lang.String>)
//  .assumeRole(S3BackendAssumeRoleConfig)
//  .assumeRolePolicy(java.lang.String)
//  .assumeRolePolicyArns(java.util.List<java.lang.String>)
//  .assumeRoleTags(java.util.Map<java.lang.String, java.lang.String>)
//  .assumeRoleTransitiveTagKeys(java.util.List<java.lang.String>)
//  .assumeRoleWithWebIdentity(S3BackendAssumeRoleWithWebIdentityConfig)
//  .customCaBundle(java.lang.String)
//  .dynamodbEndpoint(java.lang.String)
//  .dynamodbTable(java.lang.String)
//  .ec2MetadataServiceEndpoint(java.lang.String)
//  .ec2MetadataServiceEndpointMode(java.lang.String)
//  .encrypt(java.lang.Boolean)
//  .endpoint(java.lang.String)
//  .endpoints(S3BackendEndpointConfig)
//  .externalId(java.lang.String)
//  .forbiddenAccountIds(java.util.List<java.lang.String>)
//  .forcePathStyle(java.lang.Boolean)
//  .httpProxy(java.lang.String)
//  .httpsProxy(java.lang.String)
//  .iamEndpoint(java.lang.String)
//  .insecure(java.lang.Boolean)
//  .kmsKeyId(java.lang.String)
//  .maxRetries(java.lang.Number)
//  .noProxy(java.lang.String)
//  .profile(java.lang.String)
//  .region(java.lang.String)
//  .retryMode(java.lang.String)
//  .roleArn(java.lang.String)
//  .secretKey(java.lang.String)
//  .sessionName(java.lang.String)
//  .sharedConfigFiles(java.util.List<java.lang.String>)
//  .sharedCredentialsFile(java.lang.String)
//  .sharedCredentialsFiles(java.util.List<java.lang.String>)
//  .skipCredentialsValidation(java.lang.Boolean)
//  .skipMetadataApiCheck(java.lang.Boolean)
//  .skipRegionValidation(java.lang.Boolean)
//  .skipRequestingAccountId(java.lang.Boolean)
//  .skipS3Checksum(java.lang.Boolean)
//  .sseCustomerKey(java.lang.String)
//  .stsEndpoint(java.lang.String)
//  .stsRegion(java.lang.String)
//  .token(java.lang.String)
//  .useLegacyWorkflow(java.lang.Boolean)
//  .usePathStyle(java.lang.Boolean)
//  .workspaceKeyPrefix(java.lang.String)
    .build();

Properties

NameTypeDescription
bucketjava.lang.StringName of the S3 Bucket.
keyjava.lang.StringPath to the state file inside the S3 Bucket.
accessKeyjava.lang.String(Optional) AWS access key.
acljava.lang.String(Optional) Canned ACL to be applied to the state file.
allowedAccountIdsjava.util.List< java.lang.String >(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.
assumeRolePolicyjava.lang.String(Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.
assumeRolePolicyArnsjava.util.List< java.lang.String >(Optional) Set of Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed.
assumeRoleTagsjava.util.Map< java.lang.String, java.lang.String >(Optional) Map of assume role session tags.
assumeRoleTransitiveTagKeysjava.util.List< java.lang.String >(Optional) Set of assume role session tag keys to pass to any subsequent sessions.
assumeRoleWithWebIdentityS3BackendAssumeRoleWithWebIdentityConfigAssume Role With Web Identity Configuration.
customCaBundlejava.lang.String(Optional) File containing custom root and intermediate certificates.
dynamodbEndpointjava.lang.String(Optional) Custom endpoint for the AWS DynamoDB API.
dynamodbTablejava.lang.String(Optional) Name of DynamoDB Table to use for state locking and consistency.
ec2MetadataServiceEndpointjava.lang.StringOptional) Custom endpoint URL for the EC2 Instance Metadata Service (IMDS) API.
ec2MetadataServiceEndpointModejava.lang.String(Optional) Mode to use in communicating with the metadata service.
encryptjava.lang.Boolean(Optional) Enable server side encryption of the state file.
endpointjava.lang.String(Optional) Custom endpoint for the AWS S3 API.
endpointsS3BackendEndpointConfig(Optional) The endpoint configuration block.
externalIdjava.lang.String(Optional) External identifier to use when assuming the role.
forbiddenAccountIdsjava.util.List< java.lang.String >(Optional) List of forbidden AWS account IDs to prevent potential destruction of a live environment.
forcePathStylejava.lang.Boolean(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).
httpProxyjava.lang.String(Optional) URL of a proxy to use for HTTP requests when accessing the AWS API.
httpsProxyjava.lang.String(Optional) URL of a proxy to use for HTTPS requests when accessing the AWS API.
iamEndpointjava.lang.String(Optional) Custom endpoint for the AWS Identity and Access Management (IAM) API.
insecurejava.lang.BooleanOptional) Whether to explicitly allow the backend to perform “insecure” SSL requests.
kmsKeyIdjava.lang.String(Optional) Amazon Resource Name (ARN) of a Key Management Service (KMS) Key to use for encrypting the state.
maxRetriesjava.lang.Number(Optional) The maximum number of times an AWS API request is retried on retryable failure.
noProxyjava.lang.String(Optional) Comma-separated list of hosts that should not use HTTP or HTTPS proxies.
profilejava.lang.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.
regionjava.lang.StringAWS Region of the S3 Bucket and DynamoDB Table (if used).
retryModejava.lang.String(Optional) Specifies how retries are attempted.
roleArnjava.lang.String(Optional) Amazon Resource Name (ARN) of the IAM Role to assume.
secretKeyjava.lang.String(Optional) AWS secret access key.
sessionNamejava.lang.String(Optional) Session name to use when assuming the role.
sharedConfigFilesjava.util.List< java.lang.String >(Optional) List of paths to AWS shared configuration files.
sharedCredentialsFilejava.lang.String(Optional) Path to the AWS shared credentials file.
sharedCredentialsFilesjava.util.List< java.lang.String >(Optional) List of paths to AWS shared credentials files.
skipCredentialsValidationjava.lang.Boolean(Optional) Skip credentials validation via the STS API.
skipMetadataApiCheckjava.lang.Boolean(Optional) Skip usage of EC2 Metadata API.
skipRegionValidationjava.lang.Boolean(Optional) Skip validation of provided region name.
skipRequestingAccountIdjava.lang.Boolean(Optional) Whether to skip requesting the account ID.
skipS3Checksumjava.lang.Boolean(Optional) Do not include checksum when uploading S3 Objects.
sseCustomerKeyjava.lang.String(Optional) The key to use for encrypting state with Server-Side Encryption with Customer-Provided Keys (SSE-C).
stsEndpointjava.lang.String(Optional) Custom endpoint for the AWS Security Token Service (STS) API.
stsRegionjava.lang.String(Optional) AWS region for STS.
tokenjava.lang.String(Optional) Multi-Factor Authentication (MFA) token.
useLegacyWorkflowjava.lang.Boolean(Optional) Use the legacy authentication workflow, preferring environment variables over backend configuration.
usePathStylejava.lang.Boolean(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).
workspaceKeyPrefixjava.lang.String(Optional) Prefix applied to the state path inside the bucket.

bucketRequired

public java.lang.String getBucket();
  • Type: java.lang.String
Name of the S3 Bucket.

keyRequired

public java.lang.String getKey();
  • Type: java.lang.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 java.lang.String getAccessKey();
  • Type: java.lang.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 java.lang.String getAcl();
  • Type: java.lang.String
(Optional) Canned ACL to be applied to the state file.

allowedAccountIdsOptional

public java.util.List<java.lang.String> getAllowedAccountIds();
  • Type: java.util.List< java.lang.String >
(Optional) List of allowed AWS account IDs to prevent potential destruction of a live environment. Conflicts with forbidden_account_ids.

assumeRoleOptional

public S3BackendAssumeRoleConfig getAssumeRole();
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 java.lang.String getAssumeRolePolicy();
  • Type: java.lang.String
(Optional) IAM Policy JSON describing further restricting permissions for the IAM Role being assumed.

assumeRolePolicyArnsOptional

  • Deprecated: Use assumeRole.policyArns instead.
public java.util.List<java.lang.String> getAssumeRolePolicyArns();
  • Type: java.util.List< java.lang.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 java.util.Map<java.lang.String, java.lang.String> getAssumeRoleTags();
  • Type: java.util.Map< java.lang.String, java.lang.String >
(Optional) Map of assume role session tags.

assumeRoleTransitiveTagKeysOptional

  • Deprecated: Use assumeRole.transitiveTagKeys instead.
public java.util.List<java.lang.String> getAssumeRoleTransitiveTagKeys();
  • Type: java.util.List< java.lang.String >
(Optional) Set of assume role session tag keys to pass to any subsequent sessions.

assumeRoleWithWebIdentityOptional

public S3BackendAssumeRoleWithWebIdentityConfig getAssumeRoleWithWebIdentity();
Assume Role With Web Identity Configuration.

customCaBundleOptional

public java.lang.String getCustomCaBundle();
  • Type: java.lang.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 java.lang.String getDynamodbEndpoint();
  • Type: java.lang.String
(Optional) Custom endpoint for the AWS DynamoDB API. This can also be sourced from the AWS_DYNAMODB_ENDPOINT environment variable.

dynamodbTableOptional

public java.lang.String getDynamodbTable();
  • Type: java.lang.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 java.lang.String getEc2MetadataServiceEndpoint();
  • Type: java.lang.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 java.lang.String getEc2MetadataServiceEndpointMode();
  • Type: java.lang.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 java.lang.Boolean getEncrypt();
  • Type: java.lang.Boolean
(Optional) Enable server side encryption of the state file.

endpointOptional

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

endpointsOptional

public S3BackendEndpointConfig getEndpoints();
(Optional) The endpoint configuration block.

externalIdOptional

  • Deprecated: Use assume_role.external_id instead.
public java.lang.String getExternalId();
  • Type: java.lang.String
(Optional) External identifier to use when assuming the role.

forbiddenAccountIdsOptional

public java.util.List<java.lang.String> getForbiddenAccountIds();
  • Type: java.util.List< java.lang.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 java.lang.Boolean getForcePathStyle();
  • Type: java.lang.Boolean
(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).

httpProxyOptional

public java.lang.String getHttpProxy();
  • Type: java.lang.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 java.lang.String getHttpsProxy();
  • Type: java.lang.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 java.lang.String getIamEndpoint();
  • Type: java.lang.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 java.lang.Boolean getInsecure();
  • Type: java.lang.Boolean
Optional) Whether to explicitly allow the backend to perform “insecure” SSL requests. If omitted, the default value is false.

kmsKeyIdOptional

public java.lang.String getKmsKeyId();
  • Type: java.lang.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 java.lang.Number getMaxRetries();
  • Type: java.lang.Number
(Optional) The maximum number of times an AWS API request is retried on retryable failure. Defaults to 5.

noProxyOptional

public java.lang.String getNoProxy();
  • Type: java.lang.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 java.lang.String getProfile();
  • Type: java.lang.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 java.lang.String getRegion();
  • Type: java.lang.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 java.lang.String getRetryMode();
  • Type: java.lang.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 java.lang.String getRoleArn();
  • Type: java.lang.String
(Optional) Amazon Resource Name (ARN) of the IAM Role to assume.

secretKeyOptional

public java.lang.String getSecretKey();
  • Type: java.lang.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 java.lang.String getSessionName();
  • Type: java.lang.String
(Optional) Session name to use when assuming the role.

sharedConfigFilesOptional

public java.util.List<java.lang.String> getSharedConfigFiles();
  • Type: java.util.List< java.lang.String >
(Optional) List of paths to AWS shared configuration files. Defaults to ~/.aws/config.

sharedCredentialsFileOptional

public java.lang.String getSharedCredentialsFile();
  • Type: java.lang.String
(Optional) Path to the AWS shared credentials file. Defaults to ~/.aws/credentials.

sharedCredentialsFilesOptional

public java.util.List<java.lang.String> getSharedCredentialsFiles();
  • Type: java.util.List< java.lang.String >
(Optional) List of paths to AWS shared credentials files. Defaults to ~/.aws/credentials.

skipCredentialsValidationOptional

public java.lang.Boolean getSkipCredentialsValidation();
  • Type: java.lang.Boolean
(Optional) Skip credentials validation via the STS API.

skipMetadataApiCheckOptional

public java.lang.Boolean getSkipMetadataApiCheck();
  • Type: java.lang.Boolean
(Optional) Skip usage of EC2 Metadata API.

skipRegionValidationOptional

public java.lang.Boolean getSkipRegionValidation();
  • Type: java.lang.Boolean
(Optional) Skip validation of provided region name.

skipRequestingAccountIdOptional

public java.lang.Boolean getSkipRequestingAccountId();
  • Type: java.lang.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 java.lang.Boolean getSkipS3Checksum();
  • Type: java.lang.Boolean
(Optional) Do not include checksum when uploading S3 Objects. Useful for some S3-Compatible APIs.

sseCustomerKeyOptional

public java.lang.String getSseCustomerKey();
  • Type: java.lang.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 java.lang.String getStsEndpoint();
  • Type: java.lang.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 java.lang.String getStsRegion();
  • Type: java.lang.String
(Optional) AWS region for STS. If unset, AWS will use the same region for STS as other non-STS operations.

tokenOptional

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

useLegacyWorkflowOptional

public java.lang.Boolean getUseLegacyWorkflow();
  • Type: java.lang.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 java.lang.Boolean getUsePathStyle();
  • Type: java.lang.Boolean
(Optional) Enable path-style S3 URLs (https://< HOST >/< BUCKET > instead of https://< BUCKET >.< HOST >).

workspaceKeyPrefixOptional

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