Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_ses_event_destination: Add support for SNS destinations #1737

Merged
merged 2 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly enough, this resource actually did appear to support multiple cloudwatch_destination previously, even if it wasn't appropriately acceptance tested. This change will likely be reverted in #6690

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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick - but do you mind adding check for sns_destination.0.topic_arn as that is the field being added and that's the one that should also be tested?

),
},
},
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind randomizing this name here?

}

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise ^ do you mind randomizing it?

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