stavxyz / terraform-aws-backend

A Terraform module for your AWS Backend + a guide for bootstrapping your terraform managed project
Apache License 2.0
53 stars 32 forks source link

provide script or instruction for utilizing s3 versioned bucket for rolling back state #2

Open stavxyz opened 6 years ago

stavxyz commented 6 years ago

Since this module ensures that terraform users provision a versioned bucket for state, it should also provide instructions for why that is useful and how to roll back in case of disasters.

wip

  1. List state bucket versions:
aws s3api list-object-versions --bucket terraform-state-bucket | jq '.Versions|sort_by(.LastModified)'
  1. Get the version you want ( revert.tfstate is used as the <outfile> arg )

TODO: How can a user determine which version they want? Previewing state by pulling an object version and pointing terraform show at it? That's the only way I can think of. Sounds like this is going to turn into a weird side project/tool.

aws s3api get-object --bucket terraform-state-bucket --version-id ZZZZZZ ... revert.tfstate
  1. Check out the content type (probably application/json ) and metadata (if any)

    aws s3api head-object --version-id ZZZZZZ --bucket terraform-state-bucket --key terraform.tfstate
  2. Copy previous object version

    aws s3 cp revert.tfstate s3://terraform-state-bucket/revert.tfstate
  3. Set as current version:

aws s3 cp s3://terraform-state-bucket/revert.tfstate s3://terraform-state-bucket/terraform.tfstate