Adding multiple "managedRuleGroupName" in the aws_fms_policy resource

Below code basically creates 4 Policies with 4 different types of “managedRuleGroupName”:
resource “aws_fms_policy” “abc” {
provider = aws.mu
name = var.policy_name
for_each = toset(var.pre_process_managed_rule_group_names)
//Policy rules
security_service_policy_data {
type = var.policy_type
for_each = toset(var.pre_process_managed_rule_group_names)
managed_service_data = jsonencode({
type = var.policy_type
//First Rule Groups (can be defined via preProcessRuleGroups here)

  preProcessRuleGroups = [
    {
      //Available options for overrideAction are NONE|COUNT
      overrideAction = { type = "COUNT" }
      managedRuleGroupIdentifier = {
        vendorName = "AWS"
        //managedRuleGroupName = "AWSManagedRulesCommonRuleSet"
        managedRuleGroupName = each.key
      }
      ruleGroupType = "ManagedRuleGroup"
      excludeRules = []
    }

##########
I wanted to create a policy with all for “managedRuleGroupName” associated with one Policy while not having to create the block of managedRuleGroupIdentifier 4 times

If you don’t need to use Terraform variables and can instead use language appropriate configuration, you could create the different groups using a for loop in the language that you are working with.

If you do indeed need to keep using Terraform variables, at this point you’ll need to resort to use overrides that effectively let you write the hcl.