Loop since a list

Hello to everyone

I start in Terraform.

I need to create user groups on AWS

For a single group, I have this in the file main.tf :

resource "aws_iam_group" "DEV" {
  name = "development"
  path = "/"
  provider= aws.deploy
}

It works very well.

My goal is to use this function on a group list, for example :

  Production
  Preproduction
  Deployment
  Development

This group list will be in a file that can evolve.

How can I use this list in my file main.tf, please?

You can use for_each

Like that?

variable "IAM_GROUP" {
    type = "list"
    default = ["Production", "Preproduction", "Deployment"]
}

resource "aws_iam_group" "GROUP" {
  for_each = toset(var.IAM_GROUP)
  name = each.value
  path = "/"
  provider= aws.deploy
}