HashiCorp Terraform Associate 004: Terraform Drift Detection

Terraform drift is the gap between the infrastructure Terraform expects and the infrastructure that actually exists. It commonly appears after manual console changes, emergency fixes, automated systems that modify managed resources, provider-side defaults, or organizational processes that allow changes outside the Terraform workflow.

The current HashiCorp Terraform Associate 004 exam gives candidates the state and planning concepts needed to understand drift. For Terraform engineering teams, the operational questions are when to check drift, who assesses it and how to restore desired state without undoing an intentional emergency change.

Drift detection is useful only when it leads to reconciliation. A permanent dashboard full of known differences is not control; it is a second undocumented configuration system.

A normal plan is already a drift-detection tool

Before Terraform creates a plan, providers refresh relevant remote object data unless refresh is disabled. The resulting plan can therefore show changes caused by remote infrastructure that no longer matches the configuration or recorded state. An unexpected update or replacement may be evidence of drift rather than a code change.

The team should distinguish configuration-driven changes from refresh-driven changes during review. When a plan suddenly proposes action after no HCL changed, the first question should be what changed remotely, not which line of code is wrong.

Plans should also be read in context of provider behavior. A provider can normalize an API value or begin tracking an attribute that older versions ignored, producing a diff after an upgrade. That is not the same root cause as a human console edit even though both appear as a change between state/configuration and remote reality.

Refresh-only plans separate observation from remediation

Terraform’s plan -refresh-only mode reads remote object values and proposes a state-only reconciliation without planning changes to deployed resources. Producing this plan does not itself write state. A reviewed apply -refresh-only can record the observed values in state while leaving the remote resources unchanged. HCP Terraform health assessments use non-actionable refresh-only plans to check for differences between normal runs.

This is useful when operators need to understand what changed before choosing a response. They can review a refresh-only plan, distinguish unexpected remote edits from provider-computed fields, and decide whether to accept the observed state, restore desired infrastructure, or change the configuration. Even when state is updated, it is not a substitute for a reviewed HCL change that expresses the intended long-term setting.

Refresh-only workflows are particularly useful after an incident when operators know emergency changes occurred but are not yet ready to decide the permanent configuration. The team can capture current reality, understand the differences, and then prepare a reviewed configuration change instead of immediately forcing infrastructure back to the pre-incident state.

HCP Terraform can assess drift between runs

On eligible workspaces in HCP Terraform Standard or Premium, enabled health assessments can identify drift between normal runs using non-actionable refresh-only plans. HashiCorp’s example schedule is approximately daily, but assessment timing depends on recent runs, workspace eligibility, successful prior applies and whether remote or agent execution is used. These checks report observed differences; they do not update state or infrastructure themselves.

Continuous assessment is most valuable for important long-lived environments where manual or external changes are plausible. Ephemeral environments may not justify the same monitoring. Teams should align assessment cadence with the risk and change rate of the infrastructure rather than enabling alerts without an owner.

Continuous assessment should avoid alert duplication with ordinary plans. If every deployment already produces reviewed drift information, the health-assessment channel should focus on changes that appear between runs. Otherwise teams can receive the same known difference from several monitoring systems and begin ignoring all of them.

Health assessments are not substitutes for normal change review. They provide an independent signal between runs, but a production apply still needs a fresh plan because remote infrastructure may have changed after the last assessment. The detection cadence and deployment cadence solve different timing problems.

Not all drift should be reverted

An emergency firewall change made during an incident may be legitimate even though it bypassed Terraform. A managed cloud service may also adjust an attribute that the provider intentionally treats as computed. Blindly applying the old configuration can undo a necessary change or fight a service’s normal behavior.

The general configuration drift principle is to classify differences. Some should be reverted because they violate policy, some should be imported into configuration because the business intent changed, and some should be ignored because the attribute is not part of the desired-state contract.

Acceptance of legitimate drift should be explicit. If a managed service owns a field, the Terraform resource configuration or lifecycle settings should reflect that ownership. Repeatedly acknowledging the same harmless diff is a sign that the desired-state model does not accurately describe the real control boundary.

The source of drift determines the right fix

Manual changes may indicate missing permissions controls or a cumbersome deployment path. Repeated automation-generated changes may indicate that Terraform and another controller both believe they own the same field. Provider normalization differences may require configuration changes rather than process enforcement.

Teams should record the actor, time, API path, and business reason behind significant drift when those signals are available. That evidence turns a plan diff into an operating-system diagnosis rather than a simple “someone changed it” accusation.

Root-cause analysis should also ask why the alternate change path existed. A console fix may indicate missing Terraform coverage, insufficient permissions in the pipeline, an emergency procedure that bypasses review, or a workflow too slow for operations. Fixing those conditions prevents the same drift pattern from recurring.

State refresh does not make configuration correct

Updating state to reflect remote reality can reduce a plan diff, but it does not encode intended behavior in HCL. If a manual change is now the accepted desired state, the configuration must be updated so a future plan does not try to reverse it.

Conversely, changing configuration merely to silence every diff can institutionalize accidental settings. The configuration review should ask whether the new value is intentional, maintainable, and consistent with architecture and policy before it becomes source-controlled intent.

Updating configuration after a legitimate manual change should preserve review history. The commit can document the incident or business decision that changed the desired value, turning what was once unmanaged drift into an intentional part of the infrastructure model.

Teams should also decide how to handle drift in attributes intentionally managed by another controller, such as Kubernetes operators or cloud autoscaling services. If Terraform and the controller both write the same field, the system has competing desired-state engines. The fix is usually to clarify ownership, not to increase drift-alert frequency.

Policy and permissions can prevent recurring classes of drift

Cloud IAM, organization policies, policy-as-code, and deployment permissions can reduce who or what is allowed to modify Terraform-managed resources. Prevention is especially useful for high-risk controls such as network boundaries, encryption, and identity settings.

CI/CD pipelines also reduce drift when they provide a fast, auditable change path. Operators bypass Terraform less often when the normal workflow can deliver an urgent reviewed change quickly. Governance should fix the process incentive as well as the technical symptom.

Preventive controls should avoid trapping operators during emergencies. A policy that completely blocks console changes may improve consistency but become dangerous if the Terraform pipeline itself is unavailable. Mature governance provides a break-glass path with strong logging and a mandatory reconciliation step afterward.

Permissions should also make destructive manual drift harder than benign observation. Read-only operational access can support troubleshooting without granting the ability to change Terraform-owned controls. Where break-glass write access is necessary, the account should be short-lived or tightly audited so the later reconciliation has a clear actor and timeline.

Drift monitoring needs ownership and severity

Not every changed tag deserves the same response as a disabled encryption setting. Detection systems should classify drift by resource sensitivity, attribute importance, environment, and whether the change creates a security or availability risk.

An alert should identify the workspace, resource address, changed attributes, last known run, and next responsible owner. Without that context, the operations team must reconstruct basic facts before it can decide whether the infrastructure should be changed or the configuration should be updated.

Severity can also depend on whether the drift is self-healing or persistent. A temporary autoscaling attribute may settle naturally, while a public firewall rule or disabled encryption setting requires immediate response. Alerting should focus on the control impact, not just the presence of any diff.

The goal is one trustworthy desired-state path

Terraform drift is unavoidable in some environments, but unmanaged drift should be temporary. The organization needs a consistent path back to a state where configuration, state, and reality agree on the attributes Terraform owns.

Terraform engineering treats drift as feedback about the whole operating model: access controls, emergency procedures, pipeline speed, provider behavior, and ownership. Detecting differences is the first step; deciding and documenting the reconciliation is what restores control.

Drift metrics should measure time to reconciliation, not only number of detections. A low alert count can hide stale unmanaged differences, while a high count can reflect healthy detection of a dynamic environment. The stronger metric is whether significant drift is classified and either encoded or reverted within the organization’s target window.

A drift program should periodically review ignored differences as well. An exception that was reasonable during a migration can become obsolete later, leaving important attributes outside Terraform control. Expiring and revalidating exceptions keeps the desired-state boundary from shrinking permanently.

Leave a Reply

How It Works

img
Step 1. Choose Exam
on ExamLabs
Download IT Exams Questions & Answers
img
Step 2. Open Exam with
Avanset Exam Simulator
Press here to download VCE Exam Simulator that simulates real exam environment
img
Step 3. Study
& Pass
IT Exams Anywhere, Anytime!