From 1ae6b759d4ac6517058aa4a25d2f6928b28c0ffa Mon Sep 17 00:00:00 2001 From: Matias Navarro Date: Wed, 20 Aug 2025 11:23:33 -0300 Subject: [PATCH 1/2] feat(resource-channel): prune null filters values --- .../resource.tf | 2 +- nullplatform/utils.go | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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/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 From e9bc3cca7bf7ee1cbb9dbf3feb5f807c1e56fa0f Mon Sep 17 00:00:00 2001 From: Matias Navarro Date: Wed, 20 Aug 2025 11:24:02 -0300 Subject: [PATCH 2/2] feat: add to resource --- nullplatform/resource_notification_channel.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 {