Skip to content

Instantly share code, notes, and snippets.

@GregoryWiltshire
Last active October 10, 2020 04:45
Show Gist options
  • Save GregoryWiltshire/d8270f114d2ab28dae131abe220c2f4b to your computer and use it in GitHub Desktop.
Save GregoryWiltshire/d8270f114d2ab28dae131abe220c2f4b to your computer and use it in GitHub Desktop.

View output of large plan

tf plan -no-color | subl  &

Migrate everything from state A → state B

Temporarily switch to a local states by commenting out any remote backends you have,
and running ‘terraform init’, ‘yes’ to copy the remote to local state files
run:
stateA=pathtostateA
stateB=pathtostateB
ex:
stateA=terraform.tfstate
stateB=../prod/terraform.tfstate
run:
while read p; do tf state mv -dry-run -state $stateA -state-out $stateB $p $p; done < <(tf state list)
Confirm the actions listed are valid, if so re-run without the -dry-run flag

List resources modified in plan

tf plan -no-color | grep -Eo '(?#) ([A-Za-z_][A-Za-z0-9_-]*)\.*(([A-Za-z0-9_-]+)\.)+([A-Za-z0-9_-]+)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment