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

r/ses_event_destination - add arn + validation #13964

Merged
merged 7 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .changelog/13964.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_ses_event_destination: Add `arn` attribute
```

```release-note:enhancement
resource/aws_ses_event_destination: Add plan time validation for `name`, `cloudwatch_destination.default_value`, `cloudwatch_destination.default_name`, `kinesis_destination.role_arn`, `kinesis_destination.stream_arn`, and `sns_destination.topic_arn` attributes
```
42 changes: 36 additions & 6 deletions aws/resource_aws_ses_event_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package aws
import (
"fmt"
"log"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -21,10 +23,18 @@ func resourceAwsSesEventDestination() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 64),
validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z_-]+$`), "must contain only alphanumeric, underscore, and hyphen characters"),
),
},

"configuration_set_name": {
Expand Down Expand Up @@ -70,11 +80,19 @@ func resourceAwsSesEventDestination() *schema.Resource {
"default_value": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z_-]+$`), "must contain only alphanumeric, underscore, and hyphen characters"),
),
},

"dimension_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z_:-]+$`), "must contain only alphanumeric, underscore, and hyphen characters"),
),
},

"value_source": {
Expand All @@ -99,13 +117,15 @@ func resourceAwsSesEventDestination() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"stream_arn": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},

"role_arn": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
},
},
Expand All @@ -120,8 +140,9 @@ func resourceAwsSesEventDestination() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"topic_arn": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
},
},
Expand Down Expand Up @@ -234,6 +255,15 @@ func resourceAwsSesEventDestinationRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error setting sns_destination: %w", err)
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ses",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("configuration-set/%s:event-destination/%s", configurationSetName, d.Id()),
}.String()
d.Set("arn", arn)

return nil
}

Expand Down
13 changes: 8 additions & 5 deletions aws/resource_aws_ses_event_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

func TestAccAWSSESEventDestination_basic(t *testing.T) {
rName1 := acctest.RandomWithPrefix("tf-acc-test")
rName2 := acctest.RandomWithPrefix("tf-acc-test")
rName3 := acctest.RandomWithPrefix("tf-acc-test")
rName2 := acctest.RandomWithPrefix("tf-acc-test-kinesis")
rName3 := acctest.RandomWithPrefix("tf-acc-test-sns")
cloudwatchDestinationResourceName := "aws_ses_event_destination.cloudwatch"
kinesisDestinationResourceName := "aws_ses_event_destination.kinesis"
snsDestinationResourceName := "aws_ses_event_destination.sns"
Expand All @@ -34,6 +34,9 @@ func TestAccAWSSESEventDestination_basic(t *testing.T) {
testAccCheckAwsSESEventDestinationExists(cloudwatchDestinationResourceName, &v1),
testAccCheckAwsSESEventDestinationExists(kinesisDestinationResourceName, &v2),
testAccCheckAwsSESEventDestinationExists(snsDestinationResourceName, &v3),
testAccCheckResourceAttrRegionalARN(cloudwatchDestinationResourceName, "arn", "ses", fmt.Sprintf("configuration-set/%s:event-destination/%s", rName1, rName1)),
testAccCheckResourceAttrRegionalARN(kinesisDestinationResourceName, "arn", "ses", fmt.Sprintf("configuration-set/%s:event-destination/%s", rName1, rName2)),
testAccCheckResourceAttrRegionalARN(snsDestinationResourceName, "arn", "ses", fmt.Sprintf("configuration-set/%s:event-destination/%s", rName1, rName3)),
resource.TestCheckResourceAttr(cloudwatchDestinationResourceName, "name", rName1),
resource.TestCheckResourceAttr(kinesisDestinationResourceName, "name", rName2),
resource.TestCheckResourceAttr(snsDestinationResourceName, "name", rName3),
Expand Down Expand Up @@ -63,8 +66,8 @@ func TestAccAWSSESEventDestination_basic(t *testing.T) {

func TestAccAWSSESEventDestination_disappears(t *testing.T) {
rName1 := acctest.RandomWithPrefix("tf-acc-test")
rName2 := acctest.RandomWithPrefix("tf-acc-test")
rName3 := acctest.RandomWithPrefix("tf-acc-test")
rName2 := acctest.RandomWithPrefix("tf-acc-test-kinesis")
rName3 := acctest.RandomWithPrefix("tf-acc-test-sns")
cloudwatchDestinationResourceName := "aws_ses_event_destination.cloudwatch"
kinesisDestinationResourceName := "aws_ses_event_destination.kinesis"
snsDestinationResourceName := "aws_ses_event_destination.sns"
Expand Down Expand Up @@ -109,7 +112,7 @@ func testAccCheckSESEventDestinationDestroy(s *terraform.State) error {

found := false
for _, element := range response.ConfigurationSets {
if *element.Name == rs.Primary.ID {
if aws.StringValue(element.Name) == rs.Primary.ID {
found = true
}
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_ses_domain_identity` resource](/docs/providers/aws/r/ses_domain_identity.html)
- [`aws_ses_domain_identity_verification` resource](/docs/providers/aws/r/ses_domain_identity_verification.html)
- [`aws_ses_email_identity` resource](/docs/providers/aws/r/ses_email_identity.html)
- [`aws_ses_event_destination` resource](/docs/providers/aws/r/ses_event_destination.html)
- [`aws_ses_receipt_filter` resource](/docs/providers/aws/r/ses_receipt_filter.html)
- [`aws_ssm_document` data source](/docs/providers/aws/d/ssm_document.html)
- [`aws_ssm_document` resource](/docs/providers/aws/r/ssm_document.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ The following arguments are supported:

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

## Attributes Reference

In addition to the arguments, which are exported, the following attributes are exported:

* `id` - The SES event destination name.
* `arn` - The SES event destination ARN.

## Import

SES event destinations can be imported using `configuration_set_name` together with the event destination's `name`,
Expand Down