Skip to content

Commit

Permalink
Custom Diff User Tags
Browse files Browse the repository at this point in the history
Add compute to tag
Add compute to tag, batch2
  • Loading branch information
michaelkad committed Nov 18, 2024
1 parent 2af014a commit ad7d899
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 4 deletions.
18 changes: 18 additions & 0 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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{

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/resource_ibm_pi_network_address_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/resource_ibm_pi_network_port_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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/resource"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
Expand All @@ -32,6 +33,12 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource {
Create: 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.PICloudInstanceId: {
Type: schema.TypeString,
Expand Down Expand Up @@ -64,6 +71,7 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource {
Computed: true,
},
Arg_UserTags: {
Computed: true,
Description: "The user tags attached to this resource.",
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/resource_ibm_pi_network_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_shared_processor_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_volume_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -30,6 +31,11 @@ func ResourceIBMPIVolumeClone() *schema.Resource {
Create: schema.DefaultTimeout(15 * time.Minute),
Delete: schema.DefaultTimeout(15 * time.Minute),
},
CustomizeDiff: customdiff.Sequence(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
return flex.ResourcePowerUserTagsCustomizeDiff(diff)
},
),

Schema: map[string]*schema.Schema{
// Arguments
Expand All @@ -53,6 +59,7 @@ func ResourceIBMPIVolumeClone() *schema.Resource {
Type: schema.TypeBool,
},
Arg_UserTags: {
Computed: true,
Description: "The user tags attached to this resource.",
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/power/resource_ibm_pi_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ad7d899

Please sign in to comment.