Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active March 28, 2019 17:56
Show Gist options
  • Save jayers99/ab1db900e6a5c3dd1abf9ced3745ccd1 to your computer and use it in GitHub Desktop.
Save jayers99/ab1db900e6a5c3dd1abf9ced3745ccd1 to your computer and use it in GitHub Desktop.
# -i case insensitive
# -l just show file path
# -r recursive
# -n line number
searchTerm=""
# just list the files containing search term
egrep -irl --include \*.tf --exclude-dir=.* "$searchTerm"
# to see the search term
egrep -irn --include \*.tf --exclude-dir=.* "$searchTerm"
# start of some terraform linting
# look for hard coded regions
searchTerm="\s+="
egrep -irn --include \*.tf --exclude-dir=.* "$searchTerm"
# list all the arn referances
grep -ir --no-filename --include \*.tf --exclude-dir=.terraform --exclude-dir=.git -Poh '\"arn:aws:iam::.+:role.+\"' | sort | uniq -c | sort -rn
# get distribution of aws provider versions
grep -irP --no-filename --include \*.tf --exclude-dir=.terraform --exclude-dir=.git '\bversion\s*=' | sed 's/^\s*//g' | sort | uniq -c | sort -rn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment