I have a nested map as part of the attribute list in my terraform provider. I get an error mentioned below when I run terraform apply on my provider.
Below is the piece of code I am using:
func resourceUplinkSet() *schema.Resource {
return &schema.Resource{
Create: resourceUplinkSetCreate,
Read: resourceUplinkSetRead,
Update: resourceUplinkSetUpdate,
Delete: resourceUplinkSetDelete,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"port_config_infos": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"desired_speed": {
Type: schema.TypeString,
Optional: true,
},
"location": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"location_entries": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
Optional: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
},
},
},
},
}
}
Expected Result: Terraform apply creates the specified resouce.
Actual Result: Terraform crashes with the following message.
panic: interface conversion: interface {} is map[string]interface {}, not ov.PortConfigInfos
which points to the assignment portConfigInfos[i] = raw.(ov.PortConfigInfos)
shown below.
I'm trying to set the value of "port_config_infos" using a for loop:
portConfigInfosList := d.Get("port_config_infos").(*schema.Set).List()
portConfigInfos := make([]ov.PortConfigInfos,len(portConfigInfosList))
for i,raw := range portConfigInfosList {
portConfigInfos[i] = raw.(ov.PortConfigInfos)
}
uplinkSet.PortConfigInfos = portConfigInfos
I'm new to Terraform and not sure if I'm using the proper data type in the assignment. How can I proceed?