Infrastructure as Code Drift Detection Guide: Audit Cloud Resources Before They Break Deployments
Terraforminfrastructure as codeconfiguration driftcloud operationsDevOps

Infrastructure as Code Drift Detection Guide: Audit Cloud Resources Before They Break Deployments

SScaleCloud Editorial Team
2026-11-15
7 min read

Use this IaC drift detection checklist to compare code, state, and live cloud resources before deployments and remediate differences safely.

Infrastructure drift occurs when live cloud resources no longer match the Terraform, Kubernetes, or other infrastructure-as-code definitions your team reviews and deploys. This guide provides a reusable audit checklist, detection commands, approval workflow, and remediation template so you can identify drift before it causes a failed deployment, security gap, unexpected cost, or service interruption.

Overview

Infrastructure as code is most reliable when the declared configuration, state data, and real cloud environment remain aligned. Drift appears when one of those layers changes without the others being updated. A person may alter a firewall rule in a console, an automated platform process may change a value, or a provider may normalize a setting after deployment. Emergency fixes are a common source of drift, particularly when the change is made directly to production and documented later.

Not every difference requires the same response. Some differences are intentional and should be represented in code. Others are accidental and should be reverted. A third category may require importing an existing resource or adjusting lifecycle and ignore rules. Treating every plan difference as a simple “apply” decision can overwrite a valid operational change or create an avoidable outage.

A practical drift audit compares three inputs:

  • Declared configuration: the version-controlled Terraform, Kubernetes manifest, Pulumi program, CloudFormation template, or equivalent source.
  • Recorded state: the tool’s state representation, including resource identifiers and tracked attributes.
  • Live resources: the current settings and relationships reported by the cloud provider or cluster.

Run the audit with read-only access where possible, use the correct workspace or account, and record the commit, state version, provider versions, and timestamp. In a production environment, ensure state locking and remote-state access controls are working before any command that could modify state.

Checklist by scenario

Before a planned deployment

  1. Confirm the selected account, subscription, project, region, and Terraform workspace or equivalent environment.
  2. Review the proposed code change and identify resources with replacement, deletion, access-control, networking, storage, or data-retention implications.
  3. Use the project’s normal initialization and validation steps, such as formatting, configuration validation, and provider lock-file checks.
  4. Run a plan that refreshes provider information, then inspect changes that were not expected from the current commit.
  5. Separate genuine drift from computed values, timestamps, generated identifiers, provider defaults, and values deliberately ignored by configuration.
  6. Obtain approval from the service owner for security, availability, data, and cost-impacting changes.

For Terraform, teams commonly begin with a normal plan and may use terraform plan -refresh-only when they need to examine how the recorded state would change to reflect live infrastructure. Command behavior can vary with Terraform and provider versions, so verify the syntax and review the plan output before accepting any state change. Do not treat a refresh-only operation as a substitute for reviewing live resource configuration.

After an emergency console or provider-side change

  1. Record who made the change, why it was needed, what resource was affected, and whether the change was temporary.
  2. Capture the current live configuration before making another modification.
  3. Run a read-only comparison against the repository version and state.
  4. Decide whether the emergency change is now the approved target state.
  5. If approved, update code and test it through the normal review path. If not approved, schedule a controlled rollback.
  6. Close the incident only after the code, state, and live environment have been reconciled.

During a monthly or quarterly audit

  1. List managed resources and compare them with provider inventory to find unmanaged additions or missing objects.
  2. Review identity, network exposure, encryption, backup, logging, and retention settings.
  3. Check for changes made outside the deployment pipeline and correlate them with tickets or incident records.
  4. Review drift in Kubernetes namespaces, workloads, ingress rules, secrets references, resource limits, and policy objects where those resources are managed through a declarative workflow.
  5. Assign each finding an owner, risk level, target date, and remediation decision.

Common detection commands and approaches

Exact commands depend on the tool, backend, provider, and workflow. Use these as investigation patterns rather than universal instructions:

  • terraform plan to compare configuration and refreshed resource information with the current state.
  • terraform plan -refresh-only to inspect state changes associated with live infrastructure, after checking the version-specific documentation.
  • terraform state list and terraform state show to inspect tracked resources and selected attributes.
  • terraform show -json to produce machine-readable plan or state data for review tooling, subject to sensitive-data handling requirements.
  • pulumi preview or the equivalent preview operation for another IaC system, with refresh behavior confirmed for the installed version.
  • A provider’s inventory, configuration-history, or resource-describe command to verify values directly against the live environment.
  • Kubernetes manifest comparison and server-side inspection, using the cluster context explicitly so the audit cannot silently target the wrong cluster.

What to double-check

Use this decision table for each finding:

Drift typeTypical questionLikely action
Intentional changeIs the live value now the approved target?Update the IaC definition, test it, and merge through review.
Accidental changeWas the difference caused by an unauthorized or obsolete action?Revert through a controlled deployment after confirming impact.
Unmanaged resourceShould this existing object be governed by code?Import or otherwise register it, then reconcile configuration carefully.
Provider-generated valueIs the difference computed, normalized, or outside practical control?Confirm provider behavior and use an appropriate computed or ignore mechanism only when justified.
Tool or schema changeDid a provider, module, cluster, or platform upgrade alter representation?Review release notes and test the upgrade in a non-production environment.

Pay particular attention to changes involving public exposure, security groups, IAM permissions, encryption keys, database parameters, persistent volumes, DNS, load balancers, autoscaling, and backup policies. A small-looking attribute change can have a large operational effect. Also verify whether a planned replacement will destroy or recreate data-bearing resources.

Before editing state, confirm the backend, locking mechanism, backup or version history, and access permissions. State manipulation is not a general-purpose repair method. If a resource exists outside state, importing it may be appropriate, but the resulting configuration still needs to be reviewed and brought under normal testing and approval controls.

For environments that include Kubernetes, keep cluster upgrades and drift reviews connected. A version or API change can alter defaults and supported fields; use a documented Kubernetes upgrade checklist before treating every manifest difference as user-caused drift.

Common mistakes

  • Applying the first plan: A plan is evidence for review, not automatic permission to change production.
  • Running against the wrong environment: Verify account, region, workspace, cluster context, and credentials in the terminal and in the review record.
  • Ignoring remote state locking: Concurrent operations can produce confusing results or damage the reliability of the state workflow.
  • Using broad ignore rules: Ignoring an attribute can hide a security or reliability change. Document the reason, owner, and scope.
  • Confusing state refresh with remediation: Updating state may record reality without changing the live resource or the source code.
  • Importing without normalizing code: An imported resource can generate a large follow-up plan unless its important settings are represented accurately.
  • Failing to protect plan output: Plans and JSON output may contain sensitive identifiers or values. Store and share them according to your security requirements.
  • Leaving emergency changes undocumented: An unrecorded exception is likely to reappear as drift during the next deployment.

Use a short remediation record for every material finding: resource, environment, detected difference, source of truth, business or technical risk, decision, code change or rollback, approver, deployment reference, and verification result. This creates an auditable trail without requiring a separate investigation each time drift returns.

When to revisit

Run a focused drift check before production deployments, after emergency console changes, after provider or module upgrades, and when ownership of an environment changes. Add a broader review to the monthly or quarterly operations calendar, with frequency adjusted for change volume and risk.

Refresh the procedure whenever the IaC tool, provider plugin, state backend, policy engine, Kubernetes version, or cloud platform changes. Confirm command syntax, refresh behavior, supported resource types, import workflows, locking guidance, and policy examples against the versions your team actually uses. Revisit the checklist before seasonal planning cycles or major traffic periods, especially when capacity, backup, disaster recovery, or security settings are being changed. Related reviews, including cloud cost controls and backup retention and restore procedures, can reveal drift that a deployment-only review misses.

Action for your next audit: choose one non-production environment, record its exact tool and provider versions, run a read-only comparison, classify every difference as adopt, revert, import, ignore with justification, or investigate, and assign an owner to each unresolved item. Once that workflow is reliable, apply it to production with explicit approvals and a documented rollback path.

Related Topics

#Terraform#infrastructure as code#configuration drift#cloud operations#DevOps
S

ScaleCloud Editorial Team

Cloud Infrastructure Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.