Your Infrastructure Didn't Change, Your Policy Did: Detecting Governance-Transition Drift in IaC
Drift tools miss non-compliance caused by a policy change when IaC and cloud state still match. Here is how to detect it and validate fixes against policy intent.
The Blind Spot
Every infrastructure-as-code (IaC) team knows configuration drift: someone changes a resource in the portal, and the live state no longer matches the Terraform or Bicep in Git. Tools like terraform plan, driftctl, and cloud-native drift detection exist to catch exactly that.
Now consider a different failure:
- Day 1: Policy v4 allows storage accounts with public network access. Your storage account is compliant.
- Day 30: Policy v5 requires private endpoints. Nobody touched anything.
- Day 31: The same storage account is now non-compliant. The IaC still matches the cloud.
terraform planreports "No changes."
Nothing drifted between code and cloud. What drifted is the definition of "correct." I call this governance-transition drift: non-compliance introduced by a policy version change, while IaC and live state remain mutually consistent.

Standard drift detection answers: "Does reality match the code?" Governance-transition drift detection answers: "Does the code still match the rules?"
These are different questions, and the second one is usually answered only by a periodic compliance scan, which tells you that a resource fails, but not why it started failing or which policy change caused it.
Why Compliance Scanners Don't Close the Gap
A policy scanner (Azure Policy, OPA/Conftest, Sentinel, AWS Config) will flag the non-compliant storage account after v5 ships. That's useful, but three things are missing:
- Causality. The finding says "public access enabled." It does not say "this became a violation when clause
SEC-STORAGE-014was added in v5." - Traceability. The finding points at a cloud resource ID, not at the Terraform module and address that owns it.
- Fix quality. Fixes are judged by whether the scanner turns green, not by whether the policy's purpose was met.
Solving these requires treating policy as a versioned artifact and diffing it, the same way we diff code.
The Approach: From Policy Change to Approved Fix
I built a prototype (Python/FastAPI backend, VS Code extension front end, Bicep for the Azure footprint) around the pipeline below. The first five steps explain what changed and which resources are affected; the last three produce a safe fix.

Detection comes down to four ideas: normalize, diff, map, and detect.
- Normalize policies into versioned, atomic control clauses.
- Diff two policy versions semantically at clause level.
- Map each clause to the resources it governs and to the IaC block that declares them.
- Detect resources that were compliant under the old version and are not under the new one.
Step 1: Policies as Atomic, Machine-Readable Clauses
Policy documents come in many formats. The first step is to reduce them to one internal shape. A clause has a predicate (what must be true) and, importantly, an intent (why it exists):
@dataclass
class IntentMetadata:
objective: str
intent_assertions: List[str]
@dataclass
class ControlClause:
clause_id: str
name: str
resource_type: str
predicate_field: str
predicate_operator: str # equals | not_equals | contains | exists
predicate_value: str
intent: IntentMetadata
severity: str = "high"
def evaluate(self, resource_attributes: dict) -> bool:
actual = resource_attributes.get(self.predicate_field)
if self.predicate_operator == "equals":
return str(actual).lower() == str(self.predicate_value).lower()
...
A baseline is just a versioned list of these clauses. Because clauses carry a stable clause_id, two versions can be compared by ID rather than by fuzzy text matching.
Step 2: A Semantic Delta, Not a Text Diff
A text diff of two policy files tells you lines changed. A semantic delta tells you what changed in meaning. Each difference is classified as added, tightened, rescoped, relaxed, or removed.

The asymmetry is the key insight: only three of the five change types can make a previously compliant resource non-compliant, so the detector only needs to examine those.
@property
def introduces_drift(self) -> bool:
return self.change_type in ("added", "tightened", "rescoped")
Step 3: A Dependency Graph From Clause to Source Block
A finding is only actionable if an engineer can go from the finding to the line of code that needs changing. The graph links three layers:
policy clause -> cloud resource -> IaC block (file, module, address)
Each graph node also carries ownership, application, and any active exception (waiver). That last part matters: a resource with a valid, unexpired exception should be reported as excepted, not open.
Step 4: Detecting the Transition
The core algorithm is deliberately small. For each drift-introducing change in the delta:
- Find the resources of the type the clause governs.
- Evaluate each under the old baseline. For an
addedclause it was implicitly compliant; for atightenedclause, evaluate the old predicate. - Evaluate it under the new clause.
- If it was compliant and is now non-compliant, it is a governance-transition finding.
- Apply exception filtering.
was_compliant = self._evaluate_under_old(node, change, old_baseline)
is_non_compliant = not clause.evaluate(node.resource.attributes)
if was_compliant and is_non_compliant:
status = "excepted" if node.exception_id and self._is_exception_valid(node) else "open"
findings.append(DriftFinding(
...
root_cause={
"policy_version_old": old_baseline.version,
"policy_version_new": new_baseline.version,
"clause_change": change.change_type,
"iac_live_consistent": True,
},
iac_block={"file": ..., "module": ..., "address": ...},
status=status,
))
The "was compliant, now isn't" condition is what separates this from an ordinary compliance scan. It isolates resources whose status changed purely because the rules changed, and the root_cause payload records exactly which versions and which clause were responsible.
This turns a vague notification ("some resources are non-compliant") into a precise, explainable one. From the prototype's demo run:
Finding
GD-2026-0001: storage accountstproddata01became non-compliant when clauseSEC-STORAGE-014(Storage Private Endpoint Only) was added in policy v5.0. IaC and live state are identical and unchanged. The offending block isinfrastructure/storage.tf, addressmodule.storage.azurerm_storage_account.main.
The Second Problem: Fixes That Satisfy the Scanner but Not the Policy
Once you know what to fix, you have to fix it. Here's a trap: many remediations are judged by whether the scanner passes.
Consider a clause whose predicate is public_network_access == disabled, with the intent "no public path to the data." A quick fix sets the property to disabled. The scanner passes. But if no private endpoint or private DNS zone exists, then nothing can reach the account at all, or worse, a service-endpoint bypass still leaves a path open. The predicate is satisfied; the intent is not.

To catch this, each clause carries intent assertions, and the validator evaluates the post-remediation state against them, not only the predicate:
is_scanner_only = clause.evaluate(post_remediation_state) and not passed
The prototype's demo runs both cases against the same clause:
- Scanner-only fix (public access off, but no private endpoint or DNS link): predicate passes, intent validation fails, flagged as a scanner-only fix.
- Complete fix (public access off, private endpoint configured, private DNS zone linked): both pass.
This is cheap to express and surfaces a class of "green but wrong" changes that otherwise get merged.
Generating the Fix in the Right Dialect
Remediation is emitted in the same IaC format as the finding's source block (Terraform, Bicep, CloudFormation), as a before/after patch rather than an essay. Each remediation carries:
- the exact property change,
- the Well-Architected Framework recommendation it satisfies (for example, Azure WAF SE:06 for network isolation),
- a pointer to the official verified module (Azure Verified Modules for Terraform/Bicep) so teams converge on maintained patterns instead of hand-rolled snippets.
For the storage example, the Terraform change is small:
# before
public_network_access_enabled = true
# after
public_network_access_enabled = false
network_rules {
default_action = "Deny"
bypass = ["AzureServices"]
}
paired with a private endpoint and DNS zone link. The principle is to choose the least-disruptive change that satisfies the intent, and to put it behind an approval-gated pull request with the evidence attached: policy versions, clause, resource, and validation result.
Running It
The prototype includes a runnable demo that loads two sample baselines, computes the delta, detects drift, and then runs the intent validator:
cd backend
python -m src.services.demo
On the bundled sample data, the move from policy v4.0 to v5.0 adds three clauses: private endpoint only, TLS 1.2 minimum, and private DNS zone required. Detection reports five findings across three storage accounts: three open, and two excepted because the legacy account stprodlegacy04 has an active waiver (EXC-2026-001). Every finding records that IaC and live state are still consistent, so a conventional drift tool would have reported nothing.
The demo then runs the intent check from the previous section: the scanner-only fix passes the predicate but fails intent validation, and the complete fix passes both.
Honest Limitations
This is a prototype, and the gaps are worth stating plainly:
- Tightened vs. changed. The current delta engine classifies any change to a predicate's value, operator, or field as "tightened." Determining whether a change is truly stricter or merely different needs per-operator reasoning (for example, ordering TLS versions, or set inclusion for allowed values). Misclassification here yields false positives.
- Heuristic intent checks. The intent validator currently matches assertion text (such as "public", "encrypt", "TLS") against known state fields. A production version needs a real exposure and reachability model, for example, NSG rules, routes, and endpoint policies.
- Sample data. Baselines and the resource graph are in-memory samples. The connectors for Azure Policy, Azure Resource Graph, AWS Config, Sentinel, and IaC parsers exist as scaffolding and need hardening against real tenants.
- Evaluation scope. Predicates compare flat attributes. Policies with complex conditions (
anyOf/allOfnesting, effects likeDeployIfNotExists) need a richer clause model.
Takeaways
- Treat policy as a versioned input to your delivery pipeline. If code is diffed and reviewed, the rules it is judged against deserve the same discipline.
- Diff at the clause level. Only added, tightened, and rescoped clauses can create new violations, which keeps detection focused and explainable.
- Record causality. "Compliant under v4, non-compliant under v5, IaC unchanged" is far more actionable than a bare violation list, and it makes policy rollouts something you can preview before they land.
- Validate intent, not just predicates. A fix that silences the scanner but leaves the exposure intact is worse than no fix, because it ends the investigation.
A natural next step is to run the delta before a policy is published, as a blast-radius preview: "if v5 ships today, these resources, owned by these teams, in these repositories, become non-compliant." That turns governance changes from surprises into planned migrations.
Opinions expressed by DZone contributors are their own.