You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates a backend S3 bucket and DynamoDB table for managing Terraform state. Useful for bootstrapping a new
6
-
environment.
6
+
environment. This module supports cross-account state management, using a centralized account that holds the S3 bucket and KMS key.
7
+
8
+
_Note: A centralized DynamoDB locking table is not supported because terraform cannot assume more than one IAM role per execution._
7
9
8
10
## Usage
9
11
```
@@ -16,14 +18,60 @@ module "backend" {
16
18
17
19
```
18
20
21
+
## Cross Account State Management
22
+
Managing state across accounts requires additional configuration to ensure that the S3 bucket is appropriately accessible and the KMS key is usable.
23
+
24
+
The following module declaration will create an S3 bucket and KMS key that are accessible to the root account (and users with the AdministratorAccess managed role) in the target account:
The module will automatically write to the source account S3 bucket using the KMS key with cross-account access.
47
+
48
+
Access to the source S3 bucket is done based on a prefix that matches the AWS Account ID. Therefore, target accounts must use a `workspace_key_prefix` that matches the account ID, such as in the following sample backend-config values:
49
+
50
+
```
51
+
bucket = "012345678901-us-east-1-tf-state"
52
+
key = "project.tfstate"
53
+
workspace_key_prefix = "123456789012"
54
+
region = "us-east-1"
55
+
```
56
+
19
57
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20
58
## Inputs
21
59
22
60
| Name | Description | Type | Default | Required |
23
61
|------|-------------|:----:|:-----:|:-----:|
24
-
| bucket | Name of bucket to create | string | n/a | yes |
62
+
| allowed\_account\_ids | Account IDs that are allowed to access the bucket/KMS key | list(string) |`[]`| no |
63
+
| bucket | Name of bucket to create \(do not provide if using `remote\_bucket`\)| string |`""`| no |
64
+
| kms\_key\_id | ARN for KMS key for all encryption operations. | string |`""`| no |
25
65
| region | Region bucket will be created in | string | n/a | yes |
26
-
| table | Name of Dynamo Table to create | string | n/a | yes |
66
+
| remote\_bucket | If specified, the remote bucket will be used for the backend. A new bucket will not be created | string |`""`| no |
67
+
| table | Name of Dynamo Table to create | string |`"tf-locktable"`| no |
27
68
| tags | Mapping of any extra tags you want added to resources | map(string) |`{}`| no |
0 commit comments