Last active
February 23, 2018 11:32
-
-
Save andytumelty/4ad9c2258c2f10f4fd79c186affabe05 to your computer and use it in GitHub Desktop.
Terraform state corrupt? Need to extract AWS resource IDs from a state file?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# aws s3 cp s3://path/to/terraform.tfstate tmp/ | |
jq -r '.modules[].resources | keys[]' tmp/terraform.tfstate |\ | |
grep '^aws_' |\ | |
while read line | |
do | |
echo "%% $line" | |
jq -r ".modules[].resources[\"$line\"].primary.id" tmp/terraform.tfstate | |
done |\ | |
grep -v null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment