A developer wants a pre-commit check that catches a misspelled resource argument and a reference to an undeclared variable. The check must run in seconds and must not need cloud credentials or access to state. Which command fits?
Choose one.
terraform validate is a static check of the configuration in the working directory. It verifies syntax and internal consistency - valid block structure, known argument names, resolvable references and matching types - using the provider schemas installed by init, and it never contacts a remote service.
Both errors in the scenario are configuration-consistency problems, which is precisely validate's scope, and the constraints (fast, no credentials, no state) rule out plan, which configures providers and reads state even with -refresh=false. fmt -check is the tempting near-twin because it is also a fast CI gate, but it checks style only; console evaluates single expressions against state rather than checking the configuration.
- Identify the kind of error: a misspelled argument and an undeclared reference are consistency errors, not style or infrastructure errors.
- Apply the constraints: no credentials and no state access rule out plan and console.
- Separate style from correctness: fmt checks layout, validate checks correctness.
- Choose terraform validate (after init has installed the provider schemas).
Exam tip: validate = offline correctness check (names, references, types); fmt = style; plan = needs providers and state.
Terraform init, validate, and plan: the core workflow explained — the lesson that teaches this.