Skip to content

Commit 9524f4f

Browse files
authored
Merge pull request #40684 from kamilturek/b-aws-ses-identity-notification-topic-delete-invalid
r/aws_ses_identity_notification_topic: Do not fail when deleting not existing resource
2 parents ce8bc78 + d27abe5 commit 9524f4f

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

.changelog/40684.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_ses_identity_notification_topic: Prevent destroy failure when resource is already deleted outside of Terraform
3+
```

internal/service/ses/identity_notification_topic.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/aws/aws-sdk-go-v2/aws"
1313
"github.com/aws/aws-sdk-go-v2/service/ses"
1414
awstypes "github.com/aws/aws-sdk-go-v2/service/ses/types"
15+
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1617
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -78,16 +79,16 @@ func resourceIdentityNotificationTopicSet(ctx context.Context, d *schema.Resourc
7879
inputSINT.SnsTopic = aws.String(v.(string))
7980
}
8081

81-
if d.IsNewResource() {
82-
d.SetId(id)
83-
}
84-
8582
_, err := conn.SetIdentityNotificationTopic(ctx, inputSINT)
8683

8784
if err != nil {
8885
return sdkdiag.AppendErrorf(diags, "setting SES Identity Notification Topic (%s): %s", id, err)
8986
}
9087

88+
if d.IsNewResource() {
89+
d.SetId(id)
90+
}
91+
9192
inputSIHINE := &ses.SetIdentityHeadersInNotificationsEnabledInput{
9293
Enabled: d.Get("include_original_headers").(bool),
9394
Identity: aws.String(identity),
@@ -157,11 +158,15 @@ func resourceIdentityNotificationTopicDelete(ctx context.Context, d *schema.Reso
157158
NotificationType: notificationType,
158159
})
159160

161+
if tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "Must be a verified email address or domain") {
162+
return diags
163+
}
164+
160165
if err != nil {
161166
return sdkdiag.AppendErrorf(diags, "deleting SES Identity Notification Topic (%s): %s", d.Id(), err)
162167
}
163168

164-
return append(diags, resourceIdentityNotificationTopicRead(ctx, d, meta)...)
169+
return diags
165170
}
166171

167172
const identityNotificationTopicResourceIDSeparator = "|"

internal/service/ses/identity_notification_topic_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@ func TestAccSESIdentityNotificationTopic_basic(t *testing.T) {
5959
})
6060
}
6161

62+
// https://github.com/hashicorp/terraform-provider-aws/issues/36275.
63+
func TestAccSESIdentityNotificationTopic_Disappears_domainIdentity(t *testing.T) {
64+
ctx := acctest.Context(t)
65+
domain := acctest.RandomDomainName()
66+
resourceName := "aws_ses_identity_notification_topic.test"
67+
68+
resource.ParallelTest(t, resource.TestCase{
69+
PreCheck: func() {
70+
acctest.PreCheck(ctx, t)
71+
testAccPreCheck(ctx, t)
72+
},
73+
ErrorCheck: acctest.ErrorCheck(t, names.SESServiceID),
74+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
75+
CheckDestroy: acctest.CheckDestroyNoop,
76+
Steps: []resource.TestStep{
77+
{
78+
Config: testAccIdentityNotificationTopicConfig_basic(domain),
79+
Check: resource.ComposeTestCheckFunc(
80+
testAccCheckIdentityNotificationTopicExists(ctx, resourceName),
81+
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfses.ResourceDomainIdentity(), "aws_ses_domain_identity.test"),
82+
),
83+
ExpectNonEmptyPlan: true,
84+
},
85+
},
86+
})
87+
}
88+
6289
func testAccCheckIdentityNotificationTopicExists(ctx context.Context, n string) resource.TestCheckFunc {
6390
return func(s *terraform.State) error {
6491
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)