Skip to content

Instantly share code, notes, and snippets.

@cobusbernard
Created December 11, 2017 08:47
Show Gist options
  • Save cobusbernard/cf38f1bbbf9e9b3289f144f1e135d81f to your computer and use it in GitHub Desktop.
Save cobusbernard/cf38f1bbbf9e9b3289f144f1e135d81f to your computer and use it in GitHub Desktop.
function get-tfstate() {
if [ -z $1 ]; then
echo "You must specify the environment!"
return
fi
if [ -z $2 ]; then
echo "You must specify the system!"
return
fi
aws --profile <company-prefix>-$1 s3 cp s3://<statefile bucket>/env:/$1/$2/terraform.tfstate ./
cp ./terraform.tfstate ./terraform.tfstate.backup
}
function set-tfstate() {
if [ -z $1 ]; then
echo "You must specify the environment!"
return
fi
if [ -z $2 ]; then
echo "You must specify the system!"
return
fi
if [ -z $3 ]; then
echo "You must specify the statefile to upload!"
return
fi
aws --profile <company-prefix>-$1 s3 cp --acl bucket-owner-full-control $3 s3://<statefile bucket>/env:/$1/$2/terraform.tfstate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment