{"id":21261386,"url":"https://github.com/dflook/tofu-version","last_synced_at":"2026-02-23T02:03:34.026Z","repository":{"id":203571069,"uuid":"708929179","full_name":"dflook/tofu-version","owner":"dflook","description":"GitHub action to determine OpenTofu version for a configuration","archived":false,"fork":false,"pushed_at":"2025-02-28T19:03:32.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T22:53:29.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dflook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["dflook"]}},"created_at":"2023-10-23T17:05:17.000Z","updated_at":"2025-02-28T19:03:34.000Z","dependencies_parsed_at":"2023-12-08T14:53:03.781Z","dependency_job_id":"89b5e2df-4181-4d03-a3d1-166c9797d30b","html_url":"https://github.com/dflook/tofu-version","commit_stats":null,"previous_names":["dflook/tofu-version"],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Ftofu-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Ftofu-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Ftofu-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflook%2Ftofu-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflook","download_url":"https://codeload.github.com/dflook/tofu-version/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243695587,"owners_count":20332629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T04:29:22.655Z","updated_at":"2025-10-26T14:13:00.747Z","avatar_url":"https://github.com/dflook.png","language":null,"funding_links":["https://github.com/sponsors/dflook"],"categories":[],"sub_categories":[],"readme":"# tofu-version action\n\nThis is one of a suite of OpenTofu related actions - find them at [dflook/terraform-github-actions](https://github.com/dflook/terraform-github-actions).\n\nThis action determines the OpenTofu and provider versions to use for the root module.\n\nThe best way to specify the version is using a [`required_version`](https://opentofu.org/docs/language/settings/#specifying-a-required-opentofu-version) constraint.\n\nThe version to use is discovered from the first of:\n\n1. The version set in the cloud workspace if the module uses a `remote` backend or `cloud` configuration, and the remote workspace exists.\n2. A [`required_version`](https://opentofu.org/docs/language/settings/#specifying-a-required-opentofu-version) constraint in the OpenTofu configuration.\n   If the constraint is range, the latest matching version is used.\n3. A [tfswitch](https://warrensbox.github.io/terraform-switcher/) `.tfswitchrc` file in the module path\n4. A [tofuenv](https://github.com/tofuutils/tofuenv) `.opentofu-version` file in the module path\n5. A [tfenv](https://github.com/tfutils/tfenv) `.terraform-version` file in the module path\n6. An [asdf](https://asdf-vm.com/) `.tool-versions` file in the module path or any parent path\n7. An `OPENTOFU_VERSION` environment variable containing a [version constraint](https://opentofu.org/docs/language/expressions/version-constraints/).\n   If the constraint allows multiple versions, the latest matching version is used.\n8. A `TERRAFORM_VERSION` environment variable containing a [version constraint](https://opentofu.org/docs/language/expressions/version-constraints/).\n   If the constraint allows multiple versions, the latest matching version is used.\n9. The OpenTofu version that created the current state file (best effort).\n10. The latest OpenTofu version\n\nThe version of OpenTofu and all required providers will be output to the workflow log.\n\nOther tofu actions automatically determine the OpenTofu version\nin the same way. You only need to run this action if you want to use the\noutputs yourself.\n\n## Inputs\n\n* `path`\n\n  The path to the OpenTofu root module directory.\n\n  - Type: string\n  - Optional\n  - Default: The action workspace\n\n* `workspace`\n\n  The workspace to determine the OpenTofu version for.\n\n  - Type: string\n  - Optional\n  - Default: `default`\n\n* `backend_config`\n\n  List of OpenTofu backend config values, one per line.\n\n  This will be used to fetch the OpenTofu version set in the cloud workspace if using the `remote` backend.\n  For other backend types, this is used to fetch the version that most recently wrote to the OpenTofu state.\n\n  ```yaml\n  with:\n    backend_config: token=${{ secrets.BACKEND_TOKEN }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `backend_config_file`\n\n  List of OpenTofu backend config files to use, one per line.\n  Paths should be relative to the GitHub Actions workspace\n\n  This will be used to fetch the OpenTofu version set in the cloud workspace if using the `remote` backend.\n  For other backend types, this is used to fetch the version that most recently wrote to the OpenTofu state.\n\n  ```yaml\n  with:\n    backend_config_file: prod.backend.tfvars\n  ```\n\n  - Type: string\n  - Optional\n\n## Outputs\n\n* `terraform`\n\n  The Hashicorp Terraform or OpenTofu version that is used by the configuration.\n\n  - Type: string\n\n* `tofu`\n\n  If the action chose a version of OpenTofu, this will be set to the version that is used by the configuration.\n\n  - Type: string\n\n* Provider Versions\n\n  Additional outputs are added with the version of each provider that\n  is used by the OpenTofu configuration. For example, if the random\n  provider is used:\n\n  ```hcl\n  provider \"random\" {\n    version = \"2.2.0\"\n  }\n  ```\n\n  A `random` output will be created with the value `2.2.0`.\n\n  - Type: string\n\n## Environment Variables\n\n* `GITHUB_DOT_COM_TOKEN`\n\n  This is used to specify a token for GitHub.com when the action is running on a GitHub Enterprise instance.\n  This is only used for downloading OpenTofu binaries from GitHub.com.\n  If this is not set, an unauthenticated request will be made to GitHub.com to download the binary, which may be rate limited.\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_CLOUD_TOKENS`\n\n  API tokens for cloud hosts, of the form `\u003chost\u003e=\u003ctoken\u003e`. Multiple tokens may be specified, one per line.\n  These tokens may be used with the `remote` backend and for fetching required modules from the registry.\n\n  e.g:\n\n  ```yaml\n  env:\n    TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }}\n  ```\n\n  With other registries:\n\n  ```yaml\n  env:\n    TERRAFORM_CLOUD_TOKENS: |\n      app.terraform.io=${{ secrets.TF_CLOUD_TOKEN }}\n      tofu.example.com=${{ secrets.TF_REGISTRY_TOKEN }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_SSH_KEY`\n\n  A SSH private key that OpenTofu will use to fetch git/mercurial module sources.\n\n  This should be in PEM format.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_SSH_KEY: ${{ secrets.TERRAFORM_SSH_KEY }}\n  ```\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_HTTP_CREDENTIALS`\n\n  Credentials that will be used for fetching modules sources with `git::http://`, `git::https://`, `http://` \u0026 `https://` schemes.\n\n  Credentials have the format `\u003chost\u003e=\u003cusername\u003e:\u003cpassword\u003e`. Multiple credentials may be specified, one per line.\n\n  Each credential is evaluated in order, and the first matching credentials are used.\n\n  Credentials that are used by git (`git::http://`, `git::https://`) allow a path after the hostname.\n  Paths are ignored by `http://` \u0026 `https://` schemes.\n  For git module sources, a credential matches if each mentioned path segment is an exact match.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_HTTP_CREDENTIALS: |\n      example.com=dflook:${{ secrets.HTTPS_PASSWORD }}\n      github.com/dflook/terraform-github-actions.git=dflook-actions:${{ secrets.ACTIONS_PAT }}\n      github.com/dflook=dflook:${{ secrets.DFLOOK_PAT }}\n      github.com=graham:${{ secrets.GITHUB_PAT }}  \n  ```\n\n  - Type: string\n  - Optional\n\n* `TERRAFORM_PRE_RUN`\n\n  A set of commands that will be ran prior to `tofu init`. This can be used to customise the environment before running OpenTofu.\n\n  The runtime environment for these actions is subject to change in minor version releases. If using this environment variable, specify the minor version of the action to use.\n\n  The runtime image is currently based on `debian:bookworm`, with the command run using `bash -xeo pipefail`.\n\n  For example:\n\n  ```yaml\n  env:\n    TERRAFORM_PRE_RUN: |\n      # Install latest Azure CLI\n      curl -skL https://aka.ms/InstallAzureCLIDeb | bash\n\n      # Install postgres client\n      apt-get install -y --no-install-recommends postgresql-client\n  ```\n\n  - Type: string\n  - Optional\n\n## Example usage\n\n```yaml\non: [push]\n\njobs:\n  required_version:\n    runs-on: ubuntu-latest\n    name: Print the required OpenTofu and provider versions\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n\n      - name: Test tofu-version\n        uses: dflook/tofu-version@v2\n        id: tofu-version\n        with:\n          path: my-configuration\n\n      - name: Print the version\n        run: echo \"The version was ${{ steps.tofu-version.outputs.tofu }}\"\n\n      - name: Print aws provider version\n        run: echo \"The aws provider version was ${{ steps.tofu-version.outputs.aws }}\"        \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Ftofu-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflook%2Ftofu-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflook%2Ftofu-version/lists"}