hashicorp/setup-terraform
Install the Terraform CLI and (optionally) wrap it to expose plan output in later steps.
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 wrapperInputs
| Input | Description | Default | Required |
|---|---|---|---|
terraform_version | Version to install, e.g. 1.9.0 or latest. | latest | No |
terraform_wrapper | Install the output-capturing wrapper. | true | No |
cli_config_credentials_token | Terraform 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.stdoutbeing empty usually meansterraform_wrapperwas disabled.- A version like
latestcan change plan output between runs; pinterraform_versionfor reproducible CI.
Security and pinning
- Pin
terraform_versionand the action SHA. Pass any Terraform Cloud token from a secret.
Alternatives and related
aws-actions/configure-aws-credentialsAuthenticate to AWS in a workflow, ideally by assuming a role with OIDC (no stored keys).
azure/loginLog in to Azure in a workflow, using OIDC federated credentials or a service principal.
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.