{"id":13515466,"url":"https://github.com/opentofu/setup-opentofu","last_synced_at":"2025-04-06T02:07:18.620Z","repository":{"id":196515813,"uuid":"696284666","full_name":"opentofu/setup-opentofu","owner":"opentofu","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-17T21:40:32.000Z","size":502,"stargazers_count":99,"open_issues_count":15,"forks_count":12,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-30T01:05:33.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentofu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-25T13:03:34.000Z","updated_at":"2025-03-26T21:13:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"4ee4cdb7-2fb8-4f33-b33f-7f3dfa850b0d","html_url":"https://github.com/opentofu/setup-opentofu","commit_stats":null,"previous_names":["opentofu/setup-opentofu"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentofu%2Fsetup-opentofu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentofu%2Fsetup-opentofu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentofu%2Fsetup-opentofu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentofu%2Fsetup-opentofu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentofu","download_url":"https://codeload.github.com/opentofu/setup-opentofu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423512,"owners_count":20936626,"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-08-01T05:01:11.650Z","updated_at":"2025-04-06T02:07:18.595Z","avatar_url":"https://github.com/opentofu.png","language":"JavaScript","funding_links":[],"categories":["Tools","JavaScript"],"sub_categories":["CI"],"readme":"# GitHub Action for setting up OpenTofu\n\n\u003e [!NOTE]\n\u003e This is a community-maintained repository. The OpenTofu team does not fix non-critical bugs or add features, but is happy to review community pull requests.\n\n\u003e [!TIP]\n\u003e Having trouble with exit codes or the output format? Try setting the `tofu_wrapper` setting to `false`.\n\nThe `opentofu/setup-opentofu` action sets up OpenTofu CLI in GitHub Actions.\n\n## Usage\n\nThis action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners. When running on `windows-latest` the shell should be set to Bash.\n\nThe default configuration installs the latest version of OpenTofu CLI and installs the wrapper script to wrap subsequent calls to the `tofu` binary:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n```\n\nA specific version of OpenTofu CLI can be installed:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n  with:\n    tofu_version: 1.6.0\n```\n\nCredentials for Terraform Cloud ([app.terraform.io](https://app.terraform.io/)) can be configured:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n  with:\n    cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}\n```\n\nCredentials for Terraform Enterprise (TFE) can be configured:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n  with:\n    cli_config_credentials_hostname: 'tofu.example.com'\n    cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}\n```\n\nThe wrapper script installation can be skipped by setting the `tofu_wrapper` variable to `false`:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n  with:\n    tofu_wrapper: false\n```\n\nSubsequent steps can access outputs when the wrapper script is installed:\n\n```yaml\nsteps:\n- uses: opentofu/setup-opentofu@v1\n\n- run: tofu init\n\n- id: plan\n  run: tofu plan -no-color\n\n- run: echo ${{ steps.plan.outputs.stdout }}\n- run: echo ${{ steps.plan.outputs.stderr }}\n- run: echo ${{ steps.plan.outputs.exitcode }}\n```\n\nOutputs can be used in subsequent steps to comment on the pull request:\n\n\u003e **Notice:** There's a limit to the number of characters inside a GitHub comment (65535).\n\u003e\n\u003e Due to that limitation, you might end up with a failed workflow run even if the plan succeeded.\n\u003e\n\u003e Another approach is to append your plan into the $GITHUB_STEP_SUMMARY environment variable which supports markdown.\n\n```yaml\ndefaults:\n  run:\n    working-directory: ${{ env.tf_actions_working_dir }}\npermissions:\n  pull-requests: write\nsteps:\n- uses: actions/checkout@v3\n- uses: opentofu/setup-opentofu@v1\n\n- name: OpenTofu fmt\n  id: fmt\n  run: tofu fmt -check\n  continue-on-error: true\n\n- name: OpenTofu Init\n  id: init\n  run: tofu init\n\n- name: OpenTofu Validate\n  id: validate\n  run: tofu validate -no-color\n\n- name: OpenTofu Plan\n  id: plan\n  run: tofu plan -no-color\n  continue-on-error: true\n\n- uses: actions/github-script@v6\n  if: github.event_name == 'pull_request'\n  env:\n    PLAN: \"tofu\\n${{ steps.plan.outputs.stdout }}\"\n  with:\n    github-token: ${{ secrets.GITHUB_TOKEN }}\n    script: |\n      const output = `#### OpenTofu Format and Style 🖌\\`${{ steps.fmt.outcome }}\\`\n      #### OpenTofu Initialization ⚙️\\`${{ steps.init.outcome }}\\`\n      #### OpenTofu Validation 🤖\\`${{ steps.validate.outcome }}\\`\n      \u003cdetails\u003e\u003csummary\u003eValidation Output\u003c/summary\u003e\n\n      \\`\\`\\`\\n\n      ${{ steps.validate.outputs.stdout }}\n      \\`\\`\\`\n\n      \u003c/details\u003e\n\n      #### OpenTofu Plan 📖\\`${{ steps.plan.outcome }}\\`\n\n      \u003cdetails\u003e\u003csummary\u003eShow Plan\u003c/summary\u003e\n\n      \\`\\`\\`\\n\n      ${process.env.PLAN}\n      \\`\\`\\`\n\n      \u003c/details\u003e\n\n      *Pusher: @${{ github.actor }}, Action: \\`${{ github.event_name }}\\`, Working Directory: \\`${{ env.tf_actions_working_dir }}\\`, Workflow: \\`${{ github.workflow }}\\`*`;\n\n      github.rest.issues.createComment({\n        issue_number: context.issue.number,\n        owner: context.repo.owner,\n        repo: context.repo.repo,\n        body: output\n      })\n```\n\nInstead of creating a new comment each time, you can also update an existing one:\n\n```yaml\ndefaults:\n  run:\n    working-directory: ${{ env.tf_actions_working_dir }}\npermissions:\n  pull-requests: write\nsteps:\n- uses: actions/checkout@v3\n- uses: opentofu/setup-opentofu@v1\n\n- name: OpenTofu fmt\n  id: fmt\n  run: tofu fmt -check\n  continue-on-error: true\n\n- name: OpenTofu Init\n  id: init\n  run: tofu init\n\n- name: OpenTofu Validate\n  id: validate\n  run: tofu validate -no-color\n\n- name: OpenTofu Plan\n  id: plan\n  run: tofu plan -no-color\n  continue-on-error: true\n\n- uses: actions/github-script@v6\n  if: github.event_name == 'pull_request'\n  env:\n    PLAN: \"tofu\\n${{ steps.plan.outputs.stdout }}\"\n  with:\n    github-token: ${{ secrets.GITHUB_TOKEN }}\n    script: |\n      // 1. Retrieve existing bot comments for the PR\n      const { data: comments } = await github.rest.issues.listComments({\n        owner: context.repo.owner,\n        repo: context.repo.repo,\n        issue_number: context.issue.number,\n      })\n      const botComment = comments.find(comment =\u003e {\n        return comment.user.type === 'Bot' \u0026\u0026 comment.body.includes('OpenTofu Format and Style')\n      })\n\n      // 2. Prepare format of the comment\n      const output = `#### OpenTofu Format and Style 🖌\\`${{ steps.fmt.outcome }}\\`\n      #### OpenTofu Initialization ⚙️\\`${{ steps.init.outcome }}\\`\n      #### OpenTofu Validation 🤖\\`${{ steps.validate.outcome }}\\`\n      \u003cdetails\u003e\u003csummary\u003eValidation Output\u003c/summary\u003e\n\n      \\`\\`\\`\\n\n      ${{ steps.validate.outputs.stdout }}\n      \\`\\`\\`\n\n      \u003c/details\u003e\n\n      #### OpenTofu Plan 📖\\`${{ steps.plan.outcome }}\\`\n\n      \u003cdetails\u003e\u003csummary\u003eShow Plan\u003c/summary\u003e\n\n      \\`\\`\\`\\n\n      ${process.env.PLAN}\n      \\`\\`\\`\n\n      \u003c/details\u003e\n\n      *Pusher: @${{ github.actor }}, Action: \\`${{ github.event_name }}\\`, Working Directory: \\`${{ env.tf_actions_working_dir }}\\`, Workflow: \\`${{ github.workflow }}\\`*`;\n\n      // 3. If we have a comment, update it, otherwise create a new one\n      if (botComment) {\n        github.rest.issues.updateComment({\n          owner: context.repo.owner,\n          repo: context.repo.repo,\n          comment_id: botComment.id,\n          body: output\n        })\n      } else {\n        github.rest.issues.createComment({\n          issue_number: context.issue.number,\n          owner: context.repo.owner,\n          repo: context.repo.repo,\n          body: output\n        })\n      }\n```\n\n## Inputs\n\nThe action supports the following inputs:\n\n- `cli_config_credentials_hostname` - (optional) The hostname of a Terraform Cloud/Enterprise instance to\n  place within the credentials block of the OpenTofu CLI configuration file. Defaults to `app.terraform.io`.\n- `cli_config_credentials_token` - (optional) The API token for a Terraform Cloud/Enterprise instance to\n  place within the credentials block of the OpenTofu CLI configuration file.\n- `tofu_version` - (optional) The version of OpenTofu CLI to install. Instead of a full version string,\n  you can also specify a constraint string (see [Semver Ranges](https://www.npmjs.com/package/semver#ranges)\n  for available range specifications). Examples are: `\u003c1.6.0-beta`, `~1.6.0-alpha`, `1.6.0-alpha2` (all three installing\n  the latest available `1.6.0-alpha2` version). Prerelease versions can be specified and a range will stay within the\n  given tag such as `beta` or `rc`. If no version is given, it will default to `latest`.\n- `tofu_wrapper` - (optional) Whether to install a wrapper to wrap subsequent calls of\n  the `tofu` binary and expose its STDOUT, STDERR, and exit code as outputs\n  named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.\n- `github_token` - (optional) Override the GitHub token read from the environment variable. Defaults to the value of the `GITHUB_TOKEN` environment variable unless running on Forgejo or Gitea.\n\n## Outputs\n\nThis action does not configure any outputs directly. However, when you set the `tofu_wrapper` input\nto `true`, the following outputs are available for subsequent steps that call the `tofu` binary:\n\n- `stdout` - The STDOUT stream of the call to the `tofu` binary.\n- `stderr` - The STDERR stream of the call to the `tofu` binary.\n- `exitcode` - The exit code of the call to the `tofu` binary.\n\n## License\n\n[Mozilla Public License v2.0](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentofu%2Fsetup-opentofu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentofu%2Fsetup-opentofu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentofu%2Fsetup-opentofu/lists"}