Github team_membership can't inerit users of other team

I have made (manualy) in github a team called Land and assigned 2 users to this team.

data "github_team" "Land" {
  slug = "my-land"
}

Then, I created trough terrform, 2 new tams called A1-team and A2-team.

locals {
  team_descriptions = {for name in var.team-names : name => format(var.team_description_template, name)}
}

resource "github_team" "managed_team" {
  for_each = var.team-names
  name        = each.value
  description = local.team_descriptions[each.key]
  privacy     = "closed"
}

variable "team-names" {
  type = set(string)
  default = ["A1-team", "A2-team"]
}

Changes to Outputs:
  + gh-land-team = [
      + {
          + A1-team   = {
              + create_default_maintainer = false
              + description               = "A1-team is part of my-land"
              + etag                      = (known after apply)
              + id                        = (known after apply)
              + ldap_dn                   = null
              + members_count             = (known after apply)
              + name                      = "A1-team"
              + node_id                   = (known after apply)
              + parent_team_id            = null
              + privacy                   = "closed"
              + slug                      = (known after apply)
            }
          + A2-team = {
              + create_default_maintainer = false
              + description               = "A2-team is part of my-land"
              + etag                      = (known after apply)
              + id                        = (known after apply)
              + ldap_dn                   = null
              + members_count             = (known after apply)
              + name                      = "A2-team"
              + node_id                   = (known after apply)
              + parent_team_id            = null
              + privacy                   = "closed"
              + slug                      = (known after apply)
            }
        },
    ]
  + members      = [
      + "user1",
      + "user2",
    ]

My problem is when trying to assing the users of team “Land” to the newly created teams A1-team and A2-team. I want teams A1 and A2 to have the same users as Land team (user1 and user2).

locals {
  team_ids = [for team_name in var.team-names : github_team.managed_team["${team_name}"].id]
}

resource "github_team_membership" "memberships" {
  for_each = toset(data.github_team.Land.members)
  team_id = "${local.team_ids}"
  username = each.value
}


│ Error: Incorrect attribute value type
│
│   on 1-Land.tf line 67, in resource "github_team_membership" "memberships":
│   67:   team_id = "${local.team_ids}"
│     ├────────────────
│     │ local.team_ids is tuple with 2 elements
│
│ Inappropriate value for attribute "team_id": string required.
╵
╷
│ Error: Incorrect attribute value type
│
│   on 1-Land.tf line 67, in resource "github_team_membership" "memberships":
│   67:   team_id = "${local.team_ids}"
│     ├────────────────
│     │ local.team_ids is tuple with 2 elements
│
│ Inappropriate value for attribute "team_id": string required.

The github_team_membership resource is used to add a specific user to a specific team. You are trying to add a user to multiple teams, which isn’t possible. Instead you need to add the users to each team in turn. You can either do that by having two different resources (one for A1 & the other for A2), which would each loop through the list of users, or by making the for_each loop through the product of the users & teams (i.e. you loop through A1 user1, A1 user2, A2 user1, A2 user2) - take a look at the setproduct function: setproduct - Functions - Configuration Language | Terraform | HashiCorp Developer

Hello Stuart,

Thanks for your reply!
I thought that it’s possible to assign the members of one team to multiple teams since it worked by “maping” 1 to 1 and I could not figure out the for_each to do this.

resource "github_team_membership" "assign-team-a1" {
  for_each = toset(data.github_team.Land.members)
  team_id = github_team.A1-team.id
  username = each.value
}
resource "github_team_membership" "assign-team-a2" {
  for_each = toset(data.github_team.Land.members)
  team_id = github_team.A2-team.id
  username = each.value
}

I will try to do this with setproduct function.