Skip to content

Instantly share code, notes, and snippets.

@madsonic
Last active February 18, 2021 09:08
Show Gist options
  • Save madsonic/6baaee944476e49d348d4b2d83224ee5 to your computer and use it in GitHub Desktop.
Save madsonic/6baaee944476e49d348d4b2d83224ee5 to your computer and use it in GitHub Desktop.
terragrunt 0.23 migration script
#!/usr/bin/env bash
# 0.23.0 terragrunt migration script
# behaviour of find_in_parent_folders() has changed to use absolute path
# https://github.com/gruntwork-io/terragrunt/releases/tag/v0.23.0
# this has been test on macOS
# you might need to change some flags for certain distro of the commands used here
git stash save -u
# sed used here is macOS variant
# list all files with '${get_terragrunt_dir()}/${find_in_parent_folders' and remove ${get_terragrunt_dir()}
grep --exclude-dir={.git,.terragrunt-cache} -rnl '\${get_terragrunt_dir()}\/\${find_in_parent_folders' . | xargs sed -i'.bck' 's/\${get_terragrunt_dir()}\/\(\${find_in_parent_folders\)/\1/g'
git ls-files | grep '\.hcl' | xargs git add
git commit -m 'Use find_in_parent_folders() only'
git clean -df
# impose terragrunt version constraint so that user will use an incompatible version unknowingly
# < 0.23 will get a syntax error which is acceptable as a warning to upgrade as well
# root terragrunt.hcl files are excluded to avoid duplicates
# only leaf terragrunt dir are constrained to allow each dir to easily opt out of the constraint
find . -type f -name '*.hcl' -not -path '**/.terragrunt-cache/*' -not -path '**/.git/*' -not -path '.scripts/*' | xargs -n 1 grep -L 'remote_state' | xargs -n 1 sed -i'.bck' '1 i\
terragrunt_version_constraint = "~> 0.23.0"
'
git ls-files | grep '\.hcl' | xargs git add
git commit -m 'Add terragrunt version constraint'
git clean -df
# reset any remaining changed file
git checkout -- .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment