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

Output selected terraform version #326

Closed
F21 opened this issue May 30, 2023 · 5 comments
Closed

Output selected terraform version #326

F21 opened this issue May 30, 2023 · 5 comments

Comments

@F21
Copy link

F21 commented May 30, 2023

It would be nice if the version of terraform that is installed can be set as an output variable, so that it can be used by other steps in a workflow.

This would be especially useful when semver is used to select a version of terraform, for example, if terraform_version is set to ~1.4, and the output would contain the version that is ultimately selected, such as 1.4.6.

@officel
Copy link

officel commented Aug 26, 2023

@F21 Hi!

Is this what you mean?
https://github.com/hashicorp/setup-terraform/blob/main/.github/workflows/setup-terraform.yml#L14

It does not seem necessary to create output in setup-terraform.
We can write code to get the version for other steps.

@F21
Copy link
Author

F21 commented Aug 26, 2023

@officel According to https://github.com/hashicorp/setup-terraform?tab=readme-ov-file#inputs, we can use semver to select the terraform version, so we don't know the version that will be installed before hand. If we can access the final version that was selected, we would be able to use it in other steps.

@officel
Copy link

officel commented Aug 27, 2023

Seems like there is no need to output it in the setup-terrafom since we can always use the latest or a fixed version?

But.. so.. if you just want to get the version, you can do it in just a few lines.
try this.
The key is to set wapper to false or use terraform-bin.

cat .github/workflows/terraform_version.yml
name: terraform version

on:
  workflow_dispatch:

jobs:
  tv:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        versions:
          - "latest"
          - "1.4"
          - "1.1"
    outputs:
      version: ${{ steps.terraform_version.outputs.version }}
    steps:
      - uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: ${{ matrix.versions }}
      - id: terraform_version
        run: |
          echo $(terraform-bin version -json | jq -r ".terraform_version")
          echo "version=" $(terraform-bin version -json | jq -r ".terraform_version") >> "$GITHUB_OUTPUT"

@F21
Copy link
Author

F21 commented Aug 27, 2023

That works! Thanks 😄

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants