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

How do I set the terraform version the wrapper is using dynamically? #432

Closed
red8888 opened this issue Sep 4, 2024 · 1 comment
Closed

Comments

@red8888
Copy link

red8888 commented Sep 4, 2024

I have this setup to run on a list of directories some of which will have terraform version files I want to use to set the terraform version.

I'm not asking for .terraform-version support I just want to know how I can add this manually.

I also want to use the terraform wrapper to get the output in the PR but I can't figure out how to tell the wrapper what terraform version to use.

Its going to be different for every folder so I can't statically set with.terraform_version from the output of a previous job or anything. I need to set it inside of the job with hashicorp/setup-terraform.

How is this possible? I tried setting this env var I saw in the code to tfenv: export TERRAFORM_CLI_PATH="$HOME/.tfenv/bin" but that doesn't work.

I want to use the terraform wrapper of this workflow not a raw tf exe so I can get the nice output.

@red8888
Copy link
Author

red8888 commented Sep 4, 2024

Never mind I didn't understand how gh actions worked

I was able to define an output in the job and pass it to the workflow

  - name: Set Version
    id: tf_version
    run: |
      # Script reads version files and sets github output like this: echo "tf_version=$TF_VERSION" >> "$GITHUB_OUTPUT"
      my_script.sh

  - uses: hashicorp/setup-terraform@v2
    with:
      # Use output set in previous step as input to the workflow
      terraform_version: ${{ steps.tf_version.outputs.tf_version }}

@red8888 red8888 closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant