Last active
August 6, 2018 14:48
-
-
Save kerin/0b176b9580e704c5b22a2d1cf9b9cf53 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
if [ $# -lt 1 ]; then | |
echo 1>&2 "$0: Arguments: ENVIRONMENT" | |
exit 2 | |
fi | |
env=$1 | |
cwd=$(pwd) | |
cd ../environments/$env | |
IFS= | |
resources=$( \ | |
terraform show -no-color \ | |
| grep -A1 "^module" \ | |
| grep -v '^--' \ | |
| sed -e 's/^ id = //g' \ | |
| sed -Ee 's/\.([0-9]+):/[\1]/g' \ | |
| sed -e 's/:$//g' \ | |
| awk 'NR%2{printf "%s ",$0;next;}1' \ | |
| grep -v '\.data\.' \ | |
) | |
cd $cwd | |
workspace=$(terraform workspace show) | |
IFS=' ' | |
echo $resources | while read -r resource; do | |
read -r -a parts <<< "$resource" | |
terraform import -var-file=vars/$workspace.tfvars ${parts[0]} ${parts[1]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment