Interview Prep/Terraform/Plan Errors and Unexpected Replacements

`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.`

BeginnerTroubleshootingPlan Errors and Unexpected Replacements
Answer

Likely causes → You passed a list (var.users) directly.

Diagnose → terraform console → type(var.users).

Fix → for_each = toset(var.users), or build a map keyed by a stable field: { for u in var.users : u.name => u }.

Prevent → Declare variables as set(string) or map(object(...)) when they drive for_each.

All Terraform questions

More on Plan Errors and Unexpected Replacements