terraform-github-actions

terraform-version action

This is one of a suite of Terraform related actions - find them at dflook/terraform-github-actions.

This action determines the Terraform and provider versions to use for the root module.

The best way to specify the version is using a required_version constraint.

The version to use is discovered from the first of:

  1. The version set in the cloud workspace if the module uses a remote backend or cloud configuration, and the remote workspace exists.
  2. A required_version constraint in the Terraform configuration. If the constraint is range, the latest matching version is used.
  3. A tfswitch .tfswitchrc file in the module path
  4. When using a dflook/tofu-* action, a tofuenv .opentofu-version file in the module path
  5. A tfenv .terraform-version file in the module path
  6. An asdf .tool-versions file in the module path or any parent path
  7. An OPENTOFU_VERSION environment variable containing a version constraint. If the constraint allows multiple versions, the latest matching version is used.
  8. A TERRAFORM_VERSION environment variable containing a version constraint. If the constraint allows multiple versions, the latest matching version is used.
  9. The Terraform version that created the current state file (best effort).
  10. The latest Terraform version

The version of Terraform and all required providers will be output to the workflow log.

Other terraform actions automatically determine the Terraform version in the same way. You only need to run this action if you want to use the outputs yourself.

Inputs

Environment Variables

Outputs

Example usage

on: [push]

jobs:
  required_version:
    runs-on: ubuntu-latest
    name: Print the required Terraform and provider versions
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Test terraform-version
        uses: dflook/terraform-version@v1
        id: terraform-version
        with:
          path: my-configuration

      - name: Print the version
        run: echo "The version was $"
        
      - name: Print aws provider version
        run: echo "The aws provider version was $"