From 80355f03a85e13d26ea97e2145d937019d40cf8e Mon Sep 17 00:00:00 2001 From: benflowers Date: Thu, 22 Jun 2017 11:31:42 +0100 Subject: [PATCH 1/3] adds ses identity notification resource --- aws/resource_aws_ses_identity_notification.go | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 aws/resource_aws_ses_identity_notification.go diff --git a/aws/resource_aws_ses_identity_notification.go b/aws/resource_aws_ses_identity_notification.go new file mode 100644 index 00000000000..159945f697b --- /dev/null +++ b/aws/resource_aws_ses_identity_notification.go @@ -0,0 +1,97 @@ +package aws + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/service/ses" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceAwsSesNotification() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsSesNotificationSet, + Read: resourceAwsSesNotificationRead, + Update: resourceAwsSesNotificationSet, + Delete: resourceAwsSesNotificationDelete, + + Schema: map[string]*schema.Schema{ + "topic_arn": &schema.Schema{ + Type: schema.TypeString, + Required: false, + }, + + "notification_type": &schema.Schema{ + Type: schema.TypeSet, + Required: true, + }, + + "identity": &schema.Schema{ + Type: schema.TypeSet, + Required: true, + }, + }, + } +} + +func resourceAwsSesNotificationSet(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).sesConn + topic := d.Get("topic_arn").(string) + notification := d.Get("notification_type").(string) + identity := d.Get("identity").(string) + + setOpts := &ses.SetIdentityNotificationTopicInput{ + Identity: identity, + NotificationType: notification, + SnsTopic: topic, + } + + _, err := conn.SetIdentityNotificationTopicRequest(setOpts).Send() + + if err != nil { + return fmt.Errorf("Error setting SES Identity Notification: %s", err) + } + + return resourceAwsSesNotificationRead(d, meta) +} + +func resourceAwsSesNotificationRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).sesConn + notification := d.Get("notification_type").(*schema.Set) + identity := d.Get("identity").(*schema.Set) + + getOpts := &ses.GetIdentityNotificationAttributesInput{ + Identities: []string{identity}, + } + + response, err := conn.GetIdentityNotificationAttributes(getOpts) + + if err != nil { + return fmt.Errorf("Error reading SES Identity Notification: %s", err) + } + + identityAttributes = response.NotificationAttributes[identity] + switch notification { + case "Bounce": + if err := d.set("topic", identityAttributes.BounceTopic); err != nil { + return err + } + case "Complain": + if err := d.set("topic", identityAttributes.ComplaintTopic); err != nil { + return err + } + case "Delivery": + if err := d.set("topic", identityAttributes.DeliveryTopic); err != nil { + return err + } + } + + return nil +} + +func resourceAwsSesNotificationDelete(d *schema.ResourceData, meta interface{}) error { + d.Set("topic_arn", nil) + return resourceAwsSesNotificationSet(d, meta) +} From 4fce0b625f3ee7f5b5b8f1dfa2e77d943109e61d Mon Sep 17 00:00:00 2001 From: benflowers Date: Thu, 22 Jun 2017 11:58:37 +0100 Subject: [PATCH 2/3] fix compile issues --- aws/resource_aws_ses_identity_notification.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_ses_identity_notification.go b/aws/resource_aws_ses_identity_notification.go index 159945f697b..353dae9ab32 100644 --- a/aws/resource_aws_ses_identity_notification.go +++ b/aws/resource_aws_ses_identity_notification.go @@ -2,10 +2,8 @@ package aws import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ses" "github.com/hashicorp/terraform/helper/schema" ) @@ -43,9 +41,9 @@ func resourceAwsSesNotificationSet(d *schema.ResourceData, meta interface{}) err identity := d.Get("identity").(string) setOpts := &ses.SetIdentityNotificationTopicInput{ - Identity: identity, - NotificationType: notification, - SnsTopic: topic, + Identity: aws.String(identity), + NotificationType: aws.String(notification), + SnsTopic: aws.String(topic), } _, err := conn.SetIdentityNotificationTopicRequest(setOpts).Send() @@ -63,7 +61,7 @@ func resourceAwsSesNotificationRead(d *schema.ResourceData, meta interface{}) er identity := d.Get("identity").(*schema.Set) getOpts := &ses.GetIdentityNotificationAttributesInput{ - Identities: []string{identity}, + Identities: []*string{ aws.String(identity) }, } response, err := conn.GetIdentityNotificationAttributes(getOpts) @@ -72,18 +70,18 @@ func resourceAwsSesNotificationRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error reading SES Identity Notification: %s", err) } - identityAttributes = response.NotificationAttributes[identity] + notificationAttributes := response.NotificationAttributes[identity] switch notification { case "Bounce": - if err := d.set("topic", identityAttributes.BounceTopic); err != nil { + if err := d.Set("topic", notificationAttributes.BounceTopic); err != nil { return err } case "Complain": - if err := d.set("topic", identityAttributes.ComplaintTopic); err != nil { + if err := d.Set("topic", notificationAttributes.ComplaintTopic); err != nil { return err } case "Delivery": - if err := d.set("topic", identityAttributes.DeliveryTopic); err != nil { + if err := d.Set("topic", notificationAttributes.DeliveryTopic); err != nil { return err } } From 7e4b3a444339fd55ac4c6625983df6afb3662205 Mon Sep 17 00:00:00 2001 From: benflowers Date: Thu, 22 Jun 2017 15:55:04 +0100 Subject: [PATCH 3/3] format code --- aws/resource_aws_ses_identity_notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_ses_identity_notification.go b/aws/resource_aws_ses_identity_notification.go index 353dae9ab32..c5cc7386ffe 100644 --- a/aws/resource_aws_ses_identity_notification.go +++ b/aws/resource_aws_ses_identity_notification.go @@ -61,7 +61,7 @@ func resourceAwsSesNotificationRead(d *schema.ResourceData, meta interface{}) er identity := d.Get("identity").(*schema.Set) getOpts := &ses.GetIdentityNotificationAttributesInput{ - Identities: []*string{ aws.String(identity) }, + Identities: []*string{aws.String(identity)}, } response, err := conn.GetIdentityNotificationAttributes(getOpts)