Skip to content
Latchkey

hashicorp/setup-terraform

Install the Terraform CLI and (optionally) wrap it to expose plan output in later steps.

Official actionCategory: Infrastructure & KubernetesLatest v3View on GitHub

What it does

hashicorp/setup-terraform installs the Terraform CLI. By default it installs a wrapper script so the outputs of terraform steps (stdout, stderr, exitcode) are available to later steps.

That wrapper is what lets you post a formatted plan as a PR comment.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: hashicorp/setup-terraform@v3
    with:
      terraform_version: 1.9.0
  - run: terraform init
  - id: plan
    run: terraform plan -no-color
  # steps.plan.outputs.stdout is available thanks to the wrapper

Inputs

InputDescriptionDefaultRequired
terraform_versionVersion to install, e.g. 1.9.0 or latest.latestNo
terraform_wrapperInstall the output-capturing wrapper.trueNo
cli_config_credentials_tokenTerraform Cloud/Enterprise API token.-No

Notes

Set terraform_wrapper: false if another tool needs the raw terraform binary without the wrapper.

Common errors

  • steps.plan.outputs.stdout being empty usually means terraform_wrapper was disabled.
  • A version like latest can change plan output between runs; pin terraform_version for reproducible CI.

Security and pinning

  • Pin terraform_version and the action SHA. Pass any Terraform Cloud token from a secret.

Alternatives and related

Frequently asked questions

How do I comment a Terraform plan on a PR?
Keep the wrapper on (default), capture steps.<id>.outputs.stdout from the plan step, and post it with actions/github-script.
Running hashicorp/setup-terraform? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card