Removing one item from the middle of a list makes the plan destroy and recreate every subsequent resource.
IntermediateTroubleshootingPlan Errors and Unexpected Replacements
Answer
Likely causes → count with a list: instances are addressed by index, so removing [1] shifts [2] → [1] and so on. Terraform sees changed arguments at each index.
Diagnose → The plan shows aws_iam_user.u[1], [2], [3] being changed/replaced.
Fix → Switch to for_each = toset(var.users) with moved blocks from each index to its key, then remove the item.
Prevent → Use count only for "0 or 1" or truly identical copies; use for_each for collections.
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