From 08d958fac77a9742bcc5f5d51515a7e3db09fb96 Mon Sep 17 00:00:00 2001 From: "J. Kerry Martin" Date: Sat, 26 Jan 2019 15:56:31 -0700 Subject: [PATCH 1/4] Add support for resource_aws_ses_identity_notification_topic import --- ...rce_aws_ses_identity_notification_topic.go | 13 ++++++++++ ...ws_ses_identity_notification_topic_test.go | 24 +++++++++++++++++++ .../ses_identity_notification_topic.markdown | 18 ++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/aws/resource_aws_ses_identity_notification_topic.go b/aws/resource_aws_ses_identity_notification_topic.go index 00adb0644e0..6aacbee3ed5 100644 --- a/aws/resource_aws_ses_identity_notification_topic.go +++ b/aws/resource_aws_ses_identity_notification_topic.go @@ -17,6 +17,9 @@ func resourceAwsSesNotificationTopic() *schema.Resource { Read: resourceAwsSesNotificationTopicRead, Update: resourceAwsSesNotificationTopicSet, Delete: resourceAwsSesNotificationTopicDelete, + Importer: &schema.ResourceImporter{ + State: resourceAwsSesNotificationImport, + }, Schema: map[string]*schema.Schema{ "topic_arn": { @@ -136,6 +139,16 @@ func resourceAwsSesNotificationTopicDelete(d *schema.ResourceData, meta interfac return resourceAwsSesNotificationTopicRead(d, meta) } +func resourceAwsSesNotificationImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + identity, notificationType, err := decodeSesIdentityNotificationTopicId(d.Id()) + if err != nil { + return nil, err + } + d.Set("identity", identity) + d.Set("notification_type", notificationType) + return []*schema.ResourceData{d}, nil +} + func decodeSesIdentityNotificationTopicId(id string) (string, string, error) { parts := strings.Split(id, "|") if len(parts) != 2 { diff --git a/aws/resource_aws_ses_identity_notification_topic_test.go b/aws/resource_aws_ses_identity_notification_topic_test.go index 8eafd947cbc..20bbde1df63 100644 --- a/aws/resource_aws_ses_identity_notification_topic_test.go +++ b/aws/resource_aws_ses_identity_notification_topic_test.go @@ -41,6 +41,30 @@ func TestAccAwsSESIdentityNotificationTopic_basic(t *testing.T) { }) } +func TestAccAwsSESIdentityNotification_importBasic(t *testing.T) { + resourceName := "aws_ses_identity_notification_topic.test" + domain := fmt.Sprintf( + "%s.terraformtesting.com", + acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + topicName := fmt.Sprintf("test-topic-%d", acctest.RandInt()) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsSESIdentityNotificationTopicDestroy, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(testAccAwsSESIdentityNotificationTopicConfig_update, domain, topicName), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAwsSESIdentityNotificationTopicDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).sesConn diff --git a/website/docs/r/ses_identity_notification_topic.markdown b/website/docs/r/ses_identity_notification_topic.markdown index 45d3cf3e34a..364a9283b05 100644 --- a/website/docs/r/ses_identity_notification_topic.markdown +++ b/website/docs/r/ses_identity_notification_topic.markdown @@ -27,3 +27,21 @@ The following arguments are supported: * `topic_arn` - (Optional) The Amazon Resource Name (ARN) of the Amazon SNS topic. Can be set to "" (an empty string) to disable publishing. * `notification_type` - (Required) The type of notifications that will be published to the specified Amazon SNS topic. Valid Values: *Bounce*, *Complaint* or *Delivery*. * `identity` - (Required) The identity for which the Amazon SNS topic will be set. You can specify an identity by using its name or by using its Amazon Resource Name (ARN). + +## Import + +Identity Notification Topics can be imported using ID of the record. The ID is made up as IDENTITY|TYPE where IDENTITY is the SES Identity and TYPE is the Notification Type. + +e.g. + +``` +example.com|Bounce +``` + +In this example, `example.com` is the SES Identity and `Bounce` is the Notification Type. + +To import the ID above, it would look as follows: + +``` +$ import aws_ses_identity_notification_topic.test example.com|Bounce +``` From b369110857c414ca255092d77999e1507691def3 Mon Sep 17 00:00:00 2001 From: "J. Kerry Martin" Date: Wed, 6 Feb 2019 22:47:31 -0700 Subject: [PATCH 2/4] Use state passthrough for ses identity import --- ...esource_aws_ses_identity_notification_topic.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/aws/resource_aws_ses_identity_notification_topic.go b/aws/resource_aws_ses_identity_notification_topic.go index 6aacbee3ed5..7557aad8a81 100644 --- a/aws/resource_aws_ses_identity_notification_topic.go +++ b/aws/resource_aws_ses_identity_notification_topic.go @@ -18,7 +18,7 @@ func resourceAwsSesNotificationTopic() *schema.Resource { Update: resourceAwsSesNotificationTopicSet, Delete: resourceAwsSesNotificationTopicDelete, Importer: &schema.ResourceImporter{ - State: resourceAwsSesNotificationImport, + State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ @@ -82,6 +82,9 @@ func resourceAwsSesNotificationTopicRead(d *schema.ResourceData, meta interface{ return err } + d.Set("identity", identity) + d.Set("notification_type", notificationType) + getOpts := &ses.GetIdentityNotificationAttributesInput{ Identities: []*string{aws.String(identity)}, } @@ -139,16 +142,6 @@ func resourceAwsSesNotificationTopicDelete(d *schema.ResourceData, meta interfac return resourceAwsSesNotificationTopicRead(d, meta) } -func resourceAwsSesNotificationImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - identity, notificationType, err := decodeSesIdentityNotificationTopicId(d.Id()) - if err != nil { - return nil, err - } - d.Set("identity", identity) - d.Set("notification_type", notificationType) - return []*schema.ResourceData{d}, nil -} - func decodeSesIdentityNotificationTopicId(id string) (string, string, error) { parts := strings.Split(id, "|") if len(parts) != 2 { From 828d9b00fc79edf285f06303bec3adbb0e87ade7 Mon Sep 17 00:00:00 2001 From: "J. Kerry Martin" Date: Wed, 6 Feb 2019 22:48:07 -0700 Subject: [PATCH 3/4] Add step for ses identity topic import in existing acceptance test --- ...ws_ses_identity_notification_topic_test.go | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/aws/resource_aws_ses_identity_notification_topic_test.go b/aws/resource_aws_ses_identity_notification_topic_test.go index 20bbde1df63..58c8db55546 100644 --- a/aws/resource_aws_ses_identity_notification_topic_test.go +++ b/aws/resource_aws_ses_identity_notification_topic_test.go @@ -17,6 +17,7 @@ func TestAccAwsSESIdentityNotificationTopic_basic(t *testing.T) { "%s.terraformtesting.com", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) topicName := fmt.Sprintf("test-topic-%d", acctest.RandInt()) + resourceName := "aws_ses_identity_notification_topic.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -28,34 +29,15 @@ func TestAccAwsSESIdentityNotificationTopic_basic(t *testing.T) { { Config: fmt.Sprintf(testAccAwsSESIdentityNotificationTopicConfig_basic, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESIdentityNotificationTopicExists("aws_ses_identity_notification_topic.test"), + testAccCheckAwsSESIdentityNotificationTopicExists(resourceName), ), }, { Config: fmt.Sprintf(testAccAwsSESIdentityNotificationTopicConfig_update, domain, topicName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESIdentityNotificationTopicExists("aws_ses_identity_notification_topic.test"), + testAccCheckAwsSESIdentityNotificationTopicExists(resourceName), ), }, - }, - }) -} - -func TestAccAwsSESIdentityNotification_importBasic(t *testing.T) { - resourceName := "aws_ses_identity_notification_topic.test" - domain := fmt.Sprintf( - "%s.terraformtesting.com", - acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) - topicName := fmt.Sprintf("test-topic-%d", acctest.RandInt()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAwsSESIdentityNotificationTopicDestroy, - Steps: []resource.TestStep{ - { - Config: fmt.Sprintf(testAccAwsSESIdentityNotificationTopicConfig_update, domain, topicName), - }, { ResourceName: resourceName, ImportState: true, From f2e21cf01cee872b719c789cece94f4d7f6c1e8a Mon Sep 17 00:00:00 2001 From: "J. Kerry Martin" Date: Wed, 6 Feb 2019 22:48:35 -0700 Subject: [PATCH 4/4] Fix docs in ses identity notification topic import --- website/docs/r/ses_identity_notification_topic.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/ses_identity_notification_topic.markdown b/website/docs/r/ses_identity_notification_topic.markdown index 364a9283b05..512e826513b 100644 --- a/website/docs/r/ses_identity_notification_topic.markdown +++ b/website/docs/r/ses_identity_notification_topic.markdown @@ -43,5 +43,5 @@ In this example, `example.com` is the SES Identity and `Bounce` is the Notificat To import the ID above, it would look as follows: ``` -$ import aws_ses_identity_notification_topic.test example.com|Bounce +$ terraform import aws_ses_identity_notification_topic.test 'example.com|Bounce' ```