Flattening schema need help

Hello

I have the next schema

"network" : &schema.Schema {
  Type          : schema.TypeSet,
  Computed      : true,
  Elem : &schema.Resource {
    Schema: map[string]*schema.Schema {
      "id" : &schema.Schema {
        Type      : schema.TypeInt,
        Computed  : true,
      },
    },
  },
},

if err := d.Set("network", flattenNetwork(ipnet.Network)); err != nil {
  return err
}

I have two functions first worked some time ago but now it don’t work

func flattenNetwork1(net testgo.ID) map[string]int {
   return map[string]int {
     "id" : net.ID,
   }
}

New function, but I got error - panic: interface conversion: interface {} is map[string]interface {}, not *schema.Set

func flattenNetwork2(net testgo.ID) *schema.Set {
  flattenedNetwork := schema.NewSet(schema.HashInt, []interface{}{})
  flattenedNetwork.Add( net.ID )
  return flattenedNetwork
}

JSON body which I get from API
[ { "ip_net":{ "network":{ "id":6 } } } ]

So what I do wrong?

3 Likes