From dce8bef122845653abbffd6f82f14e7c539b3f96 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Thu, 11 Feb 2021 19:50:17 +0200 Subject: [PATCH] resource/aws_ses_active_receipt_rule_set: Add arn attribute (#13962) References: - https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonses.html#amazonses-resources-for-iam-policies - https://docs.aws.amazon.com/ses/latest/APIReference/API_ReceiptRuleSetMetadata.html (no arn or owner id fields) Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSSESActiveReceiptRuleSet_serial (24.89s) --- PASS: TestAccAWSSESActiveReceiptRuleSet_serial/basic (13.02s) --- PASS: TestAccAWSSESActiveReceiptRuleSet_serial/disappears (11.87s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- PASS: TestAccAWSSESActiveReceiptRuleSet_serial (3.74s) --- SKIP: TestAccAWSSESActiveReceiptRuleSet_serial/basic (1.95s) --- SKIP: TestAccAWSSESActiveReceiptRuleSet_serial/disappears (1.79s) ``` --- .changelog/13962.txt | 7 +++++ ...esource_aws_ses_active_receipt_rule_set.go | 27 +++++++++++++++---- ...ce_aws_ses_active_receipt_rule_set_test.go | 3 ++- website/docs/index.html.markdown | 5 ++-- .../ses_active_receipt_rule_set.html.markdown | 7 +++++ 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .changelog/13962.txt diff --git a/.changelog/13962.txt b/.changelog/13962.txt new file mode 100644 index 00000000000..ce98a3fd700 --- /dev/null +++ b/.changelog/13962.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_ses_active_receipt_rule_set: Add `arn` attribute +``` + +```release-note:enhancement +resource/aws_ses_active_receipt_rule_set: Add plan time validation for `rule_set_name` argument +``` diff --git a/aws/resource_aws_ses_active_receipt_rule_set.go b/aws/resource_aws_ses_active_receipt_rule_set.go index ccdd8ff2743..b506278ee56 100644 --- a/aws/resource_aws_ses_active_receipt_rule_set.go +++ b/aws/resource_aws_ses_active_receipt_rule_set.go @@ -5,8 +5,10 @@ import ( "log" "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" ) func resourceAwsSesActiveReceiptRuleSet() *schema.Resource { @@ -17,9 +19,14 @@ func resourceAwsSesActiveReceiptRuleSet() *schema.Resource { Delete: resourceAwsSesActiveReceiptRuleSetDelete, Schema: map[string]*schema.Schema{ - "rule_set_name": { + "arn": { Type: schema.TypeString, - Required: true, + Computed: true, + }, + "rule_set_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 64), }, }, } @@ -59,13 +66,23 @@ func resourceAwsSesActiveReceiptRuleSetRead(d *schema.ResourceData, meta interfa return err } - if response.Metadata != nil { - d.Set("rule_set_name", response.Metadata.Name) - } else { + if response.Metadata == nil { log.Print("[WARN] No active Receipt Rule Set found") d.SetId("") + return nil } + d.Set("rule_set_name", response.Metadata.Name) + + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "ses", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("receipt-rule-set/%s", d.Id()), + }.String() + d.Set("arn", arn) + return nil } diff --git a/aws/resource_aws_ses_active_receipt_rule_set_test.go b/aws/resource_aws_ses_active_receipt_rule_set_test.go index 3b2c9d239ff..3bc025bf64c 100644 --- a/aws/resource_aws_ses_active_receipt_rule_set_test.go +++ b/aws/resource_aws_ses_active_receipt_rule_set_test.go @@ -45,6 +45,7 @@ func testAccAWSSESActiveReceiptRuleSet_basic(t *testing.T) { Config: testAccAWSSESActiveReceiptRuleSetConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsSESActiveReceiptRuleSetExists(resourceName), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "ses", fmt.Sprintf("receipt-rule-set/%s", rName)), ), }, }, @@ -128,7 +129,7 @@ func testAccCheckAwsSESActiveReceiptRuleSetExists(n string) resource.TestCheckFu func testAccAWSSESActiveReceiptRuleSetConfig(name string) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { - rule_set_name = "%s" + rule_set_name = %[1]q } resource "aws_ses_active_receipt_rule_set" "test" { diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 0d0039d87f8..de3ede981d2 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -315,12 +315,13 @@ for more information about connecting to alternate AWS endpoints or AWS compatib - [`aws_redshift_snapshot_schedule` resource](/docs/providers/aws/r/redshift_snapshot_schedule.html) - [`aws_redshift_subnet_group` resource](/docs/providers/aws/r/redshift_subnet_group.html) - [`aws_s3_account_public_access_block` resource](/docs/providers/aws/r/s3_account_public_access_block.html) + - [`aws_ses_active_receipt_rule_set` resource](/docs/providers/aws/r/ses_active_receipt_rule_set.html) - [`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_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_ses_template` resource](/docs/providers/aws/r/ses_template.html) + - [`aws_ses_template` resource](/docs/providers/aws/r/ses_template.html) - [`aws_ssm_document` data source](/docs/providers/aws/d/ssm_document.html) - [`aws_ssm_document` resource](/docs/providers/aws/r/ssm_document.html) - [`aws_ssm_parameter` data source](/docs/providers/aws/d/ssm_parameter.html) diff --git a/website/docs/r/ses_active_receipt_rule_set.html.markdown b/website/docs/r/ses_active_receipt_rule_set.html.markdown index 25db2e57033..23fb50b536c 100644 --- a/website/docs/r/ses_active_receipt_rule_set.html.markdown +++ b/website/docs/r/ses_active_receipt_rule_set.html.markdown @@ -23,3 +23,10 @@ resource "aws_ses_active_receipt_rule_set" "main" { The following arguments are supported: * `rule_set_name` - (Required) The name of the rule set + +## Attributes Reference + +In addition to the arguments, which are exported, the following attributes are exported: + +* `id` - The SES receipt rule set name. +* `arn` - The SES receipt rule set ARN.