Let's think about it this way for a second
`terraform validate` checks for syntax errors (typos, wrong argument names) locally, without needing to call the cloud API — handy as a quick sanity check before committing. `terraform fmt` auto-fixes code style (indentation, spacing) to the standard format — it helps keep every team member's code style consistent. It's common to set up a CI/CD pipeline (GitHub Actions) to auto-run `terraform plan` on every pull request and post it as a comment — team members can then see exactly 'what's about to change' right on the PR, while `apply` only runs after merge (or after manual approval).
Let's connect this to a real scenario
If a GitHub Actions workflow file runs `terraform fmt -check` (fails on bad formatting), `terraform validate` (fails on syntax errors), and `terraform plan` (change preview) as separate steps, every push a developer makes triggers an automatic check, catching human error early.
Let's look at it together
# .github/workflows/terraform.yml (simplified)
name: Terraform
on: [pull_request]
jobs:
plan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- run: terraform fmt -check
- run: terraform validate
- run: terraform plan$ terraform fmt -check
$ terraform validate
Success! The configuration is valid.
$ terraform plan
Plan: 2 to add, 0 to change, 0 to destroy.5-minute try-it
Run both `terraform fmt -check` and `terraform validate` on a local config folder — deliberately mess up the code style first and see how `fmt` auto-fixes it.
A quick word of caution
Store your CI/CD pipeline's credentials (AWS access keys) properly as repository secrets — never hardcode them in the workflow file.