diff --git a/.changelog/13964.txt b/.changelog/13964.txt new file mode 100644 index 00000000000..84c79e3f464 --- /dev/null +++ b/.changelog/13964.txt @@ -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 +``` diff --git a/aws/resource_aws_ses_event_destination.go b/aws/resource_aws_ses_event_destination.go index 619d6089c8a..b364be19659 100644 --- a/aws/resource_aws_ses_event_destination.go +++ b/aws/resource_aws_ses_event_destination.go @@ -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" @@ -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": { @@ -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": { @@ -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, }, }, }, @@ -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, }, }, }, @@ -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 } diff --git a/aws/resource_aws_ses_event_destination_test.go b/aws/resource_aws_ses_event_destination_test.go index b7a48af6053..0890dcc23bd 100644 --- a/aws/resource_aws_ses_event_destination_test.go +++ b/aws/resource_aws_ses_event_destination_test.go @@ -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" @@ -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), @@ -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" @@ -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 } } diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 8266d49b471..9dac41fba13 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -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) diff --git a/website/docs/r/ses_event_destination.markdown b/website/docs/r/ses_event_destination.html.markdown similarity index 93% rename from website/docs/r/ses_event_destination.markdown rename to website/docs/r/ses_event_destination.html.markdown index ef701579f94..82c5f76d52e 100644 --- a/website/docs/r/ses_event_destination.markdown +++ b/website/docs/r/ses_event_destination.html.markdown @@ -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`,