From 8f5cdcb20ce823bc485382794a408d58125b9910 Mon Sep 17 00:00:00 2001 From: michaelkad Date: Mon, 28 Oct 2024 14:56:26 -0500 Subject: [PATCH] Custom Diff User Tags Add compute to tag Add compute to tag, batch2 Remove custom diff --- ibm/flex/structures.go | 18 ++++++++++++++++++ ibm/service/power/resource_ibm_pi_capture.go | 7 +++++++ ibm/service/power/resource_ibm_pi_image.go | 7 +++++++ ibm/service/power/resource_ibm_pi_instance.go | 7 +++++++ ibm/service/power/resource_ibm_pi_network.go | 7 +++++++ .../resource_ibm_pi_network_address_group.go | 3 ++- .../power/resource_ibm_pi_network_interface.go | 7 +++++++ .../resource_ibm_pi_network_port_attach.go | 1 + .../resource_ibm_pi_network_security_group.go | 3 ++- ...rce_ibm_pi_network_security_group_member.go | 2 +- ...ource_ibm_pi_network_security_group_rule.go | 2 +- .../resource_ibm_pi_shared_processor_pool.go | 7 +++++++ ibm/service/power/resource_ibm_pi_snapshot.go | 7 +++++++ ibm/service/power/resource_ibm_pi_volume.go | 7 +++++++ ibm/service/power/resource_ibm_pi_workspace.go | 7 +++++++ 15 files changed, 88 insertions(+), 4 deletions(-) diff --git a/ibm/flex/structures.go b/ibm/flex/structures.go index dadae9c479..8ecf9dd77b 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 OnlyInUpdateDiff(resources []string, diff *schema.ResourceDiff) error { for _, r := range resources { if diff.HasChange(r) && diff.Id() == "" { diff --git a/ibm/service/power/resource_ibm_pi_capture.go b/ibm/service/power/resource_ibm_pi_capture.go index e3e1dea544..5c35be92cc 100644 --- a/ibm/service/power/resource_ibm_pi_capture.go +++ b/ibm/service/power/resource_ibm_pi_capture.go @@ -19,6 +19,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -38,6 +39,11 @@ func ResourceIBMPICapture() *schema.Resource { Delete: schema.DefaultTimeout(50 * time.Minute), Update: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ @@ -108,6 +114,7 @@ func ResourceIBMPICapture() *schema.Resource { Description: "Cloud Storage Image Path (bucket-name [/folder/../..])", }, Arg_UserTags: { + Computed: true, Description: "List of user tags attached to the resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_image.go b/ibm/service/power/resource_ibm_pi_image.go index 1814bbd06a..eb770c72d5 100644 --- a/ibm/service/power/resource_ibm_pi_image.go +++ b/ibm/service/power/resource_ibm_pi_image.go @@ -11,6 +11,7 @@ import ( "github.com/IBM/go-sdk-core/v5/core" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -37,6 +38,11 @@ func ResourceIBMPIImage() *schema.Resource { Delete: schema.DefaultTimeout(60 * time.Minute), Update: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ helpers.PICloudInstanceId: { @@ -191,6 +197,7 @@ func ResourceIBMPIImage() *schema.Resource { }, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_instance.go b/ibm/service/power/resource_ibm_pi_instance.go index c73c01bd14..b59af4d690 100644 --- a/ibm/service/power/resource_ibm_pi_instance.go +++ b/ibm/service/power/resource_ibm_pi_instance.go @@ -13,6 +13,7 @@ import ( "github.com/IBM/go-sdk-core/v5/core" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -36,6 +37,11 @@ func ResourceIBMPIInstance() *schema.Resource { Update: schema.DefaultTimeout(60 * time.Minute), Delete: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -315,6 +321,7 @@ func ResourceIBMPIInstance() *schema.Resource { Type: schema.TypeString, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 3670aa3d10..0a4cf6937a 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -13,6 +13,7 @@ import ( "github.com/apparentlymart/go-cidr/cidr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -43,6 +44,11 @@ func ResourceIBMPINetwork() *schema.Resource { Update: schema.DefaultTimeout(60 * time.Minute), Delete: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ helpers.PINetworkType: { @@ -123,6 +129,7 @@ func ResourceIBMPINetwork() *schema.Resource { }, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, 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..09016d6354 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{ @@ -54,6 +54,7 @@ func ResourceIBMPINetworkAddressGroup() *schema.Resource { ValidateFunc: validation.NoZeroValues, }, Arg_UserTags: { + Computed: true, Description: "The user tags associated with this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_network_interface.go b/ibm/service/power/resource_ibm_pi_network_interface.go index f1deb2956a..087093a6a3 100644 --- a/ibm/service/power/resource_ibm_pi_network_interface.go +++ b/ibm/service/power/resource_ibm_pi_network_interface.go @@ -11,6 +11,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -35,6 +36,11 @@ func ResourceIBMPINetworkInterface() *schema.Resource { Delete: schema.DefaultTimeout(60 * time.Minute), Update: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -69,6 +75,7 @@ func ResourceIBMPINetworkInterface() *schema.Resource { ValidateFunc: validation.NoZeroValues, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index 99bb5adb05..da171a1b67 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -32,6 +32,7 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource { Create: schema.DefaultTimeout(60 * time.Minute), Delete: schema.DefaultTimeout(60 * time.Minute), }, + Schema: map[string]*schema.Schema{ helpers.PICloudInstanceId: { Type: schema.TypeString, 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..2fef018292 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{ @@ -55,6 +55,7 @@ func ResourceIBMPINetworkSecurityGroup() *schema.Resource { ValidateFunc: validation.NoZeroValues, }, Arg_UserTags: { + Computed: true, Description: "The user tags associated with this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_network_security_group_member.go b/ibm/service/power/resource_ibm_pi_network_security_group_member.go index 50fd0e7614..7178c753d1 100644 --- a/ibm/service/power/resource_ibm_pi_network_security_group_member.go +++ b/ibm/service/power/resource_ibm_pi_network_security_group_member.go @@ -301,7 +301,7 @@ func resourceIBMPINetworkSecurityGroupMemberRead(ctx context.Context, d *schema. if err != nil { log.Printf("Error on get of network security group (%s) user_tags: %s", parts[1], err) } - d.Set(Arg_UserTags, userTags) + d.Set(Attr_UserTags, userTags) } if len(networkSecurityGroup.Members) > 0 { members := []map[string]interface{}{} diff --git a/ibm/service/power/resource_ibm_pi_network_security_group_rule.go b/ibm/service/power/resource_ibm_pi_network_security_group_rule.go index 2d8461bbe4..704e775de5 100644 --- a/ibm/service/power/resource_ibm_pi_network_security_group_rule.go +++ b/ibm/service/power/resource_ibm_pi_network_security_group_rule.go @@ -421,7 +421,7 @@ func resourceIBMPINetworkSecurityGroupRuleRead(ctx context.Context, d *schema.Re if err != nil { log.Printf("Error on get of network security group (%s) user_tags: %s", nsgID, err) } - d.Set(Arg_UserTags, userTags) + d.Set(Attr_UserTags, userTags) } if len(networkSecurityGroup.Members) > 0 { diff --git a/ibm/service/power/resource_ibm_pi_shared_processor_pool.go b/ibm/service/power/resource_ibm_pi_shared_processor_pool.go index ccd4b9371c..babdbe57a1 100644 --- a/ibm/service/power/resource_ibm_pi_shared_processor_pool.go +++ b/ibm/service/power/resource_ibm_pi_shared_processor_pool.go @@ -16,6 +16,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -33,6 +34,11 @@ func ResourceIBMPISharedProcessorPool() *schema.Resource { Update: schema.DefaultTimeout(60 * time.Minute), Delete: schema.DefaultTimeout(60 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -78,6 +84,7 @@ func ResourceIBMPISharedProcessorPool() *schema.Resource { Type: schema.TypeInt, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_snapshot.go b/ibm/service/power/resource_ibm_pi_snapshot.go index 7db802f492..77abed3358 100644 --- a/ibm/service/power/resource_ibm_pi_snapshot.go +++ b/ibm/service/power/resource_ibm_pi_snapshot.go @@ -14,6 +14,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -32,6 +33,11 @@ func ResourceIBMPISnapshot() *schema.Resource { Update: schema.DefaultTimeout(60 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -59,6 +65,7 @@ func ResourceIBMPISnapshot() *schema.Resource { ValidateFunc: validation.NoZeroValues, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_volume.go b/ibm/service/power/resource_ibm_pi_volume.go index 365de4a32c..7ca96e4b84 100644 --- a/ibm/service/power/resource_ibm_pi_volume.go +++ b/ibm/service/power/resource_ibm_pi_volume.go @@ -17,6 +17,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -35,6 +36,11 @@ func ResourceIBMPIVolume() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -96,6 +102,7 @@ func ResourceIBMPIVolume() *schema.Resource { Type: schema.TypeSet, }, Arg_UserTags: { + Computed: true, Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_workspace.go b/ibm/service/power/resource_ibm_pi_workspace.go index 179bf09507..78603ae90c 100644 --- a/ibm/service/power/resource_ibm_pi_workspace.go +++ b/ibm/service/power/resource_ibm_pi_workspace.go @@ -11,6 +11,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -29,6 +30,11 @@ func ResourceIBMPIWorkspace() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), }, + CustomizeDiff: customdiff.Sequence( + func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { + return flex.ResourcePowerUserTagsCustomizeDiff(diff) + }, + ), Schema: map[string]*schema.Schema{ // Arguments @@ -62,6 +68,7 @@ func ResourceIBMPIWorkspace() *schema.Resource { ValidateFunc: validation.NoZeroValues, }, Arg_UserTags: { + Computed: true, Description: "List of user tags attached to the resource.", Elem: &schema.Schema{Type: schema.TypeString}, Optional: true,