Renaming a security group's `name` forces replacement, and the apply fails with `InvalidGroup.Duplicate` or hangs on `DependencyViolation`.
AdvancedTroubleshootingPlan Errors and Unexpected Replacements
Answer
Likely causes → name forces a new group. Default order is destroy-then-create, but the old group is attached to ENIs and can't be deleted. With create_before_destroy, the same name conflicts.
Diagnose →
aws ec2 describe-network-interfaces --filters Name=group-id,Values=sg-0abc123 \
--query 'NetworkInterfaces[].[NetworkInterfaceId,Description]'
Fix → Use name_prefix plus create_before_destroy = true so a new group is created, attached, then the old one deleted. Or revert the rename (description/tags may be enough).
Prevent → Security groups should use name_prefix and lifecycle CBD from day one.
More on Plan Errors and Unexpected Replacements
`Error: Invalid for_each argument` — `The "for_each" map includes keys derived from resource attributes that cannot be determined until apply`.Intermediate`The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type list of string.`Beginner`Error: Invalid for_each argument` — `Sensitive values, or values derived from sensitive values, cannot be used as for_each arguments.`Intermediate`Error: Invalid count argument` — `The "count" value depends on resource attributes that cannot be determined until apply`.Intermediate`Error: Unsupported attribute` — `This object has no argument, nested block, or exported attribute named "public_ip_address"`.Beginner`Error: Unsupported attribute` on `module.vpc.private_subnets` — `This object does not have an attribute named "private_subnets"`.Beginner