Skip to content
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

Add support for .terraform-version file #298

Open
lukasz-mitka opened this issue Feb 3, 2023 · 7 comments · May be fixed by #454
Open

Add support for .terraform-version file #298

lukasz-mitka opened this issue Feb 3, 2023 · 7 comments · May be fixed by #454
Assignees
Labels
enhancement New feature or request

Comments

@lukasz-mitka
Copy link

Same way actions/setup-node or actions/setup-python handle setting version from a file.
It could default to .terraform-version file as tfenv already uses it: https://github.com/tfutils/tfenv#terraform-version-file and matches pattern for other actions.

@gunta
Copy link

gunta commented Feb 16, 2023

Something like this logic would work perfect
https://github.com/actions/setup-node/blob/ae9f0f7448e93b1be0f44663e79763dbdffcc4da/src/main.ts#L80

@Crisfole
Copy link

  - name: Get Terraform Version
    id: tf_version
    run: |
      echo "value=$(cat .terraform-version)" >> $GITHUB_OUTPUT

Then later you can ${{ steps.env_name.outputs.value }}

@lukasz-mitka
Copy link
Author

@Crisfole this is a good workaround, but the idea is to have built-in solution like other actions have (https://github.com/actions/setup-node or https://github.com/actions/setup-python)

Also please fix your snippet. It should be ${{ steps.tf_version.outputs.value }}

@pioneer2k
Copy link

There are other tools on the market that uses this mechanism, like Mend Renovate for creating automated pull requests for dependency updates: https://docs.renovatebot.com/modules/manager/terraform-version/

@Crisfole
Copy link

@Crisfole this is a good workaround, but the idea is to have built-in solution like other actions have

Oh, for sure! But two years from now when I Google this again I want to have that comment available to me! 😆

@bflad bflad self-assigned this Nov 29, 2023
@bflad bflad added the enhancement New feature or request label Nov 29, 2023
@v1v v1v linked a pull request Dec 9, 2024 that will close this issue
@lvjp
Copy link

lvjp commented Dec 18, 2024

Why do not compute the version from the definition file.
I think that if we care about versioning, we must have a provider.tf like this :

terraform {
  required_version = "~> 1.10.0"
}

Maybe, an implementation like action/setup-go will be good and look like this :

uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
    terraform_version_file: provider.tf

This solution permits to not maintain version condition in two files instead of only in the terraform definitions.

@kittydoor
Copy link

These are two different things.

The constraints in the provider.tf specify lower and upper boundaries for support of terraform cli for the specific module.

.terraform-version file specifies the actively in use terraform version.

The constraints can be ~> 1.10.0 but you want to in you CI use 1.10.1 exactly rather than leave it to chance, and thus .terraform-version exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants