Skip to content

Commit

Permalink
resource/aws_ses_active_receipt_rule_set: Add arn attribute (#13962)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
DrFaust92 authored Feb 11, 2021
1 parent 271a71f commit dce8bef
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changelog/13962.txt
Original file line number Diff line number Diff line change
@@ -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
```
27 changes: 22 additions & 5 deletions aws/resource_aws_ses_active_receipt_rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
},
},
}
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion aws/resource_aws_ses_active_receipt_rule_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
),
},
},
Expand Down Expand Up @@ -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" {
Expand Down
5 changes: 3 additions & 2 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/ses_active_receipt_rule_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit dce8bef

Please sign in to comment.