Created
March 5, 2019 00:33
-
-
Save chris/3186dfb47f7d3729689f9036950ce916 to your computer and use it in GitHub Desktop.
Switch Terraform version based on .terraform-version or tfstate
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
# Switch to Terraform version for this directory. | |
# Uses presence of .terraform-version file, or find in .tfstate if possible. | |
switchtf() { | |
if [ -f .terraform-version ]; then | |
version=`cat .terraform-version` | |
chtf $version | |
echo "Switched to Terraform $version." | |
else | |
version=`grep terraform_version .terraform/terraform.tfstate | sed -E 's/^ "terraform_version": "(.+)",$/\1/'` | |
if [ -n version ]; then | |
echo "Using Terraform version $version from .terraform/terraform.tfstate" | |
chtf $version | |
else | |
echo "Couldn't detect what Terraform version to use." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment