Skip to content

Commit 861f07c

Browse files
Adamosterman
Adam
authored andcommitted
Update README with instructions to match terraform's automatic state copy behavior (#11)
* Update README with instructions to match terraform's automatic state copy behavior. * Move doc updates into README.yaml. This moves updates that had been made by hand in README.md into README.yaml and applies the output of `make readme`. * Expand init instructions into a step-by-step list. * Run make readme.
1 parent 86b17f1 commit 861f07c

File tree

2 files changed

+93
-97
lines changed

2 files changed

+93
-97
lines changed

README.md

+52-54
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# terraform-aws-tfstate-backend [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-tfstate-backend.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-tfstate-backend) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-tfstate-backend.svg)](https://github.com/cloudposse/terraform-aws-tfstate-backend/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

9-
Terraform module to provision an S3 bucket to store `terraform.tfstate` file and a DynamoDB table to lock the state file
9+
Terraform module to provision an S3 bucket to store `terraform.tfstate` file and a DynamoDB table to lock the state file
1010
to prevent concurrent modifications and state corruption.
1111

1212
The module supports the following:
@@ -26,7 +26,7 @@ __NOTE:__ This module cannot be used to apply changes to the `mfa_delete` featur
2626

2727
---
2828

29-
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
29+
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
3030
[<img align="right" title="Share via Email" src="https://docs.cloudposse.com/images/ionicons/ios-email-outline-2.0.1-16x16-999999.svg"/>][share_email]
3131
[<img align="right" title="Share on Google+" src="https://docs.cloudposse.com/images/ionicons/social-googleplus-outline-2.0.1-16x16-999999.svg" />][share_googleplus]
3232
[<img align="right" title="Share on Facebook" src="https://docs.cloudposse.com/images/ionicons/social-facebook-outline-2.0.1-16x16-999999.svg" />][share_facebook]
@@ -47,7 +47,7 @@ It's 100% Open Source and licensed under the [APACHE2](LICENSE).
4747

4848

4949

50-
We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out!
50+
We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out!
5151

5252

5353

@@ -57,48 +57,46 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
5757

5858
## Usage
5959

60-
```hcl
61-
terraform {
62-
required_version = ">= 0.11.3"
63-
}
64-
65-
module "terraform_state_backend" {
66-
source = "git::https://github.com/cloudposse/terraform-aws-tfstate-backend.git?ref=master"
67-
namespace = "cp"
68-
stage = "prod"
69-
name = "terraform"
70-
attributes = ["state"]
71-
region = "us-east-1"
72-
}
73-
```
74-
75-
__NOTE:__ First create the bucket and table without any state enabled (Terraform will use the local file system to store state).
76-
You can then import the bucket and table by using [`terraform import`](https://www.terraform.io/docs/import/index.html) and store the state file into the bucket.
77-
78-
Once the bucket and table have been created, configure the [backend](https://www.terraform.io/docs/backends/types/s3.html)
79-
80-
```hcl
81-
terraform {
82-
required_version = ">= 0.11.3"
83-
84-
backend "s3" {
85-
region = "us-east-1"
86-
bucket = "< the name of the S3 bucket >"
87-
key = "terraform.tfstate"
88-
dynamodb_table = "< the name of the DynamoDB table >"
89-
encrypt = true
90-
}
91-
}
92-
93-
module "another_module" {
94-
source = "....."
95-
}
96-
```
97-
98-
Initialize the backend with `terraform init`.
99-
100-
After `terraform apply`, `terraform.tfstate` file will be stored in the bucket,
101-
and the DynamoDB table will be used to lock the state to prevent concurrent modifications.
60+
1. Define the module in your `.tf` file using local state:
61+
```hcl
62+
terraform {
63+
required_version = ">= 0.11.3"
64+
}
65+
66+
module "terraform_state_backend" {
67+
source = "git::https://github.com/cloudposse/terraform- aws-tfstate-backend.git?ref=master"
68+
namespace = "cp"
69+
stage = "prod"
70+
name = "terraform"
71+
attributes = ["state"]
72+
region = "us-east-1"
73+
}
74+
```
75+
76+
1. `terraform init`
77+
78+
1. `terraform apply`. This will create the state bucket and locking table.
79+
80+
1. Then add a `backend` that uses the new bucket and table:
81+
```hcl
82+
terraform {
83+
required_version = ">= 0.11.3"
84+
85+
backend "s3" {
86+
region = "us-east-1"
87+
bucket = "< the name of the S3 bucket >"
88+
key = "terraform.tfstate"
89+
dynamodb_table = "< the name of the DynamoDB table >"
90+
encrypt = true
91+
}
92+
}
93+
94+
module "another_module" {
95+
source = "....."
96+
}
97+
```
98+
99+
1. `terraform init`. Terraform will detect that you're trying to move your state into S3 and ask, "Do you want to copy existing state to the new backend?" Enter "yes". Now state is stored in the bucket and the DynamoDB table will be used to lock the state to prevent concurrent modifications.
102100

103101
<br/>
104102

@@ -155,9 +153,9 @@ Available targets:
155153

156154

157155

158-
## Share the Love
156+
## Share the Love
159157

160-
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-tfstate-backend)! (it helps us **a lot**)
158+
Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-tfstate-backend)! (it helps us **a lot**)
161159

162160
Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
163161

@@ -181,9 +179,9 @@ File a GitHub [issue](https://github.com/cloudposse/terraform-aws-tfstate-backen
181179

182180
## Commercial Support
183181

184-
Work directly with our team of DevOps experts via email, slack, and video conferencing.
182+
Work directly with our team of DevOps experts via email, slack, and video conferencing.
185183

186-
We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.
184+
We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.
187185

188186
[![E-Mail](https://img.shields.io/badge/[email protected])][email]
189187

@@ -193,7 +191,7 @@ We provide [*commercial support*][commercial_support] for all of our [Open Sourc
193191
- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects.
194192
- **Build New Terraform Modules.** We'll [develop original modules][module_development] to provision infrastructure.
195193
- **Cloud Architecture.** We'll assist with your cloud strategy and design.
196-
- **Implementation.** We'll provide hands-on support to implement our reference architectures.
194+
- **Implementation.** We'll provide hands-on support to implement our reference architectures.
197195

198196

199197

@@ -208,7 +206,7 @@ Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Ou
208206

209207
## Newsletter
210208

211-
Signup for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
209+
Signup for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
212210

213211
## Contributing
214212

@@ -233,13 +231,13 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
233231

234232
## Copyright
235233

236-
Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
234+
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)
237235

238236

239237

240-
## License
238+
## License
241239

242-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
240+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
243241

244242
See [LICENSE](LICENSE) for full details.
245243

README.yaml

+41-43
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ related:
3838

3939
# Short description of this project
4040
description: |-
41-
Terraform module to provision an S3 bucket to store `terraform.tfstate` file and a DynamoDB table to lock the state file
41+
Terraform module to provision an S3 bucket to store `terraform.tfstate` file and a DynamoDB table to lock the state file
4242
to prevent concurrent modifications and state corruption.
4343
4444
The module supports the following:
@@ -57,48 +57,46 @@ description: |-
5757
5858
# How to use this project
5959
usage: |-
60-
```hcl
61-
terraform {
62-
required_version = ">= 0.11.3"
63-
}
64-
65-
module "terraform_state_backend" {
66-
source = "git::https://github.com/cloudposse/terraform-aws-tfstate-backend.git?ref=master"
67-
namespace = "cp"
68-
stage = "prod"
69-
name = "terraform"
70-
attributes = ["state"]
71-
region = "us-east-1"
72-
}
73-
```
74-
75-
__NOTE:__ First create the bucket and table without any state enabled (Terraform will use the local file system to store state).
76-
You can then import the bucket and table by using [`terraform import`](https://www.terraform.io/docs/import/index.html) and store the state file into the bucket.
77-
78-
Once the bucket and table have been created, configure the [backend](https://www.terraform.io/docs/backends/types/s3.html)
79-
80-
```hcl
81-
terraform {
82-
required_version = ">= 0.11.3"
83-
84-
backend "s3" {
85-
region = "us-east-1"
86-
bucket = "< the name of the S3 bucket >"
87-
key = "terraform.tfstate"
88-
dynamodb_table = "< the name of the DynamoDB table >"
89-
encrypt = true
90-
}
91-
}
92-
93-
module "another_module" {
94-
source = "....."
95-
}
96-
```
97-
98-
Initialize the backend with `terraform init`.
99-
100-
After `terraform apply`, `terraform.tfstate` file will be stored in the bucket,
101-
and the DynamoDB table will be used to lock the state to prevent concurrent modifications.
60+
1. Define the module in your `.tf` file using local state:
61+
```hcl
62+
terraform {
63+
required_version = ">= 0.11.3"
64+
}
65+
66+
module "terraform_state_backend" {
67+
source = "git::https://github.com/cloudposse/terraform- aws-tfstate-backend.git?ref=master"
68+
namespace = "cp"
69+
stage = "prod"
70+
name = "terraform"
71+
attributes = ["state"]
72+
region = "us-east-1"
73+
}
74+
```
75+
76+
1. `terraform init`
77+
78+
1. `terraform apply`. This will create the state bucket and locking table.
79+
80+
1. Then add a `backend` that uses the new bucket and table:
81+
```hcl
82+
terraform {
83+
required_version = ">= 0.11.3"
84+
85+
backend "s3" {
86+
region = "us-east-1"
87+
bucket = "< the name of the S3 bucket >"
88+
key = "terraform.tfstate"
89+
dynamodb_table = "< the name of the DynamoDB table >"
90+
encrypt = true
91+
}
92+
}
93+
94+
module "another_module" {
95+
source = "....."
96+
}
97+
```
98+
99+
1. `terraform init`. Terraform will detect that you're trying to move your state into S3 and ask, "Do you want to copy existing state to the new backend?" Enter "yes". Now state is stored in the bucket and the DynamoDB table will be used to lock the state to prevent concurrent modifications.
102100
103101
<br/>
104102

0 commit comments

Comments
 (0)