From ca43cbea0f7542b428417ce5981fa2ab60b2dab9 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Mon, 23 Dec 2024 20:19:03 +0100 Subject: [PATCH 1/4] Do not fail when deleting not existing resource --- internal/service/ses/identity_notification_topic.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/service/ses/identity_notification_topic.go b/internal/service/ses/identity_notification_topic.go index ce17ed2b6d3..ced1c975d72 100644 --- a/internal/service/ses/identity_notification_topic.go +++ b/internal/service/ses/identity_notification_topic.go @@ -12,6 +12,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ses" awstypes "github.com/aws/aws-sdk-go-v2/service/ses/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -157,11 +158,15 @@ func resourceIdentityNotificationTopicDelete(ctx context.Context, d *schema.Reso NotificationType: notificationType, }) + if tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "Must be a verified email address or domain") { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting SES Identity Notification Topic (%s): %s", d.Id(), err) } - return append(diags, resourceIdentityNotificationTopicRead(ctx, d, meta)...) + return diags } const identityNotificationTopicResourceIDSeparator = "|" From 2d1659307b9e60160fdecef084d5c6cdef5eabf3 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Mon, 23 Dec 2024 20:29:22 +0100 Subject: [PATCH 2/4] Add changelog --- .changelog/40684.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40684.txt diff --git a/.changelog/40684.txt b/.changelog/40684.txt new file mode 100644 index 00000000000..4a0f4573b68 --- /dev/null +++ b/.changelog/40684.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ses_identity_notification_topic: Prevent destroy failure when resource is already deleted outside Terraform +``` From b820af3631b46f13078b0addb552495b63ba86ec Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Dec 2024 15:28:06 -0500 Subject: [PATCH 3/4] Add 'TestAccSESIdentityNotificationTopic_Disappears_domainIdentity'. --- .../ses/identity_notification_topic_test.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/service/ses/identity_notification_topic_test.go b/internal/service/ses/identity_notification_topic_test.go index a0b92381d58..9457da2ffb1 100644 --- a/internal/service/ses/identity_notification_topic_test.go +++ b/internal/service/ses/identity_notification_topic_test.go @@ -59,6 +59,33 @@ func TestAccSESIdentityNotificationTopic_basic(t *testing.T) { }) } +// https://github.com/hashicorp/terraform-provider-aws/issues/36275. +func TestAccSESIdentityNotificationTopic_Disappears_domainIdentity(t *testing.T) { + ctx := acctest.Context(t) + domain := acctest.RandomDomainName() + resourceName := "aws_ses_identity_notification_topic.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.SESServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: acctest.CheckDestroyNoop, + Steps: []resource.TestStep{ + { + Config: testAccIdentityNotificationTopicConfig_basic(domain), + Check: resource.ComposeTestCheckFunc( + testAccCheckIdentityNotificationTopicExists(ctx, resourceName), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfses.ResourceDomainIdentity(), "aws_ses_domain_identity.test"), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func testAccCheckIdentityNotificationTopicExists(ctx context.Context, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] From d27abe5a1fb5d769fc258b2e9be1fcf31d06a851 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 23 Dec 2024 15:31:55 -0500 Subject: [PATCH 4/4] Cosmetics. --- .changelog/40684.txt | 2 +- internal/service/ses/identity_notification_topic.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.changelog/40684.txt b/.changelog/40684.txt index 4a0f4573b68..90cbe093b55 100644 --- a/.changelog/40684.txt +++ b/.changelog/40684.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_ses_identity_notification_topic: Prevent destroy failure when resource is already deleted outside Terraform +resource/aws_ses_identity_notification_topic: Prevent destroy failure when resource is already deleted outside of Terraform ``` diff --git a/internal/service/ses/identity_notification_topic.go b/internal/service/ses/identity_notification_topic.go index ced1c975d72..083ea702465 100644 --- a/internal/service/ses/identity_notification_topic.go +++ b/internal/service/ses/identity_notification_topic.go @@ -79,16 +79,16 @@ func resourceIdentityNotificationTopicSet(ctx context.Context, d *schema.Resourc inputSINT.SnsTopic = aws.String(v.(string)) } - if d.IsNewResource() { - d.SetId(id) - } - _, err := conn.SetIdentityNotificationTopic(ctx, inputSINT) if err != nil { return sdkdiag.AppendErrorf(diags, "setting SES Identity Notification Topic (%s): %s", id, err) } + if d.IsNewResource() { + d.SetId(id) + } + inputSIHINE := &ses.SetIdentityHeadersInNotificationsEnabledInput{ Enabled: d.Get("include_original_headers").(bool), Identity: aws.String(identity),