Skip to content

Instantly share code, notes, and snippets.

@andytumelty
Last active February 23, 2018 11:32
Show Gist options
  • Save andytumelty/4ad9c2258c2f10f4fd79c186affabe05 to your computer and use it in GitHub Desktop.
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?
# 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