Using TFENV with GitHub Actions
Wouldn't it be great if hashicorp/setup-terraform would automaticly make use of tfenv's .terraform file?
Since it doesn't lets extract the contents of the file and pass that along to the setup-terraform action:
```
- name: Use terraform-version
id: terraform-version
shell: bash
run: |
TERRAFORM_VERSION="${{ github.workspace }}/.terraform-version"
if [ -f "$TERRAFORM_VERSION" ]; then
echo ".terraform-version file exists"
echo "Setting terraform version defined in .terraform-version"
echo ::set-output name=version::$(cat $TERRAFORM_VERSION)
else
echo ".terraform-version does not exist."
echo "Using `latest` terraform version"
echo ::set-output name=version::latest
fi
- name: Setup Terraform using terraform-version or latest
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ steps.terraform-version.outputs.version }}
```
---
Orginal credit goes to [Ezbon Jacob](https://github.com/codezninja) and [Jason Antman](https://github.com/jantman)
---
Photo by [engin akyurt](https://unsplash.com/@enginakyurt?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/images/nature/cloud?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)