Skip to content

Commit

Permalink
resource/aws_ses_event_destination: Add support for SNS destinations
Browse files Browse the repository at this point in the history
Fixes: #1697

```
terraform-provider-aws [master●] % acctests aws TestAccAWSSESEventDestination_basic
=== RUN   TestAccAWSSESEventDestination_basic
--- PASS: TestAccAWSSESEventDestination_basic (159.86s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	159.898s
```
  • Loading branch information
stack72 committed Sep 23, 2017
1 parent 42f52ad commit ecdc749
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
53 changes: 39 additions & 14 deletions aws/resource_aws_ses_event_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ func resourceAwsSesEventDestination() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"configuration_set_name": &schema.Schema{
"configuration_set_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"enabled": &schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"matching_types": &schema.Schema{
"matching_types": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Expand All @@ -53,20 +53,21 @@ func resourceAwsSesEventDestination() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"kinesis_destination"},
MaxItems: 1,
ConflictsWith: []string{"kinesis_destination", "sns_destination"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_value": &schema.Schema{
"default_value": {
Type: schema.TypeString,
Required: true,
},

"dimension_name": &schema.Schema{
"dimension_name": {
Type: schema.TypeString,
Required: true,
},

"value_source": &schema.Schema{
"value_source": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateDimensionValueSource,
Expand All @@ -79,15 +80,32 @@ func resourceAwsSesEventDestination() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"cloudwatch_destination"},
MaxItems: 1,
ConflictsWith: []string{"cloudwatch_destination", "sns_destination"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"stream_arn": &schema.Schema{
"stream_arn": {
Type: schema.TypeString,
Required: true,
},

"role_arn": &schema.Schema{
"role_arn": {
Type: schema.TypeString,
Required: true,
},
},
},
},

"sns_destination": {
Type: schema.TypeSet,
MaxItems: 1,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"cloudwatch_destination", "kinesis_destination"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"topic_arn": {
Type: schema.TypeString,
Required: true,
},
Expand Down Expand Up @@ -125,9 +143,7 @@ func resourceAwsSesEventDestinationCreate(d *schema.ResourceData, meta interface

if v, ok := d.GetOk("kinesis_destination"); ok {
destination := v.(*schema.Set).List()
if len(destination) > 1 {
return fmt.Errorf("You can only define a single kinesis destination per record")
}

kinesis := destination[0].(map[string]interface{})
createOpts.EventDestination.KinesisFirehoseDestination = &ses.KinesisFirehoseDestination{
DeliveryStreamARN: aws.String(kinesis["stream_arn"].(string)),
Expand All @@ -136,6 +152,15 @@ func resourceAwsSesEventDestinationCreate(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] Creating kinesis destination: %#v", kinesis)
}

if v, ok := d.GetOk("sns_destination"); ok {
destination := v.(*schema.Set).List()
sns := destination[0].(map[string]interface{})
createOpts.EventDestination.SNSDestination = &ses.SNSDestination{
TopicARN: aws.String(sns["topic_arn"].(string)),
}
log.Printf("[DEBUG] Creating sns destination: %#v", sns)
}

_, err := conn.CreateConfigurationSetEventDestination(createOpts)
if err != nil {
return fmt.Errorf("Error creating SES configuration set event destination: %s", err)
Expand Down
22 changes: 20 additions & 2 deletions aws/resource_aws_ses_event_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestAccAWSSESEventDestination_basic(t *testing.T) {
"aws_ses_event_destination.kinesis", "name", "event-destination-kinesis"),
resource.TestCheckResourceAttr(
"aws_ses_event_destination.cloudwatch", "name", "event-destination-cloudwatch"),
resource.TestCheckResourceAttr(
"aws_ses_event_destination.sns", "name", "event-destination-sns"),
),
},
},
Expand Down Expand Up @@ -156,6 +158,10 @@ data "aws_iam_policy_document" "fh_felivery_document" {
}
}
resource "aws_sns_topic" "ses_destination" {
name = "ses-destination-test"
}
resource "aws_ses_configuration_set" "test" {
name = "some-configuration-set-%d"
}
Expand All @@ -166,7 +172,7 @@ resource "aws_ses_event_destination" "kinesis" {
enabled = true,
matching_types = ["bounce", "send"],
kinesis_destination = {
kinesis_destination {
stream_arn = "${aws_kinesis_firehose_delivery_stream.test_stream.arn}",
role_arn = "${aws_iam_role.firehose_role.arn}"
}
Expand All @@ -178,10 +184,22 @@ resource "aws_ses_event_destination" "cloudwatch" {
enabled = true,
matching_types = ["bounce", "send"],
cloudwatch_destination = {
cloudwatch_destination {
default_value = "default"
dimension_name = "dimension"
value_source = "emailHeader"
}
}
resource "aws_ses_event_destination" "sns" {
name = "event-destination-sns",
configuration_set_name = "${aws_ses_configuration_set.test.name}",
enabled = true,
matching_types = ["bounce", "send"],
sns_destination {
topic_arn = "${aws_sns_topic.ses_destination.arn}"
}
}
`, edRandomInteger)
5 changes: 5 additions & 0 deletions website/docs/r/ses_event_destination.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following arguments are supported:
* `matching_types` - (Required) A list of matching types. May be any of `"send"`, `"reject"`, `"bounce"`, `"complaint"`, or `"delivery"`.
* `cloudwatch_destination` - (Optional) CloudWatch destination for the events
* `kinesis_destination` - (Optional) Send the events to a kinesis firehose destination
* `sns_destination` - (Optional) Send the events to an SNS Topic destination

~> **NOTE:** You can specify `"cloudwatch_destination"` or `"kinesis_destination"` but not both

Expand All @@ -65,3 +66,7 @@ Kinesis Destination requires the following:
* `stream_arn` - (Required) The ARN of the Kinesis Stream
* `role_arn` - (Required) The ARN of the role that has permissions to access the Kinesis Stream

SNS Topic requires the following:

* `topic_arn` - (Required) The ARN of the SNS topic

0 comments on commit ecdc749

Please sign in to comment.