diff --git a/.changelog/36804.txt b/.changelog/36804.txt new file mode 100644 index 000000000000..7e0f3bdbeab0 --- /dev/null +++ b/.changelog/36804.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_devopsguru_notification_channel: Fix persistent diff when `filters.message_types` or `filters.severities` contains multiple elements +``` diff --git a/internal/service/devopsguru/notification_channel.go b/internal/service/devopsguru/notification_channel.go index 5ad7ed648c45..878a87392898 100644 --- a/internal/service/devopsguru/notification_channel.go +++ b/internal/service/devopsguru/notification_channel.go @@ -11,11 +11,12 @@ import ( "github.com/aws/aws-sdk-go-v2/service/devopsguru" awstypes "github.com/aws/aws-sdk-go-v2/service/devopsguru/types" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -60,28 +61,28 @@ func (r *resourceNotificationChannel) Schema(ctx context.Context, req resource.S }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "message_types": schema.ListAttribute{ + "message_types": schema.SetAttribute{ Optional: true, - CustomType: fwtypes.ListOfStringType, + CustomType: fwtypes.SetOfStringType, ElementType: types.StringType, - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplace(), + PlanModifiers: []planmodifier.Set{ + setplanmodifier.RequiresReplace(), }, - Validators: []validator.List{ - listvalidator.ValueStringsAre( + Validators: []validator.Set{ + setvalidator.ValueStringsAre( enum.FrameworkValidate[awstypes.NotificationMessageType](), ), }, }, - "severities": schema.ListAttribute{ + "severities": schema.SetAttribute{ Optional: true, - CustomType: fwtypes.ListOfStringType, + CustomType: fwtypes.SetOfStringType, ElementType: types.StringType, - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplace(), + PlanModifiers: []planmodifier.Set{ + setplanmodifier.RequiresReplace(), }, - Validators: []validator.List{ - listvalidator.ValueStringsAre( + Validators: []validator.Set{ + setvalidator.ValueStringsAre( enum.FrameworkValidate[awstypes.InsightSeverity](), ), }, @@ -241,8 +242,8 @@ type resourceNotificationChannelData struct { } type filtersData struct { - MessageTypes fwtypes.ListValueOf[types.String] `tfsdk:"message_types"` - Severities fwtypes.ListValueOf[types.String] `tfsdk:"severities"` + MessageTypes fwtypes.SetValueOf[types.String] `tfsdk:"message_types"` + Severities fwtypes.SetValueOf[types.String] `tfsdk:"severities"` } type snsData struct { diff --git a/internal/service/devopsguru/notification_channel_test.go b/internal/service/devopsguru/notification_channel_test.go index 88293ec168aa..b9029e9e9142 100644 --- a/internal/service/devopsguru/notification_channel_test.go +++ b/internal/service/devopsguru/notification_channel_test.go @@ -91,7 +91,6 @@ func testAccNotificationChannel_filters(t *testing.T) { resourceName := "aws_devopsguru_notification_channel.test" snsTopicResourceName := "aws_sns_topic.test" messageType := string(types.NotificationMessageTypeNewInsight) - severity := string(types.InsightSeverityHigh) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -104,7 +103,7 @@ func testAccNotificationChannel_filters(t *testing.T) { CheckDestroy: testAccCheckNotificationChannelDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccNotificationChannelConfig_filters(rName, messageType, severity), + Config: testAccNotificationChannelConfig_filters(rName, messageType), Check: resource.ComposeTestCheckFunc( testAccCheckNotificationChannelExists(ctx, resourceName, &channel), resource.TestCheckResourceAttr(resourceName, "sns.#", "1"), @@ -112,8 +111,7 @@ func testAccNotificationChannel_filters(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "filters.#", "1"), resource.TestCheckResourceAttr(resourceName, "filters.0.message_types.#", "1"), resource.TestCheckResourceAttr(resourceName, "filters.0.message_types.0", messageType), - resource.TestCheckResourceAttr(resourceName, "filters.0.severities.#", "1"), - resource.TestCheckResourceAttr(resourceName, "filters.0.severities.0", severity), + resource.TestCheckResourceAttr(resourceName, "filters.0.severities.#", "3"), ), }, { @@ -187,7 +185,7 @@ resource "aws_devopsguru_notification_channel" "test" { `, rName) } -func testAccNotificationChannelConfig_filters(rName, messageType, severity string) string { +func testAccNotificationChannelConfig_filters(rName, messageType string) string { return fmt.Sprintf(` resource "aws_sns_topic" "test" { name = %[1]q @@ -200,8 +198,8 @@ resource "aws_devopsguru_notification_channel" "test" { filters { message_types = [%[2]q] - severities = [%[3]q] + severities = ["LOW", "MEDIUM", "HIGH"] } } -`, rName, messageType, severity) +`, rName, messageType) }