-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read terraform version from a .terraformrc file #208
Comments
I second this, but would prefer pulling from |
+1 specifically for |
I also believe |
👍 for the |
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:
|
@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 |
/assign |
For users who liked to use the required_version block instead .terraform-version file, we are using and offer a action that use-case. https://github.com/cloudeteer/actions/tree/main/get-terraform-version |
Very cool! Here is an excerpt from the above. name: Setup Terraform
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Terraform version
id: terraform_version
uses: cloudeteer/actions/get-terraform-version@main
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ steps.terraform_version.output.required_version }} |
@nitrocode I think it is worth to keep this issue open, I'd love to see reading terraform version as built-in feature into the standard action |
Also, for those who don't want to use an extra action, we do this: - name: Set Terraform version
run: |
TF_VERSION=$(cat .terraform-version)
echo "TF_VERSION=$TF_VERSION" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: ${{ env.TF_VERSION }} You could also do something similar with Actions outputs if you preferred that. |
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 ?
The text was updated successfully, but these errors were encountered: