العودة إلى الدورة

For_Each: التكرار المتقدم

احتراف البنية التحتية كبرمجيات (Terraform & OpenTofu)

Maps and Sets

count is great for identical resources. But what if you have a list of different user names?

hcl variable "users" { type = set(string) default = ["alice", "bob", "charlie"] }

resource "aws_iam_user" "the_team" { for_each = var.users name = each.key }

for_each is more robust than count because it doesn't care about the order of the list. If you delete 'alice', 'bob' and 'charlie' remain untouched.