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

✨ feat(versionfile): accept versionfile #324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tush-tr
Copy link

@tush-tr tush-tr commented May 26, 2023

Added input support for terraform version file

Description

This pull request introduces a new feature to the setup-terraform action, allowing it to accept the Terraform version from a file. It addresses two previously opened issues: #208, #298. The feature enables users to specify the desired Terraform version through a terraform_version_file.

Changes Made

  • Added support for reading the Terraform version from a .terraformrc(or any terraform version) file.

Motivation

The motivation behind this feature is to provide more flexibility in specifying the Terraform version used within GitHub Action workflows. With the addition of this feature, users can define the Terraform version in a separate file, allowing for easier management and version control of the desired version across different workflows.

How to Use

To utilize this new feature, follow these steps:

  1. Update your existing GitHub Action workflow file (*.yml) that uses setup-terraform.
  2. Add a new input called terraform_version_file to the setup-terraform action, specifying the path to the file containing the desired Terraform version.
  3. Commit and push the updated workflow file to your repository.
  4. When the workflow runs, the setup-terraform action will read the Terraform version from the specified file and install the corresponding CLI version.

Example workflow configuration:

name: Terraform Workflow

on:
  push:
    branches:
      - main

jobs:
  terraform:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version_file: .terraform-version

      # Continue with the rest of your workflow steps...

@tush-tr tush-tr requested a review from a team as a code owner May 26, 2023 22:52
@hashicorp-cla
Copy link

hashicorp-cla commented May 26, 2023

CLA assistant check
All committers have signed the CLA.

@bendbennett bendbennett added the tf-devex-triage Terraform DevEx project tracking label May 30, 2023
@bendbennett
Copy link
Contributor

Hi @tush-tr 👋

Thank you for taking the time to create and submit this PR. We will need to discuss this change so that we can reach a product decision on whether the GitHub Action should accept a form of a “version” file. I have therefore marked this PR as requiring triage so that this can be discussed.

@phyzical
Copy link

phyzical commented Aug 18, 2023

@bendbennett just thought i would add 1 argument to supporting this feature

  • renovatebot supports the file making it a some what defacto similar to .ruby-version for ruby

Granted the workaround is just cat .terraform-version and provide it directly to terraform_version

);
}

version = await fs.readFile(versionFilePath, "utf-8");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this won't work if tfutils/tfenv#347 (allow whole line comments) is merged, and assuming of course that the user has the version file due to using tfenv.

I say this mainly because I think it's an important consideration for the (Hashicorp) team in making a product decision about it as mentioned above: terraform itself doesn't have a version file concept, so either:

  1. setup-terraform would support a simple 'just the version' format, and Hashicorp owns that format;
  2. it tries to support all formats seen in the wild, on the basis of user reports that certain things (like comments) break it or something (and, er, hopes they never conflict?);
  3. it declares support for a specific format (e.g. tfenv's) and aims to support that (and inherently then breaking changes in that format necessitate breaking changes in setup-terraform)

@bflad bflad self-assigned this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tf-devex-triage Terraform DevEx project tracking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants