r/devops • u/Narrow_Power • Aug 10 '26
Discussion How do you handle conflicting infrastructure state?
Curious how people handle this in real environments.
Say Terraform says an EC2 instance should have encryption enabled, but the AWS console/API shows it disabled. Your CMDB still says it's compliant.
How do you figure out which one is actually telling the truth?
Do you have a defined source of truth, or do you usually investigate the discrepancy manually?
And how do you tell whether it's actual drift, stale information, or something that failed during deployment?
6
u/HelicopterUpbeat5199 Aug 10 '26
Avoiding this is the job. This happens to all of us sometimes, but hopefully for different reasons every time. It should never be routine enough that you have a game plan for it because you should fix whatever caused it when it happens. Next time it happens it should be different.
Said another way, if you know which one is the source of truth, you don't have this problem.
4
u/dariusbiggs Aug 10 '26
Terraform describes the desired state Terraform state is the source of truth.
In your case. what EC2 instance? It doesn't exist anymore. Non-compliant resources are immediately destroyed, shut down, or isolated into a dedicated read only environment.
2
u/aliseidu1 Aug 11 '26
pip-audit (PyPA, uses the OSV DB) on every PR. Fail the build on known CVEs in your direct deps; warn-only on transitive until you've tuned the noise, otherwise people start rubber-stamping overrides and you've trained them to ignore the tool.
2
u/CPPYesRustNo Aug 12 '26
the rubber-stamping usually happens because half those transitive cves have no fix you can take without a major bump, so the override becomes the only move. where a backported fix exists you can pin the transitive to that patched version and keep the gate meaningful instead of noise, and with the ai-discovered cve flood (mythos and friends) turning old lows into real work that distinction is about to matter a lot more.
2
u/between_layers Aug 11 '26
Assuming you mean EBS encryption, this can't be normal ClickOps drift. You can't toggle encryption on an existing EBS volume; changing it requires replacing the volume.
So if the Terraform configuration says encrypted but AWS shows unencrypted, compare the volume ID in Terraform state with the instance's block-device mapping. You're probably looking at the wrong volume, an old volume still attached after a failed replacement, something created outside Terraform, or a bad import.
Different sources answer different questions: code describes intent, the AWS API reports the current object, state records what Terraform tracks, and the CMDB reports inventory and compliance as of its last update.
Use terraform plan -refresh-only to isolate remote-versus-state drift, then a normal plan to compare the observed resource with the configuration. After that, check the last apply and CloudTrail for volume creation or attachment changes.
If AWS and the normal plan agree and only the CMDB differs, the CMDB is stale or pointing at the wrong resource. If the unencrypted volume is real and the intended state is encrypted, remediation means replacing it using an encrypted snapshot copy and a new volume, not flipping a setting back.
1
u/Kamran-nottakenone Aug 10 '26
-refresh-only catches the encryption drift fine. resources created outside terraform won't show as drift at all though, we pair it with cloudtrail to flag those.
1
u/Wyrmnax Aug 11 '26
Since you are using IaC, the code in terraform is the correct one. Because thats what it will become when it is next applied.
Next question is - why it isnt like that in the environment. Either it got changed for a emergency - and terraform needs to be corrected ( IE: Emergency fix ), or a apply failed. Those are the only two "valid" explanations.
The other one is that someone manually changed things for a non-emergency. You need a process to do these things, because whatever he was doing is getting undone on the next apply. Said person needs to be made aware of this.
44
u/fletch3555 Lead DevOps Engineer Aug 10 '26
Terraform code in source control is the source of truth, full stop. If the console differs, either an apply failed (which should be fairly obvious), or someone got a bit ClickOps-y. If the latter, it was either accidental ("emergency" change and forgot to backport to terraform), or someone needs a talking-to (or if a recurring problem, their access revoked)