Static analysis and linting
What static analysis can establish
Static analysis examines code or a representation of code without deploying the target infrastructure. Formatting, schema validation, lint rules and policy checks answer different questions. For example, a storage resource can be valid according to its provider schema and still permit unwanted public access. A scanner can flag a likely problem, but a passing report does not prove that the deployed service is secure. Some tools load plugins, resolve modules or obtain rules over the network, so static does not mean safe to run on arbitrary code.
Start with Terraform checks
Use the supplied local fixture in a new disposable directory. It declares only a built-in resource and pins the provisional Terraform 1.14.8 version. No external provider is needed. The following commands are a manual, unexecuted sequence, not a transcript. Inspect the configuration and environment first; stop on a failed step.
terraform fmt -check -recursiveterraform init -backend=falseterraform validateterraform providers schema -json > schema.jsonThe formatting check detects style differences without rewriting source. Initialization with backend disabled prepares dependencies for validation; it does not make an arbitrary module offline or safe. Validation examines configuration consistency, including available schemas, rather than actual cloud reachability or permissions. The schema command describes provider-defined arguments, attributes and types; its JSON is a machine-readable schema, not a security assessment. Store that output in the disposable directory. A specific run still needs plan review with its actual inputs.
Use linters and security scanners for separate purposes
TFLint checks Terraform-specific rules and can use provider-aware rule plugins. Checkov and Trivy inspect infrastructure configuration for policy or misconfiguration findings. Their rules and analysis coverage overlap but are not identical. The following are illustrative invocations for an already reviewed and pinned toolchain in a disposable, offline-controlled environment, not commands to run automatically.
tflintcheckov -d . --framework terraformtrivy config .Before running, verify the binary, ruleset version, configuration, plugin provenance and network requirements. TFLint initialization can install plugins. Scanners can resolve remote modules or update checks, and may produce different results with different variable values. Do not send plan files, state or secrets to an external service. No scanner versions are approved in this package; these examples are static.
Interpret findings rather than count them
A fictional report illustrates five separate issues. It is not output from any named scanner.
F01 formatting inconsistent alignmentF02 validation unsupported argumentF03 lint unused input variableF04 policy public storage accessF05 policy encryption setting unknownF01 is a style correction. F02 must be fixed before deployment. F03 may indicate an obsolete interface; check consumers before removing the input. F04 is a security finding that requires review of effective permissions and intended access. F05 is unresolved evidence, not a pass. Review module expansion, input values, rule coverage and possible false positives or negatives. Use a protected plan review if static information is insufficient.
Handle exceptions with evidence
If a finding is inapplicable, document the actual rule ID, resource scope, reason, compensating control, owner, approval and expiry. Checkov supports scoped skip comments; do not copy a made-up rule identifier into actual configuration. Record the scanner version and rule bundle, then rerun the affected check after the exception expires or code changes. Avoid blanket disabling of checks, treating skipped findings as tested, or ignoring scanner errors. Review the report and exit-status policy together; a command failure or missing result is not a clean scan.
Practice and next step
Classify the five fictional findings, identify which gates they affect, and decide what additional evidence is required. Next, use integration tests to verify behavior that static checks cannot establish.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Static analysis and linting — knowledge check
Review static analysis and integration test strategy.
What does terraform fmt -check establish?
Which tool is intended for Terraform lint rules and optional plugins?
A provider-valid storage configuration permits unwanted public access. What follows?
A scanner cannot evaluate an encryption value. What should the reviewer do?
What makes a suppression reviewable?