From 8549f091cd6aa315a17460b23b81dfa132d64eba Mon Sep 17 00:00:00 2001 From: Robert Horrox <31014379+RobertHorrox@users.noreply.github.com> Date: Tue, 17 Oct 2023 04:40:46 -0400 Subject: [PATCH] Fix opsgenie_integration_action filter block (#250) See: https://github.com/opsgenie/terraform-provider-opsgenie/issues/249 * Add code to check if filter block being added in expandOpsgenieIntegrationActions is empty. If empty set filter value to nil instead of the empty filter block. --- opsgenie/resource_opsgenie_integration_action.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/opsgenie/resource_opsgenie_integration_action.go b/opsgenie/resource_opsgenie_integration_action.go index dead7760..b271214c 100644 --- a/opsgenie/resource_opsgenie_integration_action.go +++ b/opsgenie/resource_opsgenie_integration_action.go @@ -599,7 +599,14 @@ func expandOpsgenieIntegrationActions(input interface{}) []integration.Integrati action.CustomPriority = customPriority.(string) } filters := expandOpsgenieFilter(inputMap["filter"].([]interface{})) - action.Filter = &filters + + // If a filter is not included in the resource, this will still set an empty filter. `omitempty` will + // only leave out the key when marshaling the Json if its value is `nil` + if filters.ConditionMatchType == "" && len(filters.Conditions) == 0 { + action.Filter = nil + } else { + action.Filter = &filters + } if action.Type == integration.Create { action.Source = inputMap["source"].(string)