Every plan shows an update for `aws_security_group` and `aws_security_group_rule` alternately adding and removing the same rule.
IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer
Likely causes → Inline ingress {} blocks in aws_security_group and separate rule resources manage the same group. Each one thinks the other's rules are drift.
Diagnose → grep -rn 'security_group_id\s*=\s*aws_security_group.web' . alongside ingress { in the group.
Fix → Choose one style. Current best practice: no inline rules, use aws_vpc_security_group_ingress_rule / aws_vpc_security_group_egress_rule. Move rules with removed/import to avoid gaps.
Prevent → Same rule for route tables (route {} vs aws_route) and IAM (inline policy vs attachment resources).
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`.IntermediateThe plan prints `Note: Objects have changed outside of Terraform` and lists a security group with an extra ingress rule.BeginnerEvery 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