Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Diff User Tags #175

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 OnlyInUpdateDiff(resources []string, diff *schema.ResourceDiff) error {
for _, r := range resources {
if diff.HasChange(r) && diff.Id() == "" {
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
1 change: 1 addition & 0 deletions ibm/service/power/resource_ibm_pi_network_port_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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_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
Loading