Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save josephsindel/5e37571e360a50071904a9edb58df5ee to your computer and use it in GitHub Desktop.
Save josephsindel/5e37571e360a50071904a9edb58df5ee to your computer and use it in GitHub Desktop.
cat gen_statefile.sh
#!/bin/bash -x
TYPE=$1
REGION=$2
if [ -n "${REGION}" ] || [ -n "${TYPE}" ]
then
rm -rf /tmp/tmpstate
git clone ssh://git@github.com/ringdna/tfmodule_statefile-generator.git .statefile
terraform init .statefile/
terraform apply -state=.statefile/terraform.tfstate -var region=$REGION -var type=$TYPE -auto-approve=true .statefile/
rm -rf .terraform
rm -rf .statefile
terraform init
terraform workspace list | grep mgmt 2>&1 > /dev/null
if [ $? -ne 0 ]
then
terraform workspace new mgmt
fi
terraform workspace list | grep dev 2>&1 > /dev/null
if [ $? -ne 0 ]
then
terraform workspace new dev
fi
terraform workspace list | grep qa 2>&1 > /dev/null
if [ $? -ne 0 ]
then
terraform workspace new qa
fi
terraform workspace list | grep stg 2>&1 > /dev/null
if [ $? -ne 0 ]
then
terraform workspace new stg
fi
terraform workspace list | grep prod 2>&1 > /dev/null
if [ $? -ne 0 ]
then
terraform workspace new prod
fi
terraform workspace select default
else
echo "SPECIFY TYPE AND REGION"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment