Comments (7)
@schollii you're right, this should be documented somewhere. Right now it's not.
Please have a look here for some of the scripts we've used in the past: https://github.com/cloudposse/terraform-root-modules/tree/master/aws/tfstate-backend/scripts
from terraform-aws-tfstate-backend.
Thanks that's useful to know. It could be useful to mention the scripts in the docs, but also the procedure I mentioned, in case the scripts are not adequate for whatever reason.
from terraform-aws-tfstate-backend.
@schollii @osterman.
I found and documented a smooth way to apply and destroy using this module. See PR #46.
from terraform-aws-tfstate-backend.
So the trick of using the module's support for automatically generating a backend.tf file works really nicely and simplifies the destruction. Here is what I use.
Creation
# main.tf
module "terraform_state_backend" {
source = "git::https://github.com/cloudposse/terraform-aws-tfstate-backend.git?ref=..."
...
terraform_backend_config_file_name = "backend.tf"
terraform_backend_config_file_path = "."
force_destroy = false
}
Then this is needed only once:
terraform init
: downloads modules and providersterraform apply -auto-approve
: creates thebackend.tf
and the s3 bucket etc but state is stored locallyterraform init -force-copy
: moves the state to s3 bucket create
Since this is only once I put all these in a script init.sh
that gets run once and that's it. It seems idempotent but I have not pushed testing of that very much.
Once the above is done you can define more resources and terraform apply as needed.
Deletion
- in
main.tf
edit themodule.terraform_state_backend
to haveforce_destroy
true andterraform_backend_config_file_path
to""
terraform apply -target module.terraform_state_backend -auto-approve
: activate the above mods (s3 becomes destroyable, remove the backend.tf file)terraform init -force-copy
: move the state to local host
I put all the above in a destroy.sh
script that also check before step 3 that step 2 has been done (actually I could surely have the scrip do step 2 automatically but this way it is a more "conscious" decision by the user to destroy - running it by mistake will fail). Additionally the script does terraform init before step 2 because there are some failure conditions that need it.
from terraform-aws-tfstate-backend.
Excellent. Thank you. Could you put your scripts in a comment for reference? Then I'll rewrite my doc.
from terraform-aws-tfstate-backend.
I think this cam be closed. Nice working with you, @schollii.
from terraform-aws-tfstate-backend.
likewise @jmcgeheeiv thanks for contributing the solution in #46
from terraform-aws-tfstate-backend.
Related Issues (20)
- Dependency Dashboard
- darwin_arm64 still not supported HOT 5
- KMS encryption HOT 1
- Logging bucket generates a name with a duplicate HOT 4
- Using this module without without specifying an external context label module generates invalid resource names
- Upgrading from <0.33.1 to >=0.33.1 requires state move for bucket HOT 2
- terraform-provider-aws v4.0 incompatibility HOT 2
- Allow making changes to the s3 bucket policy
- terraform apply completes successfully with "Warning: Argument is deprecated" HOT 5
- Unable to be used with terraform workspaces HOT 2
- Reimplement with "cloudposse/terraform-aws-s3-bucket" to standardize parameters/features
- Add delete_protection to DynamoDB table HOT 3
- No compatibility with terraform v1.6 HOT 1
- Add lifecycle configuration to delete objects under a certain size to remove destroyed states
- Bucket replication managed by this module HOT 4
- Feature Request - Allow a parameter for the name of DynamoDB table HOT 1
- Error creating S3 bucket ... the region 'us-east-1' is wrong; expecting 'eu-central-1' HOT 3
- Remove the `read_capacity` and `write_capacity` from lifecycle change ignore
- Add support for multiple terraform backend config files HOT 6
- DynamoDB label attributes inconsistent due to null label module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-aws-tfstate-backend.