For each inside a resource causes "resource already exists error"

hi , i am trying to create 1 firewall security rule group and multiple env variables inside that group from a yaml file .

yaml example :

rule_groups:
  - name: "TEST"
    allowed-domains:
     - ".go.microsoft.com"
     - ".signin.aws.amazon.com"
    source: "10.129.1.0/24"

  - name: "TEST2"
    allowed-domains:
     - ".go.microsoft.com"
     - ".vortex.data.microsoft.com"
     - ".vscodeexperiments.azureedge.net"
     - ".vscode-cdn.net"
     - ".vscode.blob.core.windows.net"
     - ".visualstudio.com"
    source: "10.129.12.0/24"    

terraform example :
my problem is with the “rule_variables” section , terraform fails when iam trying to create multipile “ip_sets” “key” and thinks iam trying to recreate the rule group itself

locals {
list  = yamldecode(file("${path.module}/settings.yaml"))["rule_groups"]
fw_group_rule = flatten([for rule in local.list : {
      "name"                       = rule.name
      "allowed-domains"            = rule.allowed-domains
      "definition"                 = rule.source
    }
  ])
}

resource "aws_networkfirewall_rule_group" "limit-Domain-Access" {
  for_each = {
    for rule in local.fw_group_rule : rule.name => rule
    }
  capacity = 1000
  name     = "limit-Domain-Access"
  type     = "STATEFUL"
  rule_group {
  rule_variables {
    ip_sets {
      key = each.value.name
      ip_set {
        definition = [each.value.definition]
      }
   }
}
  rules_source {
    rules_string = <<EOF
    pass http ֿֿֿֿֿ${"$"}${each.value.name} any -> $EXTERNAL_NET any (http.host; dotprefix; content:"${join(", ", each.value.allowed-domains)}"; endswith; msg:"matching HTTP allowlisted FQDNs"; priority:1; flow:to_server, established; sid:1; rev:1;)
    EOF
  }
}
   tags = {
   Name = "limit-Domain-Access"
  }

ERROR :

│ Error: error creating NetworkFirewall Rule Group limit-Domain-Access: InvalidRequestException: A resource with the specified name already exists
│ 
│   with aws_networkfirewall_rule_group.limit-Domain-Access["TEST2"],
│   on domain_access_suricata.tf line 11, in resource "aws_networkfirewall_rule_group" "limit-Domain-Access":
│   11: resource "aws_networkfirewall_rule_group" "limit-Domain-Access" {
│ 

I would appreciate any help .

solved : amazon web services - terraform loop over nested resource objets - Stack Overflow