This is how I do it.
Explore the docs »
Report Bug
.
Request Feature
Ben's Terraform AWS TFState Remote Backend Module
Start with a simple Terraform project looking something similar to the following. This module will create the S3 bucket and DynamoDB table you need. A good practice is to keep this Terraform project simple and check the state data into your source control.
module "context" {
source = "bendoerr-terraform-modules/context/null"
version = "xxx"
namespace = "bd"
role = "production"
region = "us-east-1"
project = "tfstate"
}
module "tfstate" {
source = "bendoerr-terraform-modules/tfstate/aws"
version = "xxx"
context = module.context.shared
}
output "store" {
value = module.tfstate.tfstate_id # -> bd-prod-ue1-tfstate-store
}
output "lock_table" {
value = module.tfstate.lock_table_name # -> bd-prod-ue1-tfstate-locks
}
In future projects your TF state can be centrally maintained.
terraform {
backend "s3" {
bucket = "brd-prod-ue1-tfstate-store"
dynamodb_table = "brd-prod-ue1-tfstate-locks"
key = "terraform.tfstate"
kms_key_id = "alias/aws/s3"
region = "us-east-1"
workspace_key_prefix = "foundryvtt-on-demand"
}
}
Project: 10 Workspaces & 5 Applies Each Per Day
Module path: examples/complete
Name Monthly Qty Unit Monthly Cost
module.tfstate.aws_dynamodb_table.locks
├─ Write request unit (WRU) 1,500 WRUs $0.00
└─ Read request unit (RRU) 1,500 RRUs $0.00
module.tfstate.module.store.aws_s3_bucket.this[0]
└─ Standard
├─ Storage 0.02 GB $0.00
├─ PUT, COPY, POST, LIST requests 4.5 1k requests $0.02
└─ GET, SELECT, and all other requests 3 1k requests $0.00
OVERALL TOTAL $0.03
──────────────────────────────────
9 cloud resources were detected:
∙ 2 were estimated, all of which include usage-based costs, see https://infracost.io/usage-file
∙ 7 were free, rerun with --show-skipped to see details
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Project ┃ Monthly cost ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
┃ 10 Workspaces & 5 Applies Each Per Day ┃ $0.03 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Name | Version |
---|---|
terraform | >= 0.13 |
aws | ~> 5.0 |
Name | Version |
---|---|
aws | ~> 5.0 |
Name | Source | Version |
---|---|---|
label_dynamodb_rw | bendoerr-terraform-modules/label/null | 0.4.1 |
label_locks | bendoerr-terraform-modules/label/null | 0.4.1 |
label_s3_rw | bendoerr-terraform-modules/label/null | 0.4.1 |
label_store | bendoerr-terraform-modules/label/null | 0.4.1 |
store | terraform-aws-modules/s3-bucket/aws | 3.15.1 |
Name | Type |
---|---|
aws_dynamodb_table.locks | resource |
aws_iam_policy.s3_rw | resource |
aws_iam_policy.state_dynamodb_rw | resource |
aws_iam_policy_document.dynamodb_rw | data source |
aws_iam_policy_document.s3_rw | data source |
aws_kms_alias.s3 | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
context | Shared Context from Ben's terraform-null-context | object({ |
n/a | yes |
Name | Description |
---|---|
iam_locks_rw_arn | n/a |
iam_locks_rw_id | n/a |
iam_tfstate_rw_arn | n/a |
iam_tfstate_rw_id | n/a |
lock_table_arn | n/a |
lock_table_id | n/a |
lock_table_name | n/a |
tfstate_arn | n/a |
tfstate_id | n/a |
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- If you have suggestions for adding or removing projects, feel free to open an issue to discuss it, or directly create a pull request after you edit the README.md file with necessary changes.
- Please make sure you check your spelling and grammar.
- Create individual PR for each suggestion.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
- Benjamin R. Doerr - Terraformer - Benjamin R. Doerr - Built Ben's Terraform Modules
Only the latest tagged version is supported.
See SECURITY.md.