An empty Terraform plan can sit beside a security finding for the same resource. The two checks answer different questions. Drift detection looks for changes outside the configuration workflow; security scanning checks the configuration against rules. An overly broad access policy can match your Terraform code perfectly.

Keep both checks, and decide how to handle each result. Drift needs an explanation and a decision about the desired state. A security finding needs an assessment of the access or exposure it creates. Neither result should automatically trigger a production repair.

What each check can tell you

CheckQuestion it helps answerWhat remains to review
Configuration validationIs the configuration internally consistent?Whether its settings meet your security requirements
Normal Terraform planWhat changes would reconcile configuration with observed managed resources?Which differences came from code changes, remote changes, or other inputs
Refresh-only planHow would state and outputs change to reflect remote objects?Whether the remote change should be accepted or corrected
Security policy checkDoes the inspected configuration violate a selected rule?Coverage, exceptions, effective access, and business impact

HashiCorp’s terraform validate documentation describes syntax and internal-consistency checks; it does not inspect remote services. A successful validation result is useful, but it is not a security review of the deployed environment.

Use a plan mode that matches the question

A normal plan can contain changes caused by an edited configuration as well as differences in remote objects. If a pull request changes instance sizing and someone also changes a network rule in the console, review both sources of change before interpreting the result.

HashiCorp documents refresh-only planning as a way to propose updates to state and outputs based on changes made outside Terraform. In an initialized, trusted workspace, an inspection command can be:

terraform plan -refresh-only -detailed-exitcode -input=false

With that exit-code option, zero means no proposed changes, one means an error, and two means a nonempty plan. A CI job must handle two deliberately. It should not report an API failure as a clean result or treat every detected difference as an execution error.

This command plans; it does not apply the proposed state updates. Protect the workspace and its credentials, and review the configuration and providers used to run it. Planning is not a sandbox for untrusted code or plugins.

Preserve the plan exit code in CI

For a Bash-based inspection job, put the plan in a conditional so an enabled errexit setting does not terminate the job before you can distinguish drift from failure:

if terraform plan -refresh-only -detailed-exitcode -input=false; then
  plan_status=0
else
  plan_status=$?
fi

case "$plan_status" in
  0) printf '%s\n' 'No refresh-only changes detected' ;;
  2) printf '%s\n' 'Changes detected: route this result for review'; exit 2 ;;
  *) printf '%s\n' 'Plan failed: assessment incomplete' >&2; exit 1 ;;
esac

This example intentionally returns a nonzero status for detected changes. Configure the surrounding job to report that as “review required,” while retaining the distinction from an execution failure. It does not apply changes. If your CI uses a separate result output instead, ensure later steps cannot overwrite the recorded status or make an incomplete plan look clean.

Reconcile one change before automating the process

Consider a hypothetical administrative security-group rule that was narrowed during an incident. Terraform still describes the old, broader source range. A later ordinary apply could propose restoring that range.

Find who made the live change and why, then decide what the approved configuration should be. If the restriction is correct, update the code and review a fresh plan. If it broke a required administrative path, fix the design with the people responsible for that path.

HashiCorp’s drift walkthrough separates updating state from changing configuration. Accepting remote values into state leaves the configuration to review. The code, state, and live resource need to describe an intentional result. Preserve the incident record so the next person understands why the rule changed.

For an unauthorized broadening of access, the response differs. Contain the exposure through the incident or change process, investigate relevant activity, and correct the source configuration as needed. Blindly reverting every difference can erase a legitimate emergency repair.

Account for what Terraform does not manage

A plan covers the selected workspace and the resources its providers know how to observe. It is not a complete inventory of everything someone can create in a cloud account.

Keep a separate account-level resource inventory and compare it with what Terraform manages. Record unmanaged resources, intentionally ignored attributes, unavailable permissions, and collection errors. Those gaps matter when interpreting an empty plan.

The same applies to targeted or refresh-limited runs. HashiCorp documents that skipping refresh can hide external changes and that routine resource targeting can leave drift undetected. A shortened run may be useful for a specific purpose, but its result needs that scope attached.

Combine drift checks with security rules

Use representative cases to test the pipeline. A deliberately broad rule committed in a test configuration should be caught by the appropriate security check even when there is no drift. A harmless manual change should produce a drift result even when it has no security impact.

A third case should exercise failed collection. Give the test job an identity that cannot read a required resource, and check that the failure is visible to the operator. An empty findings list must not hide an incomplete run.

Our cloud misconfiguration guide explains how to pair configuration checks with safe access tests. The security requirement comes from the workload; the tools provide evidence about whether the selected checks hold.

Keep a record the next operator can use

For each run, retain the workspace, source revision, tool and provider versions, collection time, result, and relevant resource identifiers. Protect plan artifacts because they can contain sensitive values. Store enough information to reproduce a finding without publishing credentials or entire state files in a ticket.

Give every unresolved difference an owner and a decision: accept it through a reviewed configuration change, correct it, or investigate further. Then rerun the relevant checks. Our DevSecOps services can help connect those decisions to the pipeline your team already uses.

DevSecOps services from Libre Labs View all posts