Help with nested dynamic block

If you can help me a nested dynamic group I am trying to solve, I have the values coming from a json like below

{
	"avi_gslbservice_groups": [
		{
			"name": "us-east-1",
			"priority": 10,
			"algorithm": "GSLB_ALGORITHM_ROUND_ROBIN",
			"avi_gslbservice_groups_ip": {
				"host": "url2",
				"enabled": "false"
			}
		},
		{
			"name": "us-east-2",
			"priority": 7,
			"algorithm": "GSLB_ALGORITHM_TOPOLOGY",
                        "avi_gslbservice_groups_ip": {
				"host": "url1",
				"enabled": "false"
			}
		}
	]
}

and dynamic code snippet like this,

dynamic "groups" {   
   for_each = var.avi_gslbservice_groups
   content {
      dynamic "members" {
        for_each = groups.value.avi_gslbservice_groups_ip
        content {
            ip {
                 type = "V4"
                 addr = ""
              }
              fqdn = members.value["host"]
              vs_uuid = ""
              cluster_uuid = ""
              ratio = 1
              enabled = members.value["enabled"]
            }         
          }        		    
        name = groups.value["name"]
        priority = groups.value["priority"]
        algorithm = groups.value["algorithm"]
      }
     }

problem I am facing is, name, priority and algorithm all get picked up correctly, but I am not able to select fqdn (host value from json) and enabled (enabled from json) from the second layer in json

Error I get at terraform plan is

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 25, in resource "avi_gslbservice" "avi_gslbservice":
  25:               fqdn = members.value["host"]
    ├────────────────
    │ members.value is "false"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 25, in resource "avi_gslbservice" "avi_gslbservice":
  25:               fqdn = members.value["host"]
    ├────────────────
    │ members.value is "url2"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 25, in resource "avi_gslbservice" "avi_gslbservice":
  25:               fqdn = members.value["host"]
    ├────────────────
    │ members.value is "false"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 25, in resource "avi_gslbservice" "avi_gslbservice":
  25:               fqdn = members.value["host"]
    ├────────────────
    │ members.value is "url1"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 29, in resource "avi_gslbservice" "avi_gslbservice":
  29:               enabled = members.value["enabled"]
    ├────────────────
    │ members.value is "false"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 29, in resource "avi_gslbservice" "avi_gslbservice":
  29:               enabled = members.value["enabled"]
    ├────────────────
    │ members.value is "url2"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 29, in resource "avi_gslbservice" "avi_gslbservice":
  29:               enabled = members.value["enabled"]
    ├────────────────
    │ members.value is "false"

This value does not have any indices.

Error: Invalid index

  on modules\avi\avi_gslbservice.tf line 29, in resource "avi_gslbservice" "avi_gslbservice":
  29:               enabled = members.value["enabled"]
    ├────────────────
    │ members.value is "url1"

This value does not have any indices.

Below resolved my issue.

There was nothing to iterate over in my avi_gslbservice_groups_ip , thus got the error. I changed the logic to have only one dynamic block as below,

dynamic "groups" {   
   for_each = var.avi_gslbservice_groups
   
   content {
        members {
            ip {
                 type = "V4"
                 addr = ""
              }
              fqdn = groups.value.avi_gslbservice_groups_ip["host"]
              vs_uuid = ""
              cluster_uuid = ""
              ratio = 1
              enabled = groups.value.avi_gslbservice_groups_ip["enabled"]
            }                      
        name = groups.value["name"]
        priority = groups.value["priority"]
        algorithm = groups.value["algorithm"]
      }
     }

Also for people who want to have multiple host entries added in a single group can format the json as below, and use my original post’s nested dynamic block. In below even you could provide single host within and still original post’s nested dynamic block would work.

{
    "avi_gslbservice_groups": [
        {
            "name": "us-east-1",
            "priority": 7,
            "algorithm": "GSLB_ALGORITHM_ROUND_ROBIN",
            "avi_gslbservice_groups_ip": [
                {
                    "host": "host1",
                    "enabled": "true"
                },
                {
                    "host": "host2",
                    "enabled": "false"
                }
            ]
        },
        {
            "name": "us-east-2",
            "priority": 10,
            "algorithm": "GSLB_ALGORITHM_TOPOLOGY",
            "avi_gslbservice_groups_ip": [
                {
                    "host": "host1",
                    "enabled": "true"
                },
                {
                    "host": "host2",
                    "enabled": "false"
                }
            ]
        }
    ]
}