One-liners to quickly summarize Terraform
Created: December 01, 2020
I built these one lines to quickly summarize unfamiliar Terraform that has no
documentation available. They do rely on the Terraform being correctly formatted
with terraform fmt
.
Summarize resources in Terraform modules
grep -RPn "^resource " | grep "modules/" | sed 's/:/ /g' | sed 's/"//g' | cut -f1-2,4-5 -d" " | column -t | sort -k 4
Summarize resources outside of Terraform modules
grep -RPn "^resource " | grep -v "modules/" | sed 's/:/ /g' | sed 's/"//g' | cut -f1-2,4-5 -d" " | column -t | sort -k 4
Summarize module blocks and their sources
grep -A5 -RPn "^module " | grep -P "module|source = " | sed 's/.*source\s*=\s*/source /g' | sed -z 's/{\n//g' | sed 's/:/ /g' | sed 's/"//g' | cut -f1-2,4,6 -d" " | sort -k3 | column -t