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
Copy file name to clipboardExpand all lines: README.md
+31-51Lines changed: 31 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,71 +1,47 @@
1
1
# terraform-aws-backend
2
-
[](https://github.com/rhythmictech/terraform-aws-backend/actions) <ahref="https://twitter.com/intent/follow?screen_name=RhythmicTech"><imgsrc="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=RhythmicTech"alt="follow on Twitter"></a>
3
2
4
-
Creates a backend S3 bucket and DynamoDB table for managing Terraform state. Useful for bootstrapping a new
5
-
environment. This module supports cross-account state management, using a centralized account that holds the S3 bucket and KMS key.
<ahref="https://twitter.com/intent/follow?screen_name=RhythmicTech"><imgsrc="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=twitter"alt="follow on Twitter"></a>
6
9
7
-
_Note: A centralized DynamoDB locking table is not supported because terraform cannot assume more than one IAM role per execution._
10
+
Creates a backend S3 bucket and DynamoDB table for managing Terraform state. Note that when bootstrapping a new environment, it is typically easier to use a separate method for creating the bucket and lock table. This module is intended to create a backend in an AWS account that is already Terraform-managed. This is useful to store the state for other accounts externally, which is always preferred.
11
+
12
+
*Breaking Changes*
13
+
14
+
Previous versions of this module had support for cross-account management in a way that proved awkward for many uses cases and made it more difficult than it should've to fully secure the tfstate between accounts. Version 4.x and later eliminates support for this and refocuses the module on using centralized tfstate buckets with cross-account role assumption for execution of terraform. As a result, many variable names have changed and functionality has been dropped. Upgrade to this version at your own peril.
Managing state across accounts requires additional configuration to ensure that the S3 bucket is appropriately accessible and the KMS key is usable.
22
-
23
-
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:
In the target account, use this declaration to import the module:
28
+
To use this bucket to manage the state for other AWS accounts, you must create IAM roles in those accounts and allow the users who run Terraform to assume them.
The module will automatically write to the source account S3 bucket using the KMS key with cross-account access.
46
-
47
-
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:
48
-
49
-
```
50
-
bucket = "012345678901-us-east-1-tf-state"
51
-
key = "project.tfstate"
52
-
workspace_key_prefix = "123456789012"
53
-
region = "us-east-1"
54
-
```
30
+
See [Use AssumeRole to Provision AWS Resources Across Accounts](https://learn.hashicorp.com/tutorials/terraform/aws-assumerole) for more information on this pattern.
55
31
56
32
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
| <aname="input_allowed_account_ids"></a> [allowed\_account\_ids](#input\_allowed\_account\_ids)| Account IDs that are allowed to access the bucket/KMS key |`list(string)`|`[]`| no |
93
-
| <aname="input_bucket"></a> [bucket](#input\_bucket)| Name of bucket to create (do not provide if using `remote_bucket`) |`string`|`""`| no |
94
-
| <aname="input_kms_alias_name"></a> [kms\_alias\_name](#input\_kms\_alias\_name)| Name of KMS Alias |`string`|`""`| no |
95
-
| <aname="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id)| ARN for KMS key for all encryption operations. |`string`|`""`| no |
96
-
| <aname="input_logging_target_bucket"></a> [logging\_target\_bucket](#input\_logging\_target\_bucket)| The name of the bucket that will receive the log objects |`string`|`null`| no |
97
-
| <aname="input_logging_target_prefix"></a> [logging\_target\_prefix](#input\_logging\_target\_prefix)| A key prefix for log objects |`string`|`"TFStateLogs/"`| no |
98
-
| <aname="input_remote_bucket"></a> [remote\_bucket](#input\_remote\_bucket)| If specified, the remote bucket will be used for the backend. A new bucket will not be created |`string`|`""`| no |
73
+
| <aname="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name)| Name of bucket to create |`string`| n/a | yes |
74
+
| <aname="input_kms_alias_name"></a> [kms\_alias\_name](#input\_kms\_alias\_name)| Name of KMS Alias |`string`|`null`| no |
75
+
| <aname="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id)| ARN for KMS key for all encryption operations (a key will be created if this is not provided) |`string`|`null`| no |
76
+
| <aname="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules)| lifecycle rules to apply to the bucket (set to null to skip lifecycle rules) | <pre>list(object(<br> {<br> id = string<br> enabled = bool<br> prefix = string<br> expiration = number<br> noncurrent_version_expiration = number<br> }))</pre> | <pre>[<br> {<br> "enabled": true,<br> "expiration": 90,<br> "id": "tfstate-expire",<br> "noncurrent_version_expiration": 90,<br> "prefix": null<br> }<br>]</pre> | no |
77
+
| <aname="input_logging_target_bucket"></a> [logging\_target\_bucket](#input\_logging\_target\_bucket)| The name of the bucket that will receive the log objects (logging will be disabled if null) |`string`|`null`| no |
78
+
| <aname="input_logging_target_prefix"></a> [logging\_target\_prefix](#input\_logging\_target\_prefix)| A key prefix for log objects |`string`|`null`| no |
99
79
| <aname="input_table"></a> [table](#input\_table)| Name of Dynamo Table to create |`string`|`"tf-locktable"`| no |
100
80
| <aname="input_tags"></a> [tags](#input\_tags)| Mapping of any extra tags you want added to resources |`map(string)`|`{}`| no |
0 commit comments