Interview Prep/Terraform/Lost, Corrupted and Drifted State

Drift detection in CI fails every night on a Lambda function's `source_code_hash`, though no one deployed.

IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → The ZIP is built in CI and contains timestamps or file permission differences, so its hash changes every build; or the app team deploys Lambda code with another tool.

Diagnose → Build the archive twice and compare sha256sum; check CloudTrail for UpdateFunctionCode from non-Terraform principals.

Fix → Make builds reproducible (archive_file from a fixed source dir, stable file modes), or split ownership: Terraform manages the function config and ignore_changes = [source_code_hash, s3_key], CI deploys the code.

Prevent → Agree which tool owns application code vs infrastructure.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State