The plan prints `Note: Objects have changed outside of Terraform` and lists a security group with an extra ingress rule.
BeginnerTroubleshootingLost, Corrupted and Drifted State
Answer
Likely causes → Drift: someone added a rule in the console or CLI during an incident.
Diagnose →
terraform plan -refresh-only
aws ec2 describe-security-groups --group-ids sg-0abc123 --query 'SecurityGroups[0].IpPermissions'
CloudTrail (AuthorizeSecurityGroupIngress) tells you who and when.
Fix → Decide: if the rule is wanted, add it to code. If not, a normal terraform apply removes it. Never just apply blindly during an incident; ask first.
Prevent → Read-only console access in prod, break-glass roles with alerts, and nightly terraform plan -detailed-exitcode drift checks.
More on Lost, Corrupted and Drifted State
Someone deleted the state object from the S3 bucket. `terraform plan` now wants to create 140 resources that already exist.IntermediateState is gone and the bucket had no versioning. How do you recover a production stack?Advanced`Error: Failed to load state` followed by a JSON error like `invalid character '}' looking for beginning of object key string`.IntermediateEvery plan wants to change `desired_capacity` on an Auto Scaling group back to 2, though autoscaling has raised it to 6.BeginnerA resource was deleted manually in the console. The plan wants to create it, and an apply fails because a dependent resource still references the old ID.Intermediate`terraform plan -refresh-only` shows drift, and you apply it. The next normal plan still wants to revert the change. Why?Intermediate