Skip to content

Commit

Permalink
Merge pull request #40684 from kamilturek/b-aws-ses-identity-notifica…
Browse files Browse the repository at this point in the history
…tion-topic-delete-invalid

r/aws_ses_identity_notification_topic: Do not fail when deleting not existing resource
  • Loading branch information
ewbankkit authored Dec 23, 2024
2 parents ce8bc78 + d27abe5 commit 9524f4f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/40684.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ses_identity_notification_topic: Prevent destroy failure when resource is already deleted outside of Terraform
```
15 changes: 10 additions & 5 deletions internal/service/ses/identity_notification_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -78,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),
Expand Down Expand Up @@ -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 = "|"
Expand Down
27 changes: 27 additions & 0 deletions internal/service/ses/identity_notification_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9524f4f

Please sign in to comment.