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

r/aws_devopsguru_notification_channel: fix filters persistent diff #36804

Merged
merged 1 commit into from Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .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
```
31 changes: 16 additions & 15 deletions internal/service/devopsguru/notification_channel.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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](),
),
},
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions internal/service/devopsguru/notification_channel_test.go
Expand Up @@ -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() {
Expand All @@ -104,16 +103,15 @@ 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"),
resource.TestCheckResourceAttrPair(resourceName, "sns.0.topic_arn", snsTopicResourceName, "arn"),
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"),
),
},
{
Expand Down Expand Up @@ -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
Expand All @@ -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)
}