Skip to content

CI — Terraform

Runs terraform validate and terraform fmt -check against a Terraform root module. Initializes with no backend and caches providers between runs.

Usage

yaml
jobs:
  ci:
    uses: KevinDeBenedetti/github-workflows/.github/workflows/ci-terraform.yml@main
    with:
      tf-dir: terraform
      terraform-version: 1.10.0

Inputs

InputTypeDefaultDescription
run-validatebooleantrueRun terraform validate (requires init)
run-fmt-checkbooleantrueRun terraform fmt -check -diff to enforce formatting
tf-dirstringterraformPath to the Terraform root module directory
terraform-versionstringlatestTerraform version to install
runnerstring'"ubuntu-latest"'Runner labels as JSON — '"ubuntu-latest"' or a label array

Steps

  1. Checkout
  2. Setup Terraform (hashicorp/setup-terraform, wrapper disabled)
  3. Cache Terraform providers (.terraform, keyed on .terraform.lock.hcl)
  4. terraform init -backend=false
  5. (if run-validate) terraform validate
  6. (if run-fmt-check) terraform fmt -check -diff

Notes

  • All steps run in tf-dir via defaults.run.working-directory.
  • init always runs with -backend=false so no remote backend credentials are required for validation.
  • The Terraform wrapper is disabled (terraform_wrapper: false) since self-hosted runners may lack a system Node.js and no step consumes the wrapper outputs.