Terragrunt Notes.md 2.8 KB

Terragrunt Notes

aka "how to develop the terraform 12+ stuff"

Local cache of providers

helpful tip, speed up cache by adding the following to your ~./bashrc:

export TF_PLUGIN_CACHE_DIR=~/.terraform.d/plugin-cache
[[ -d "$TF_PLUGIN_CACHE_DIR" ]] || mkdir -p $TF_PLUGIN_CACHE_DIR

Renaming Directories/Resources

General process:

  1. Make sure everything's up to date.
  2. Move the remote state.
  3. Update the configuration.
  4. Rename the directory
  5. Make sure terragrunt applies cleanly (But updates all the tags, so lots of changes to review)

For this example, I was renaming 010-standard-vpc to 010-vpc-splunk in test/aws-us-gov/mdr-test-modelclient.

cd 010-standard-vpc/
# clear out cache to make our lives easier
rm -rf .terragrunt-cache
# validate that we're on latest code
terragrunt-local apply
# Get the `bucket` and 'key' value
cat `find . -name 'backend.tf'`
# In this example:
#   bucket         = "afsxdr-terraform-state"
#   key            = "aws/test/aws-us-gov/mdr-test-modelclient/010-standard-vpc/terraform.tfstate"
aws --profile mdr-common-services-gov \
  s3 mv \
   s3://afsxdr-terraform-state/aws/test/aws-us-gov/mdr-test-modelclient/010-standard-vpc/terraform.tfstate \
   s3://afsxdr-terraform-state/aws/test/aws-us-gov/mdr-test-modelclient/010-vpc-splunk/terraform.tfstate
# move and rename
cd ..
git mv 010-standard-vpc 010-vpc-splunk
cd 010-vpc-splunk
# Apply again: NOTE: The only changes should be to the tags. Do not accept any other changes, or you will have extra resources
rm -rf .terragrunt-cache
terragrunt-local apply

If you get:

Error refreshing state: state data in S3 does not have the expected content.

You forgot to rename the directory you're working in.

GitFlow Notes

These notes will walk you through the Terragrunt git flow for making changes.

  • Fork the Master branch to your branch
  • change local xdr-terrafrom-live repo with expected new tag ( so you don't forget to do it when you are done. )
  • make changes to xdr-terraform-modules
  • make changes to xdr-terraform-live
  • increment the ref=v0.x.x in your terragrunt.hcl
  • use terragrunt-local to try the changes
  • ( did you run the saml command to login?)
  • use tgswitch to change versions
  • rm -rf .terragrunt-cache to resolve "strange" errors
  • push new branch to github
  • get pr approved and merged in
  • tag master to latest tag that is set in terragrunt.hcl
  • verify it is working in TEST without terragrunt-local
  • deploy to PROD
  • delete github branch and close jira ticket

Destroy instances

TF_VAR_instance_termination_protection=false terragrunt apply
TF_VAR_instance_termination_protection=false terragrunt destroy

tfswitch.toml

colby-williams taught me: cp -ar to copy symlinks correctly.

ln -s ../../../../.tfswitch.toml .

ls -larth .tfswitch.toml -> ../../../../.tfswitch.toml