Created
May 4, 2020 18:26
-
-
Save lancehudson/358bde15160c13eae85ddc17ecc66a42 to your computer and use it in GitHub Desktop.
Export all regions with terraforming
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
#!/usr/bin/env bash | |
TERRAFORMING="~/.gem/ruby/2.6.0/bin/terraforming" | |
AWS_PROFILE="dev" | |
AWS_REGIONS=($(AWS_PROFILE=$AWS_PROFILE aws ec2 describe-regions | jq -r '.Regions[].RegionName')) | |
COMPONENTS=($($TERRAFORMING help | grep terraforming | grep -v help | awk '{print $2}')) | |
for REGION in "${AWS_REGIONS[@]}" | |
do | |
rm -rf $REGION | |
mkdir -p $REGION | |
for COMPONENT in "${COMPONENTS[@]}" | |
do | |
if [[ $COMPONENT != iam* ]] || [[ $REGION = us-east-1 ]] | |
then | |
$TERRAFORMING $COMPONENT --profile $AWS_PROFILE --region $REGION > $REGION/$COMPONENT.tf | |
fi | |
done | |
done | |
find . -type f -name '*.tf' | xargs wc -l | grep ' 1 .' | awk '{print $2}' | xargs rm | |
find . -empty -type d -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment