Safeguard
Developer Tools•

Terraform validate, plan or a security scan: what does each catch?

Validate checks syntax and consistency, plan shows proposed changes, and a security scan checks risky settings. Use all three, in that order.

Safeguard Security Team
3 min read

Terraform validate checks that your configuration is syntactically valid and internally consistent. Plan shows what would change in a specific run. Neither one judges whether a setting is risky, such as a public bucket. A separate security or policy scan does that, so a safe pipeline runs all three in order.

What each step answers

StepQuestion it answersWhat it does not do
terraform validateIs the code well formed and internally consistent?Check remote services, state or provider APIs
terraform planWhat will change in this workspace with these inputs?Judge whether the end state is safe
Security or policy scanDoes this config or plan break a rule we care about?Prove the cloud matches the code

Validate in more detail

The reference says validate checks files in a directory and does not validate remote services such as remote state or provider APIs. It runs regardless of variables or existing state, which makes it most useful for reusable modules. It checks things like attribute names and value types. It is safe to run automatically, for example on save in an editor or as a CI test step.

To validate without touching a configured backend, initialise with the backend disabled. The reference documents terraform init -backend=false for this.

Plan in more detail

Plan includes an implied validation, but in the context of a particular run: a specific workspace and set of variable values. It is the first step that sees real inputs, so it is the first step that can show you a surprise, such as a resource being replaced rather than updated.

Where security checks belong

A valid, planned configuration can still open a database to the internet. The language has no opinion on that. Two places work well for checks:

  1. On the code, early, in the editor and pull request. Fast feedback, but it cannot see resolved variable values.
  2. On the plan, converted to JSON, which has real values after evaluation. Slower, more accurate.

Run both if you can. Early checks catch most mistakes cheaply, and plan checks catch the ones that only appear once values are resolved. For more on choosing, see where to enforce policy as code.

A simple pipeline order

  1. Format check.
  2. Validate, with the backend disabled.
  3. Scan the code.
  4. Plan with the detailed exit code.
  5. Scan the plan JSON.
  6. Human approval, then apply the saved plan.

Try it yourself

Click through it at your own pace, or open it full screen.

In the demo, notice which checks run before a merge is allowed. Your validate, scan and plan steps are the same idea applied to infrastructure code.

Quick check

Does terraform validate need cloud credentials?

No. It does not validate remote services. It needs an initialised directory, and you can initialise with the backend disabled.

Can terraform plan tell me a setting is insecure?

No. It shows proposed changes. Judging risk needs a policy or security check on the code or plan.

Safeguard runs policies and gates on pull requests, so a failed rule can hold a merge, and its dependency and SBOM scanning covers the packages your infrastructure code pulls in. You can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.