From f4395bf355802e1a9fee7061936a93f6a5e5c655 Mon Sep 17 00:00:00 2001 From: michaelkad Date: Mon, 28 Oct 2024 14:56:26 -0500 Subject: [PATCH] Custom Diff User Tags --- ibm/flex/structures.go | 18 ++++++++++++++++++ .../resource_ibm_pi_network_address_group.go | 2 +- .../resource_ibm_pi_network_security_group.go | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ibm/flex/structures.go b/ibm/flex/structures.go index 41c407e251..ba3ece8d05 100644 --- a/ibm/flex/structures.go +++ b/ibm/flex/structures.go @@ -2902,7 +2902,25 @@ func ResourceTagsCustomizeDiff(diff *schema.ResourceDiff) error { } return nil } +func ResourcePowerUserTagsCustomizeDiff(diff *schema.ResourceDiff) error { + if diff.Id() != "" && diff.HasChange("pi_user_tags") { + // power tags + o, n := diff.GetChange("pi_user_tags") + oldSet := o.(*schema.Set) + newSet := n.(*schema.Set) + removeInt := oldSet.Difference(newSet).List() + addInt := newSet.Difference(oldSet).List() + if v := os.Getenv("IC_ENV_TAGS"); v != "" { + s := strings.Split(v, ",") + if len(removeInt) == len(s) && len(addInt) == 0 { + fmt.Println("Suppresing the TAG diff ") + return diff.Clear("pi_user_tags") + } + } + } + return nil +} func ResourceValidateAccessTags(diff *schema.ResourceDiff, meta interface{}) error { if value, ok := diff.GetOkExists("access_tags"); ok { diff --git a/ibm/service/power/resource_ibm_pi_network_address_group.go b/ibm/service/power/resource_ibm_pi_network_address_group.go index b20b0cf26e..fddb0bed04 100644 --- a/ibm/service/power/resource_ibm_pi_network_address_group.go +++ b/ibm/service/power/resource_ibm_pi_network_address_group.go @@ -35,7 +35,7 @@ func ResourceIBMPINetworkAddressGroup() *schema.Resource { }, CustomizeDiff: customdiff.Sequence( func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - return flex.ResourceTagsCustomizeDiff(diff) + return flex.ResourcePowerUserTagsCustomizeDiff(diff) }, ), Schema: map[string]*schema.Schema{ diff --git a/ibm/service/power/resource_ibm_pi_network_security_group.go b/ibm/service/power/resource_ibm_pi_network_security_group.go index b92c8a8e45..4f1f107562 100644 --- a/ibm/service/power/resource_ibm_pi_network_security_group.go +++ b/ibm/service/power/resource_ibm_pi_network_security_group.go @@ -36,7 +36,7 @@ func ResourceIBMPINetworkSecurityGroup() *schema.Resource { }, CustomizeDiff: customdiff.Sequence( func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - return flex.ResourceTagsCustomizeDiff(diff) + return flex.ResourcePowerUserTagsCustomizeDiff(diff) }, ), Schema: map[string]*schema.Schema{