Reconciling drift means restoring the live environment to match the intended Terraform configuration, which is the right choice when the out of band change should not remain. Aligning the code means updating Terraform to reflect a real change that should be kept. The decision depends on whether the manual change was a mistake or a valid new baseline.
Why Terraform drift and code alignment are different decisions
terraform drift is a state problem, not just a syntax problem. The live environment has changed outside the code, so the question is whether Terraform should bring reality back under declared control or whether the code should be updated to accept a legitimate operational change. That distinction matters because the wrong choice can either erase a valid production change or preserve an unauthorised one.
In practice, drift often appears first as an operational surprise, not as a deliberate governance decision, which is why teams sometimes “fix” the wrong layer and leave the actual control gap intact.
How it works in practice
Reconciliation and alignment answer two different questions. Reconciliation asks, “Should the live system be changed to match the current Terraform definition?” Alignment asks, “Should the Terraform definition be changed to match the live system?” Both actions are valid, but they serve different outcomes and carry different blast-radius implications.
Use reconciliation when the out-of-band change violates policy, bypasses review, or introduces risk that should not persist. Typical examples include manual console edits to security groups, buckets, or IAM-style permissions, where the live setting should be returned to the declared baseline. Use alignment when the drift reflects an approved change that was implemented operationally first, or when the code was simply lagging behind a known production reality.
- Confirm whether the change was authorised, temporary, or emergency-only.
- Check whether the drift affects security controls, availability, or compliance boundaries.
- Decide which source of truth should survive, the live environment or the code.
- Record the reason for the decision so future plan/apply actions do not reintroduce the same mismatch.
If the live change is merged into code too quickly, Terraform can silently normalise bad practice; if code is forced back too aggressively, it can break a necessary production fix or rollback path. These controls tend to break down when teams use manual changes for urgent remediation but never convert that exception into a reviewed baseline.
Common Variations and Edge Cases
Tighter control often increases delivery friction, so teams need to balance immutable infrastructure discipline against the operational reality that not every change arrives through the same channel. The right answer also varies by environment: production systems usually demand a lower tolerance for unexplained drift than sandboxes or short-lived test stacks.
Some drift is expected, especially where providers inject defaults, autoscaling changes resource counts, or managed services mutate settings outside the Terraform file. In those cases, the important judgement is whether the deviation is harmless state noise or a material change in security, cost, or behaviour. If the environment is intentionally mutable, the code should still describe the intended steady state as accurately as possible, with exceptions documented rather than assumed.
For teams managing secrets, tokens, certificates, or other sensitive configuration, the alignment choice can also affect auditability and rollback safety, because preserving live reality without updating code can leave future plans misleading. The safest pattern is to treat every drift event as a governance decision, not a mechanical sync step.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST CSF 2.0 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | GV.3 — Risk Management Strategy | Terraform drift decisions depend on risk-based source-of-truth governance. |
| CM-2 — Baseline Configuration | The question is fundamentally about choosing the authoritative baseline. | |
| CM-6 — Configuration Settings | Drift commonly appears as unauthorized or undocumented setting changes. | |
| Recommendation — Use GV.3 to decide whether drift should be rolled back or accepted as the new baseline. Define CM-2 baselines so Terraform and live state can be reconciled consistently. Use CM-6 to review and correct settings that diverge from approved configuration. | ||
| CIS Controls v8 | 5 — Account Management | Manual infrastructure changes often bypass controlled access and review. |
| 4 — Secure Configuration of Enterprise Assets and Software | Drift is a configuration integrity problem requiring controlled baselines. | |
| Recommendation — Apply Control 5 to restrict manual changes and preserve approved infrastructure baselines. Use Control 4 to detect and correct configuration drift against approved Terraform state. | ||
Practitioner Guidance
Decision rule: If the drift changes security posture, access, or exposure, reconcile the environment first and only align the code after the live state is back under control. If the drift reflects an approved new baseline, update code through the same review path you would use for any other infrastructure change.
What to verify: Verify whether the drift came from an emergency fix, a provider-side mutation, or an unauthorised manual edit. The source of the change determines whether the immediate action should be rollback, codification, or exception handling.
Common mistake: Teams often treat drift detection as a housekeeping task and then approve whichever side is easiest to change. That shortcut hides whether the real problem is poor change control, poor documentation, or a legitimate operational adjustment that has not yet been formalised.
Practitioner takeaway: The key judgement is not which side is newer, it is which side should define the durable baseline after the change has been reviewed for risk and intent.
Related resources from NHI Mgmt Group
- What is the difference between aligning Terraform code and reconciling production state?
- What is the difference between Terraform code and Terraform state for governance?
- What is the difference between stack-level visibility and code-level review for Terraform governance?
- What is the difference between resource discovery and code-to-resource mapping in Terraform operations?