Open nitrocode opened 2 years ago
I second this, but would prefer pulling from .terraform-version
or from required_version
in the terraform block.
+1 specifically for .terraform-version
. Would be willing to PR that too.
I also believe .terraform-version
is better, because tfenv
also respects it - so "two birds with one stone" 😁
:+1: for the .terraform-version
.
Really good idea, to use .terraform-version. Mostly because, .terraformrc is reserved for this use: https://www.terraform.io/cli/config/config-file - and this could create confusion
It would be nice to have it in the setup action, but for now you can just do it this way:
- name: Set variables
run: |
TF_VERSION=$(cat .terraform-version)
echo "TF_VERSION=$TF_VERSION" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TF_VERSION }}
@karelbemelmans that's a good workaround.
I would propose a minor tweak to the version retrieval to allow comments in the file
- name: Set variables
run: |
TF_VERSION=$(grep -vP '^[\s]?#' .terraform-version)
echo "TF_VERSION=$TF_VERSION" >> $GITHUB_ENV
✗ cat .terraform-version
# this is a good version
1.2.3
✗ grep -vP '^[\s]?#' .terraform-version
1.2.3
@karelbemelmans the spec for .terraform-version
supports using a regex to calculate the correct version which isn't compatible with this action or the library used to download Terraform; these both need Terraform compatible version ranges. To support .terraform-version
spec regex patterns you'd need an additional step to download the available versions and grep through them (grep -e
in the docs).
/assign
Instead of hard coding the version in the workflow, it would be nice to have it read it from a file similar to how
actions/setup-node@v3
reads from.nvmrc
Something like this perhaps ?