Working with List and Variables

Attempting to create a list of groups in AAD when my code runs everything is fine accept the code only creates the first group name in the list and never creates the others. My code:
variable “azuread_group_name” {
description = “This is the variable file for user input for creating AAD Groups…”
type = list
default = [“c12test”, “c12tester1”, “c12tester3”]
}

The code you shown only generates the list variable, so I assume you have a azuread_group resource definition somewhere else generating the groups?

I would recommend using a map instead of a list for this even though there are no other attributes used, because if you use a list like above and decide to remove c12test, then the rest will be deleted and recreated with a different index.

variable “azuread_group_names” {
  description = “This is the variable file for user input for creating AAD Groups…”
  type = map
  default = {
    c12test : { name : “c12test”},
    c12tester1 : { name : “c12tester1”},
    c12tester3 : { name : “c12tester3”}
}

This is actually a map-of-maps to allow adding more attributes at a later time without having to make too many changes.

resource "azuread_group" "c123testgroups" {
  for_each = var.azuread_group_names
  name = each.value.name
}

Yes, I have azuread_group defined elesewhere and thanks for the tip I am new to terraform so currently on training wheels.

Without seeing the azuread_group resource definition you’re using, it’s difficult to say why the configuration is behaving the way it does.