Hello,
I’m trying write custom provider and faced with next error
Error: roles: must be a map
I have the next field in the schema
"roles" : &schema.Schema {
Type : schema.TypeMap,
Computed : true,
Elem : &schema.Resource {
Schema : datasourceRoleSchema(),
},
},
and next code to setup
tmp := flattenRoles(value.([]Roles))
if len(tmp) > 0 {
err = d.Set(fieldName, tmp)
}
flattenRoles looks like
func flattenRoles(roles []Roles) []map[string]interface{} {
flattened := make([]map[string]interface{}, len(roles))
for i, v := range roles {
m := make(map[string]interface{})
m["role"] = flattenRole(v.Role)
flattened[i] = m
}
return flattened
}
func flattenRole(role *Role) map[string]interface{} {
m := make(map[string]interface{})
m["id"] = role.ID
m["label"] = role.Label
m["identifier"] = role.Identifier
return m
}
JSON input looks like:
"roles": [
{
"role": {
"created_at": "2020-03-10T14:34:27.000+02:00",
"id": 3,
"identifier": "locations_manager",
"label": "Cloud Locations Manager",
"permissions": [
{
"permission": {
"created_at": "2020-03-10T14:34:19.000+02:00",
"id": 137,
"identifier": "cdn_locations",
"updated_at": "2020-03-10T14:34:19.000+02:00"
}
},
{
"permission": {
"created_at": "2020-03-10T14:34:21.000+02:00",
"id": 450,
"identifier": "location_groups",
"updated_at": "2020-03-10T14:34:21.000+02:00"
}
}
],
"system": false,
"updated_at": "2020-03-10T14:34:27.000+02:00",
"users_count": 1
}
}
],