The standard quality gate for a Terraform project in one job: terraform fmt -check,
terraform validate per root configuration, and tflint. One block, like
node-build-and-test and dotnet-build-and-test, so every Terraform repository runs the same
three checks and cannot drift apart. validate runs with init -backend=false, so the block
needs no cloud credentials and no access to remote state.
Add this file to the consuming repository at .github/workflows/terraform.yml, or add the
job to an existing pull-request workflow. List the root configuration directories to
validate:
name: terraform
on:
pull_request:
jobs:
check:
uses: kalloeash/github-actions-templates/.github/workflows/terraform-format-validate-lint.yml@v0
with:
directories: |
bootstrap
infraThe tool version defaults are pinned in the block and bumped centrally. A project that needs a specific version passes it explicitly:
jobs:
check:
uses: kalloeash/github-actions-templates/.github/workflows/terraform-format-validate-lint.yml@v0
with:
terraform-version: "1.13.4"
tflint-version: "v0.61.0"tflint reads .tflint.hcl from the repository root. A minimal one enables the bundled
Terraform ruleset:
plugin "terraform" {
enabled = true
preset = "recommended"
}| Name | Default | Description |
|---|---|---|
terraform-version |
1.15.8 |
Terraform version passed to setup-terraform. Pinned in the block, bumped centrally; override to match your project. |
tflint-version |
v0.63.1 |
tflint version passed to setup-tflint. Pinned in the block, bumped centrally; override to match your project. |
directories |
. |
Newline-separated list of root configuration directories to validate. |
Needs contents: read only.
- The checks run in order (
fmt, thenvalidate, thentflint) in a single job, so the run stops at the first failure, the same way the Node and .NET gates do. fmt -check -recursiveandtflint --recursivecover the whole tree, so subdirectories and modules are formatted and linted without their own entry.validateruns per directory indirectories, because it initializes providers against a root configuration. A module validated through a root does not need its own entry.inituses-backend=false: validation checks syntax and references, not backend access, so no credentials are required.- Commit
.terraform.lock.hclin each root configuration.initrespects a committed lockfile, so validation runs against the provider versions the project has locked instead of whatever is newest. tflint --inituses the workflow token to raise the GitHub API rate limit for plugin downloads. The bundled Terraform ruleset needs no download, and an external ruleset works with no change to this block.