diff --git a/examples/resources/nullplatform_notification_channel/resource.tf b/examples/resources/nullplatform_notification_channel/resource.tf index 33e3f94..4a848fa 100644 --- a/examples/resources/nullplatform_notification_channel/resource.tf +++ b/examples/resources/nullplatform_notification_channel/resource.tf @@ -88,5 +88,5 @@ output "github_channel_repository" { } output "agent_channel_command" { - value = nullplatform_notification_channel.custom_agent.configuration[0].agent[0].command[0].data.cmdline + value = nullplatform_notification_channel.agent.configuration[0].agent[0].command[0].data.cmdline } diff --git a/nullplatform/resource_notification_channel.go b/nullplatform/resource_notification_channel.go index 07f48ab..3d8996e 100644 --- a/nullplatform/resource_notification_channel.go +++ b/nullplatform/resource_notification_channel.go @@ -304,7 +304,11 @@ func NotificationChannelCreate(d *schema.ResourceData, m any) error { if err := json.Unmarshal([]byte(v.(string)), &filtersMap); err != nil { return fmt.Errorf("invalid filters JSON: %v", err) } - newChannel.Filters = filtersMap + if pruned, keep := pruneNulls(filtersMap); keep { + newChannel.Filters = pruned.(map[string]interface{}) + } else { + newChannel.Filters = make(map[string]interface{}) + } } else { newChannel.Filters = make(map[string]interface{}) } @@ -518,7 +522,9 @@ func NotificationChannelUpdate(d *schema.ResourceData, m any) error { if err := json.Unmarshal([]byte(v.(string)), &filtersMap); err != nil { return fmt.Errorf("invalid filters JSON: %v", err) } - updateChannel.Filters = filtersMap + if pruned, keep := pruneNulls(filtersMap); keep { + updateChannel.Filters = pruned.(map[string]interface{}) + } } if err := nullOps.UpdateNotificationChannel(d.Id(), updateChannel); err != nil { diff --git a/nullplatform/utils.go b/nullplatform/utils.go index fb73bc2..2962766 100644 --- a/nullplatform/utils.go +++ b/nullplatform/utils.go @@ -59,3 +59,36 @@ func tryParseJSON(value string) any { } return parsedValue } + + +func pruneNulls(v interface{}) (interface{}, bool) { + switch t := v.(type) { + case map[string]interface{}: + out := make(map[string]interface{}, len(t)) + for k, vv := range t { + if pruned, keep := pruneNulls(vv); keep { + out[k] = pruned + } + } + if len(out) == 0 { + return nil, false + } + return out, true + case []interface{}: + out := make([]interface{}, 0, len(t)) + for _, vv := range t { + if pruned, keep := pruneNulls(vv); keep { + out = append(out, pruned) + } + } + if len(out) == 0 { + return nil, false + } + return out, true + default: + if t == nil { + return nil, false + } + return t, true + } +} \ No newline at end of file