Infrastructure drift occurs when deployed resources no longer match the configuration and state managed by your infrastructure as code workflow. This guide provides a repeatable way to detect drift, determine whether a change was intentional, choose between importing, reverting, or updating code, and record the decision safely.
Overview
Infrastructure as code (IaC) is most reliable when the repository is treated as the reviewable source of truth for cloud resources. Drift weakens that model. It can result from a console edit, an emergency command, an automated process outside the IaC pipeline, a provider default changing, or a resource being altered by another team.
Drift is not automatically an incident. An approved change made outside the normal workflow may simply indicate that the code and state need to be brought into alignment. An unapproved security-group rule, public endpoint, changed IAM binding, or reduced backup setting requires a different response. The first task is therefore classification, not immediate remediation.
A sound infrastructure drift detection workflow has five stages:
- Detect: compare the desired configuration with the observed remote resource.
- Confirm: establish whether the difference is real and identify its scope.
- Classify: decide whether the change was approved, accidental, unauthorized, or provider-managed.
- Remediate: update code, import a resource, revert the remote change, or adjust state only when justified.
- Record: preserve the plan, decision, owner, ticket, and validation results.
For Terraform-based workflows, a refresh-aware plan is commonly the starting point. A typical review sequence might be:
terraform init
terraform plan -out=drift-review.tfplan
terraform show drift-review.tfplanUse the equivalent plan, refresh, or preview operation for your IaC tool. Avoid assuming that every apparent difference is drift: computed attributes, provider behavior, ignored fields, secrets, timestamps, and resources managed by more than one system can all affect a comparison.
For related operational checks, see the Terraform plan review checklist and the cloud IAM access review workflow.
Checklist by scenario
Scenario 1: A scheduled plan reports changes
- Save the plan output and note the workspace, account, region, commit, and execution time.
- Confirm that the plan used the expected credentials, variable files, backend, provider versions, and workspace.
- Separate additions, updates, and destructions. Treat replacement actions and access-control changes as high priority.
- Compare the changed attributes with recent commits, deployment records, and approved tickets.
- Ask the owning team whether a console action, migration, recovery procedure, or separate automation created the change.
- Do not apply solely because the plan is non-empty. First establish the intended end state.
Scenario 2: The change was intentional
If the remote change is approved and should remain, update the IaC configuration to express that decision. Run formatting, validation, policy checks, and a fresh plan. Review whether the change also requires updates to variables, modules, documentation, access reviews, alerts, or cost controls.
In some cases, the resource already exists remotely but is missing from state. Import it using the tool's supported import workflow, then adjust the configuration until a subsequent plan represents the desired result. Importing does not automatically produce a complete, maintainable configuration; inspect all relevant arguments and avoid copying sensitive values into source control.
Scenario 3: The change was accidental or unauthorized
Preserve evidence before changing the resource: capture the plan, relevant audit events, the actor, timestamp, affected attributes, and any related incident record. Assess impact and prioritize exposure, data loss, availability, and access changes. If the desired configuration is still correct, a reviewed apply may restore the resource. For urgent security or availability issues, use the approved emergency procedure, then reconcile the emergency action with IaC afterward.
When the event may indicate compromise, do not treat a normal IaC apply as the complete response. Coordinate with the security and incident teams, rotate affected credentials where appropriate, and follow your organization’s incident runbook. The production incident runbook template can help structure that process.
Scenario 4: The difference is expected provider or platform behavior
Some attributes are computed, normalized, assigned by the provider, or controlled by a managed service. Check the provider documentation and the resource schema before suppressing a difference. If an attribute is intentionally outside IaC ownership, document that boundary and use the tool’s supported ignore or lifecycle mechanism narrowly. Do not ignore an entire resource to silence one confusing field.
Decision table
| Finding | Preferred action | Before applying |
|---|---|---|
| Approved remote change should remain | Update code and, if necessary, import the resource | Run validation, policy checks, and a fresh plan |
| Unapproved change conflicts with desired state | Revert through a reviewed IaC plan or emergency procedure | Preserve evidence and assess impact |
| Resource exists but is absent from state | Import, then model it in code | Confirm ownership and state-locking controls |
| Provider-managed or computed attribute | Verify behavior and document the boundary | Use a narrow ignore rule only when justified |
| Unclear ownership or possible compromise | Pause routine remediation and escalate | Involve security, operations, and the resource owner |
What to double-check
State and backend safety
- Verify that the command points to the correct backend, workspace, subscription or project, account, and region.
- Confirm that state locking is active where supported and that no concurrent apply is running.
- Protect state files and plan artifacts because they may contain resource details or sensitive values.
- Do not edit state manually unless the tool’s documented procedure and a recovery plan support it.
- Take an appropriate state backup or use the backend’s versioning and recovery features before high-risk operations.
Plan interpretation
- Look for replacement indicators, destructive actions, dependency changes, and changes to networking or identity.
- Check whether a variable, module, provider, or dependency version changed between the last known-good run and the current plan.
- Review both the human-readable plan and machine-readable output when your pipeline uses policy checks.
- Test the proposed configuration in a safe environment when the resource type or change permits it.
Ownership and policy
- Identify the owning team and the approved path for changes.
- Check whether a separate controller, operator, autoscaler, backup service, or cloud-managed feature writes to the resource.
- Confirm that the remediation preserves encryption, network boundaries, logging, backups, least privilege, and required availability settings.
- Use policy as code to flag risky changes before apply, but keep human review for context-dependent decisions.
For Kubernetes resources, the same principle applies even when the implementation differs: compare the declared manifests with the live cluster, identify the controller responsible for reconciliation, and avoid having two systems continually overwrite one another. See the GitOps drift detection and remediation workflow for that scenario.
Common mistakes
- Applying the first plan immediately: A plan describes proposed actions, not proof that those actions are safe. Review context, ownership, and impact first.
- Updating state to hide drift: State manipulation can make the tool stop reporting a difference without changing the real resource or documenting the desired configuration. Use it only for a clearly understood state-management problem.
- Importing without modeling: Import can associate an existing resource with state, but it does not replace configuration design, security review, or ownership decisions.
- Using broad ignore rules: Ignoring all changes on a resource can conceal security and availability problems. Scope exceptions to specific, understood attributes.
- Changing the console and planning later: Emergency access may be necessary, but an unrecorded console change leaves the team with an unreliable source of truth. Create the follow-up task immediately.
- Ignoring deletion and replacement: A small-looking argument change may force a replacement. Read the full plan and verify dependencies before approval.
- Failing to close the loop: A resolved resource can drift again if the cause remains. Review permissions, pipeline paths, ownership, and guardrails after remediation.
When to revisit
Make drift review part of normal infrastructure operations rather than a one-time cleanup. Run a plan on a schedule appropriate to the environment and risk, and review it before major deployments, migrations, seasonal planning cycles, and security or compliance reviews. Revisit the workflow whenever you change the IaC tool, provider, module structure, backend, state strategy, policy rules, or cloud account layout.
After a console change or emergency intervention, record the event while the context is fresh. The follow-up should end with one of three clear outcomes: the code now expresses the approved state, the remote resource has been safely reverted, or the ownership boundary has been documented and enforced.
Use this compact runbook during each review:
- Run a refresh-aware plan against the intended environment.
- Save the output and verify context, credentials, backend, and lock status.
- Classify every material difference as approved, accidental, unauthorized, provider-managed, or unknown.
- Escalate unknown or high-impact changes before remediation.
- Choose code update, import, revert, or a narrowly justified state action.
- Run validation, policy checks, and a fresh plan.
- Apply only after the appropriate approval.
- Record the final state, evidence, owner, ticket, and preventive action.
This workflow keeps infrastructure drift detection practical: detect changes early, make intent explicit, and ensure that the next plan reflects a state the team understands and can maintain.