Direct answer
Drift means the real infrastructure no longer matches Terraform state. A plan refreshes remote object state by default, so a normal plan run surfaces those differences, but detection is where the safe part ends. Before anything reconciles, each difference needs a classification: who made the change, whether it was expected, and whether the right fix is to import it, revert it, accept it as intentional, or rebuild it from configuration. Do not let Claude Code auto-apply a reconciliation across every detected difference, because drift tells you that reality changed without telling you who changed it or whether the change was safe.
The concrete win is a review that separates an intentional out-of-band fix from an accident before an apply overwrites either one. The concrete loss is that drift evidence is only as complete as the refresh behind it, and a minimal refresh can hide differences in resources you never touched. Start with a full refresh, classify, then decide.
Why unreviewed reconciliation is expensive
An apply that reconciles drift blindly picks a side in every disagreement between state and reality. When the difference was an emergency fix applied by hand during an incident, reconciliation reverts the fix. When the difference was a forgotten manual change, reconciliation might finally encode it, or might destroy a resource someone configured outside the workflow. Either outcome is a surprise delivered at the worst time.
Three costs follow from skipping triage. Restoring a resource that a reconcile deleted. Chasing an incident caused by an apply that reverted a working configuration. Losing trust in the plan, because reviewers stop believing the diff reflects reality.
The fix is procedural rather than technical. Make drift a review event with a named decision per difference, not an automatic cleanup.
What Counts as Drift
Official, F007: Terraform plan refreshes remote object state by default so that its records reflect current remote state. The plan then compares desired configuration against that refreshed state and reports the actions needed to converge.
Drift is the gap between those two. It appears in three ordinary forms.
Configuration drifted from reality because someone changed infrastructure outside Terraform, such as a console edit, a manual scaling action, or a script. Reality drifted from configuration because an external system mutated a resource, such as an autoscaler, a managed service feature, or another tool writing the same object. State itself is stale or wrong because a resource was destroyed or created without Terraform knowing.
| Drift category | Likely owner | Review path |
|---|---|---|
| Manual console or CLI change | Human operator or incident responder | Confirm intent, then import or revert |
| External system mutation | Autoscaler, managed service, or another tool | Decide whether Terraform should own the field |
| Resource replaced outside Terraform | Unknown until investigated | Investigate before any apply |
| Configuration change not yet applied | Change author | Treat as a normal plan review |
Read the third row as the dangerous one. A resource that vanished and reappeared with a new ID is not a routine difference, and reconciling it can cascade into dependent resources. When the missing resource was destroyed during an incident, the access path that allowed it is covered by break glass incident access controls.
Refresh Completeness
Refresh behavior is the evidence base for the whole triage, so its limits matter more than its speed.
Official, F008: the -refresh=false option can produce an incomplete plan by ignoring external changes. Use it only when the missing drift is understood and accepted.
Official, F009: minimal refresh reduces API calls but can ignore external drift in resources that are not planned for change. A clean reviewed diff does not prove that the whole environment is drift-free.
| Refresh mode | Coverage | Known blind spot |
|---|---|---|
| Default refresh | Reads current remote state where the provider can see it | Provider visibility limits; resources it cannot read |
| Minimal refresh | Narrowed read set | Drift in resources outside the planned change set |
-refresh=false |
Stored state only | All external changes since the last refresh are invisible |
Treat default refresh as the evidence for any reconciliation that matters. The tradeoff is API quota and time, which is why minimal refresh tempts teams during large applies. The blind spot is exactly the drift you have not triaged.
Official, Terraform state documentation treats state as the record Terraform reconciles against. State quality therefore bounds drift evidence quality, which is why the Terraform state locking and access controls guide treats state as a privileged dependency.
Classifying Resource Differences
Classification turns a wall of diff into a set of decisions. For each resource action, ask who owns the change and what the safe resolution is.
| Observed difference | Proposed action | Approval evidence |
|---|---|---|
| Attribute changed in reality only | Import the real value into state, or revert reality | Owner confirms the change and its intent |
| Attribute changed in config only | Normal apply after review | Standard change approval |
| Resource present in reality, absent from state | Import before any apply | Owner confirms Terraform should manage it |
| Resource in state, absent from reality | Investigate deletion before rebuilding | Investigation record naming what happened |
| Whole resource replaced | Block pending root-cause review | Named approver accepting data or identity loss |
Two classifications deserve extra caution. A resource in state but missing from reality usually means something destroyed it, and rebuilding it without understanding why recreates the condition that removed it. A whole-resource replacement is a delete plus a create, and it can change identifiers that downstream systems depend on.
Drift detection proves a difference exists. It does not prove the cause. Writing down the cause is part of triage, not a conclusion the plan provides.
Ownership and Expected Changes
Every difference has an owner, and the review is faster when the owner is reachable. Map each drifted resource to a team before the reconciliation decision, because an unowned resource is the one most likely to hide an incident fix.
Some drift is expected and should be encoded rather than reverted. A managed service that writes its own tags, an autoscaler that changes a replica count, a platform feature that mutates a setting. The decision for these is whether Terraform should own the field or ignore it, which is a design question rather than a one-off cleanup.
| Refresh question | Answer owner | Where it is recorded |
|---|---|---|
| Who made this change? | Resource owner | Change record |
| Was it expected? | Resource owner | Change record |
| Should Terraform own the field? | Platform owner | Configuration decision |
| Is reverting safe? | Service owner | Approval evidence |
The RACI ownership for infrastructure changes guide covers naming an accountable human per change class, which is the same discipline drift triage needs at the resource level.
Reconciliation Options
Four options cover nearly every difference, and choosing among them is the actual work of triage.
Import. Bring the real resource into state so Terraform manages it going forward. Right when the change is intentional and should become the baseline.
Revert. Apply configuration to overwrite the out-of-band change. Right when the change was accidental and configuration is the source of truth.
Accept. Record the difference as intentional and adjust configuration to match, so future plans stay clean. Right when the change is expected and Terraform should not fight it.
Rebuild. Destroy and recreate the resource from configuration. Right when the real resource is in an unrecoverable or unknown state, and only with an owner who accepts the loss.
| Option | Use when | Cost |
|---|---|---|
| Import | Change is intentional and should be managed | State gains the resource; configuration may need updating |
| Revert | Change was accidental | Applies over reality; verify nothing depended on the change |
| Accept | Change is expected and out of Terraform scope | Configuration updated to match; drift stops recurring |
| Rebuild | Real resource is unknown or broken | Delete plus create; identity and data loss possible |
Import is the most underused option in practice. Teams that always revert pay for it the next time the same manual change reappears.
Approval Thresholds
Not every difference needs the same rigor. Tie approval strength to what reconciliation would do.
Read-only differences that a plan reports but an apply would not change need a light record. In-place updates need the standard change approval from the service owner. Any delete, replace or rebuild needs a named approver who accepts the loss, plus an investigation into why the resource left its expected state. Differences touching stateful resources, networking or identity deserve the highest tier regardless of size.
| Observed difference | Minimum approval | Evidence retained |
|---|---|---|
| Read-only or no-op | Reviewer records the classification | Triage note |
| In-place update | Service owner | Plan artifact and approval |
| Delete or replace | Named approver accepting loss | Investigation and approval |
| Rebuild of stateful resource | Service owner plus platform owner | Root-cause note and approval |
The risk-tiered infrastructure approvals guide covers building the tier definitions, and the Terraform plan review gates guide covers binding an approval to a saved plan. Where a reconciled change belongs in the team calendar, and what counts as an emergency, is covered by change freeze emergency rules.
Recording the Chosen Action
A triage decision that is not recorded is a decision that gets re-litigated next cycle. Keep four fields per difference.
The resource and the observed difference. The chosen option among import, revert, accept and rebuild. The owner who confirmed intent. The evidence that the action was applied and verified afterward.
# per-difference triage record fields
# resource: aws_instance.app[2]
# difference: instance_type changed outside Terraform
# option: import (keep the larger type)
# owner: platform-oncall
# evidence: plan after import shows no further changeThe post-apply verification matters most. A reconciliation that was approved but never confirmed leaves the next plan to rediscover the same difference, which is how drift becomes a recurring tax.
Drift That Should Block Work
Some differences should stop the workflow rather than proceed to a decision. Stop and investigate when any of these appear.
A resource in state is missing from reality and nobody can say why. A whole-resource replacement appears without a corresponding configuration change. A drifted resource is shared across environments or holds state that cannot be recreated. The difference only appears with a full refresh, meaning a prior minimal refresh would have hidden it. The drifted resource is in the blast radius of a change already in flight.
| Signal | Why it blocks | Resolution |
|---|---|---|
| Unexplained missing resource | Something destroyed it outside the workflow | Investigate before rebuilding |
| Unrequested replacement | Identity or data loss possible | Root-cause review first |
| Shared or stateful drift | Blast radius crosses teams | Escalate to platform owner |
| Refresh-only difference | Evidence was incomplete earlier | Re-run full refresh |
| Drift under an in-flight change | Two changes could interact | Sequence the work |
Automated guardrails can help here without taking over the decision. Azure Policy includes built-in definitions that report configuration states for network access, encryption, identity and logging, and the policy as code audit before deny guide covers rolling those out from reporting to prevention. A policy result is one input to triage, not the decision itself.
Working with Claude Code on drift
Give the agent a full-refresh plan and ask for a classification table rather than a summary. Ask it to list each difference with its resource, action, and the options that would resolve it, and ask it to flag anything it cannot attribute to an owner.
The agent is useful for surfacing the diff and proposing classifications. Deciding whether an out-of-band change was intentional is a business question for the resource owner. OWASP guidance on secure coding with AI calls for human review of CI/CD changes made by AI coding agents and treating their output as untrusted, which fits drift exactly: the agent reports reality, and a human decides what reality should be. Deciding which team owns that decision is a governance question, covered by the platform governance council charter.
For the identity and permissions side of running these plans safely, the Kubernetes RBAC least privilege reviews guide covers the additive permission union, and the cloud IAM permission boundaries guide covers the ceiling on what a planning identity can grant. Recording drift as a dated risk decision with an owner follows the same discipline as change freeze emergency rules, which define what qualifies as an exception and who authorizes it.
The concrete win, loss, and implication
The concrete win is a decision you can defend. Each difference gets an owner and a chosen option, so an apply either encodes an intentional change or reverts an accidental one, and the record shows which.
The concrete loss is coverage you cannot fully verify. A refresh is bounded by what the provider can see, and a minimal refresh can hide drift in resources outside the planned change set. Drift evidence is strong for what it read and silent about what it did not.
The practical implication is that drift is a governance signal, not a cleanup task. Teams that triage before reconciling catch incident fixes before an apply reverts them. Teams that auto-apply learn about out-of-band changes from the outage the apply caused.
Related reading in this batch
Drift sits between planning and state. Terraform plan review gates covers turning a plan into a bound approval, and Terraform state locking and access controls covers the backend and identity split that makes refresh evidence trustworthy.
Kubernetes drift has its own ownership question. Server-side apply ownership checks covers field ownership when two systems write the same object. NetworkPolicy blast radius reviews covers traffic policy that can look correct and still not be enforced. Pod Security admission gate reviews covers workload admission as a change gate.
Governance around reconciliation appears in cloud IAM permission boundaries, access recertification for agent identities, and change freeze emergency rules. Keeping the instructions that describe how to reconcile a given resource current is covered by runbook ownership and review cadence. Evidence handling for the decisions triage produces is covered by SOC 2 change evidence packets and audit evidence integrity checks.
Data gap and future update
The Terraform plan reference supports the refresh behavior in F007 through F009. Provider-specific visibility limits, which determine what a refresh can and cannot read for a given resource type, were not enumerated here because they vary by provider and resource.
No measurement of drift frequency, reconciliation incidents or time spent triaging is reported, because none was collected. A future update quantifying how often an out-of-band change is an intentional fix versus an accident would need a repository history with recorded triage decisions. No such dataset exists in the public sources used.
The Azure Policy reference is included as an example of automated configuration reporting, not as a drift-detection mechanism. A policy result reports a configuration state; it does not reconcile Terraform state against reality.
One AI API Key option for OpenAI-format agents
Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.
OpenAI-format agents have a separate route: One AI API Key provides https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That is a different client and request format, not a workaround for Claude Code authentication. See the free model list for eligibility notes, the quickstart for request shape, or the cost calculator to compare hosted options.
FAQ
Does a clean plan mean there is no drift?
Only for what the refresh read. A default refresh reads current remote state, but a minimal refresh or -refresh=false can hide external changes, including drift in resources not selected for change. A clean diff is not a drift-free certificate.
What is the difference between import and revert?
Import brings the real resource into state so Terraform manages it as it currently exists. Revert applies configuration to overwrite the out-of-band change. Import keeps the change and makes it the baseline; revert discards it in favor of configuration.
Should Claude Code reconcile drift automatically?
No. The agent can produce a full-refresh plan and propose classifications, but choosing import, revert, accept or rebuild for each difference is an ownership and risk decision. Auto-reconciling every difference risks reverting an intentional incident fix or destroying a resource nobody explained.
When is a drifted resource a blocker rather than a decision?
When it is missing from reality without explanation, when a whole replacement appears without a configuration cause, or when it is shared or stateful and sits in the blast radius of an in-flight change. Those stop the workflow pending investigation.
How do I stop the same drift from recurring?
Decide whether Terraform should own the field. If an external system or managed feature writes it legitimately, adjust configuration so the plan stops reporting it as a change. If the change was manual and unwanted, revert it and close the access path that allowed it.
More Claude Code troubleshooting
- Claude Code Cloud Costs: Budget and Quota Guardrails
- Claude Code Incident Tabletops: NIST-Aligned Exercises
- Claude Code AISVS: Control Mapping for Platform Teams
- Claude Code Security Exceptions: Expiry and Ownership
- Claude Code Vendor Review: Security Evidence Checklist
- Claude Code Threat Models: Infrastructure Agent Boundaries
- Claude Code OpenTelemetry: Semantic Conventions for Agents
- Claude Code Incident Timelines: Request ID Correlation
- Claude Code SLO Alerts: Burn Rate During Changes
- Claude Code Error Budgets: Release Decision Policy
- Claude Code Postmortems: Evidence Without Blame
- Claude Code Log Pipelines: Health Checks Before Triage
Sources
- Official: Terraform plan command reference, supporting default refresh and the minimal-refresh and
-refresh=falseblind spots in F007, F008 and F009. - Official: Terraform apply command reference, reference for the reconciliation step triage protects.
- Official: Terraform state documentation, reference for state as the record reconciliation compares against.
- Official: Azure Policy built-in definitions, example of automated configuration-state reporting.
- Independent: OWASP Secure Coding with AI Cheat Sheet, supporting human review of AI-agent-driven infrastructure changes.