Exercise 1: Why fmt -check and validate Run Before plan, and What Each Catches — Possible Solution ==================================================================== Both `fmt -check` and `validate` are LOCAL, CHEAP checks -- neither needs to talk to a real cloud provider or compute an actual infrastructure diff. `plan`, by contrast, is comparatively expensive: it refreshes real state against real infrastructure (Chapter 5's three-way comparison) and can take real time against a large configuration. Running the cheap checks first means a pipeline fails FAST on a trivial mistake -- a badly formatted file or a syntax error -- without ever spending the time (and, for some providers, real API calls) needed to compute a full plan. This is the same "fail fast" logic behind ordering any CI pipeline's cheapest checks earliest. What each one specifically catches, and why neither substitutes for the other: - `terraform fmt -check` catches STYLE inconsistency only -- inconsistent indentation, spacing, alignment. It has no awareness of whether the configuration is even valid HCL; a file could be perfectly formatted and still reference an undefined variable. - `terraform validate` catches SYNTAX and TYPE errors -- malformed HCL, a variable referenced that was never declared, an argument of the wrong type -- but does not care at all about formatting style, and critically, it doesn't touch real infrastructure or compute an actual plan; it only checks that the configuration is internally well-formed. Neither one can catch what `plan` catches (an actual, real diff against live infrastructure) -- they're deliberately narrower, cheaper filters that catch different, non-overlapping classes of trivial mistakes before the pipeline pays for a full plan. WHY THIS WORKS AS AN ANSWER ------------------------------ This explains the fail-fast/cost-ordering reasoning for running cheap checks first, and clearly separates what fmt (style) vs. validate (syntax/types) each catches, showing they check genuinely different, non-redundant things rather than treating them as interchangeable.