Infrastructure drift is one of the most persistent failure modes in infrastructure as code. When cloud resources diverge from the Terraform configuration and state file, the environment becomes an unknown that erodes security, compliance, reliability, and cost control. Terraform Cloud drift detection provides a native, scheduled reconciliation loop that surfaces those divergences, notifies the right operators, and offers remediation paths without building custom tooling.
What Terraform Drift Is and Why It Matters
Infrastructure drift in Terraform describes a mismatch between the blueprint — your .tf files and modules — and the actual resources running in the cloud, and the Terraform state file is the artifact that represents the platform's understanding of that blueprint.
Terraform drift detection identifies when the actual cloud infrastructure diverges from the declared Terraform infrastructure as code configuration, and this gap matters for security, compliance, reliability, and cost.
Drift refers to changes from the desired state of your infrastructure as defined in your Terraform configuration and state to its actual state. For example, you may code five AWS EC2 instances with Terraform code, deploy them with terraform apply, and have them created in your AWS account. Then someone can go to the AWS console, change the parameters for these instances, or even manually delete one of them. Such changes made outside of your IaC process are drift.
If your Terraform code doesn't define a resource and you create it manually, that is not drift. However, this manual approach means you don't have control over the resource through your process, and creating multiple resources manually will incur costs your team won't know about. You will also have to update these resources manually, which can be time-consuming for a large number of infrastructure resources.
The problem is not limited to consoles. Manual changes, console modifications, or other automation can silently alter infrastructure, leaving serious blind spots and inconsistencies.
How Terraform Cloud Drift Detection Works
Terraform Cloud, also known as HCP Terraform, is one of the most popular platforms for managing Terraform code. Apart from managing Terraform state or helping implement policy as code, it can also help you detect drift.
In Terraform Cloud, drift detection works by running terraform plan against your infrastructure to compare the actual state of your resources with what is recorded in your state file.
It works by performing automatic, background evaluations of your workspaces at scheduled intervals — typically starting 24 hours after the last successful run. During these assessments, HCP Terraform executes a background refresh to query the cloud provider's APIs and sync the current state of managed resources. It then compares this live state against the expected configuration defined in your code to identify "configuration drift" — discrepancies caused by manual changes, service failures, or external automation.
When a mismatch is identified, the platform updates the workspace status to a "Drift" designation, populates a dedicated Drift tab with a visualization of the specific attribute changes, and triggers customizable notifications via email, Slack, or webhooks. This automated loop allows operators to proactively remediate drift by either overwriting the external changes with a standard plan or accepting them by updating the configuration through a refresh-only plan.
This runs periodically, and if it detects that your infrastructure doesn't match the state, it will record it as drift.
Terraform Cloud displays the current state of drift and provides additional information such as the last time drift was checked, the resources detected as being in a state of drift, and a visualization of what attributes have changed.
Key Features of Terraform Cloud Drift Detection
| Feature | Description |
|---|---|
| Periodical runs | Checks for infrastructure drift on a schedule |
| Drift summary in UI | Easy to understand which resources have drifted |
| Notifications | Send notifications to Slack or apps that support webhooks |
| Remediation workflow | Make your VCS the single source of truth, as it should be in any GitOps workflow |
| Central visibility | Displays current drift state, last check time, affected resources, and attribute visualization |
Enabling Drift Detection in Terraform Cloud
To enable drift detection in TFC, you will first need to ensure that you are at least on the HCP Standard plan.
The configuration typically involves workspace settings and health assessments.
terraform {
cloud {
organization = "mycompany"
workspaces {
name = "production"
}
}
}
In Terraform Cloud workspace settings:
Enable "Automatic speculative plans"
Set "Drift detection" to run on schedule
The enablement flow is:
Select the workspace you want to enable drift detection for, go to Settings, and then select Health:
Enable the Health Assessments and then select "Save settings" as shown.
Next, at the workspace level, go to Health, and then select Drift. Here, you will see all the information related to drift.
By default, this runs daily, but you can start a new health assessment that includes drift detection.
Terraform Cloud:
Runs scheduled drift detection
Sends notifications for detected drift
Shows drift in the UI
Can auto-queue remediation runs
Notifications and Alerting
With drift detection for Terraform Cloud you can create customizable notifications to make sure the right people are alerted using your preferred method of communication, including email, Slack, or a webhook.
The ability to send notifications to Slack or apps that support webhooks is a core feature.
Customizable notifications and context to understand when changes occur, track down who made them, and avoid application downtime.
Notifications to the appropriate people when changes occur so you can take action to avoid unnecessary costs.
Remediation Options When Drift Is Detected
There are three main things you can do when drift is detected:
- Reapply your code to fix the drift by reverting it to its previous state
Reapplying your code to fix the drift by reverting it to its previous state is a valid solution
Operators can resolve drift issues directly from the Terraform Drift tab by accepting changes with a refresh-only plan or by making changes to the new infrastructure state.
The automated loop allows operators to proactively remediate drift by either overwriting the external changes with a standard plan or accepting them by updating the configuration through a refresh-only plan.
Handling Drift
Option 1: Accept Terraform's Desired State
Apply Terraform to bring infrastructure back to desired state:
```
Review the changes
terraform plan
Apply to fix drift
terraform apply
```
Option 2: Accept the Drifted State
Update Terraform
A remediation workflow to make your VCS the single source of truth, as it should actually be in any GitOps workflow.
Analyzing Drift Output
Export Plan for Analysis
```
Generate plan in JSON format
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
Parse with jq
jq '.resource_changes[] | select(.change.actions | contains(["update"]))' plan.json
```
Drift Report Script
```
!/bin/bash
drift-report.sh
set -e
echo "=== Terraform Drift Report ==="
echo "Generated: $(date)"
echo ""
terraform init -input=false > /dev/null
Capture plan output
PLANOUTPUT=$(terraform plan -detailed-exitcode 2>&1) || EXITCODE=$?
if [ "${EXITCODE:-0}" -eq 0 ]; then
echo "Status: No drift detected"
elif [ "${EXITCODE:-0}" -eq 2 ]; then
echo "Status: DRIFT DETECTED"
echo ""
echo "Changes:"
echo "$PLANOUTPUT" | grep -A 100 "Terraform will perform"
else
echo "Status: Error during plan"
echo "$PLANOUTPUT"
fi
```
Benefits of Drift Detection for Terraform Cloud
Agility and simplicity
A central plane to manage and provide visibility into your infrastructure without creating custom tooling or manually running a plan or refresh for every workspace or state.
Reduce risk
Customizable notifications and context to understand when changes occur, track down who made them, and avoid application downtime.
Reduce cost
Notifications to the appropriate people when changes occur so you can take action to avoid unnecessary costs.
env zero emphasizes continuous monitoring integrated with VCS, scheduling, policy enforcement, automated remediation workflows, cost management, and centralized governance — features organizations typically prioritize when moving from manual checks to platform-scale reconciliation.
The guide covers native Terraform commands and their limits, automated continuous monitoring patterns, governance controls such as policy-as-code and RBAC, remediation decision frameworks, and a practical tool-evaluation checklist for selecting drift detection solutions.
Real-world tradeoffs — including operational overhead, auditability, and cost implications — are emphasized so you can choose between manual processes and automated reconciliation.
Alternative and Complementary Approaches
Build a zero-cost drift detection system using GitHub Actions and Terraform's native exit codes. This workflow automatically discovers all Terraform root modules, runs daily drift checks, and creates GitHub issues when changes are detected.
Infrastructure drift happens when your cloud resources diverge from your Terraform state. Manual changes, console modifications, or other automation can silently alter infrastructure, leaving some serious blind spots and inconsistencies. Traditional drift detection generally involves complex, custom, or expensive solutions.
By leveraging Terraform's built-in exit codes and GitHub's issue tracking, we can build a robust drift detection system using only native features with no external services required. This approach works well for small-to-medium deployments. Larger-scale production use requires additional considerations like multi-account support, sensitive data sanitization, and automated remediation.
The workflow runs on a daily schedule and supports manual execution via workflow_dispatch.
Conclusion
Terraform Cloud drift detection transforms drift from an invisible risk into a visible, actionable event. The platform runs scheduled refreshes and plans against live cloud APIs, surfaces attribute-level changes in a dedicated Drift tab, and delivers customizable notifications through email, Slack, or webhooks. Enablement requires an HCP Standard plan and activating Health Assessments at the workspace level, after which drift checks run by default daily and can be triggered on demand.
The value is not just detection. Operators can remediate directly from the UI by reapplying code to revert drift or by accepting external changes via a refresh-only plan, keeping the VCS as the single source of truth. This reduces manual plan runs, centralizes visibility across workspaces, and provides context to track who changed what and when, which directly reduces security risk, compliance exposure, downtime, and unexpected cost.
For teams that need broader governance, drift detection integrates with policy-as-code and RBAC controls, continuous monitoring patterns, and automated remediation workflows. For smaller setups, native Terraform exit codes combined with GitHub Actions can provide a zero-cost drift check, though production scale demands the auditability, multi-account support, and sanitization that platform-native drift detection provides.