From 02e212344069bad8675de2b10ebe038dfdd2c43b Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 26 Jun 2020 22:58:41 +0300 Subject: [PATCH 01/10] add arn support test refactor docs validations --- aws/resource_aws_ses_receipt_rule.go | 131 ++++++++++++------ aws/resource_aws_ses_receipt_rule_test.go | 120 ++++++++-------- website/docs/r/ses_receipt_rule.html.markdown | 7 + 3 files changed, 162 insertions(+), 96 deletions(-) diff --git a/aws/resource_aws_ses_receipt_rule.go b/aws/resource_aws_ses_receipt_rule.go index 653c403699f..358eee4f780 100644 --- a/aws/resource_aws_ses_receipt_rule.go +++ b/aws/resource_aws_ses_receipt_rule.go @@ -4,10 +4,12 @@ import ( "bytes" "fmt" "log" + "regexp" "sort" "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" @@ -25,10 +27,20 @@ func resourceAwsSesReceiptRule() *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"), + validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z]`), "must begin with a alphanumeric character"), + validation.StringMatch(regexp.MustCompile(`[0-9a-zA-Z]$`), "must end with a alphanumeric character"), + ), }, "rule_set_name": { @@ -52,7 +64,6 @@ func resourceAwsSesReceiptRule() *schema.Resource { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, - Set: schema.HashString, }, "scan_enabled": { @@ -65,6 +76,10 @@ func resourceAwsSesReceiptRule() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + ses.TlsPolicyOptional, + ses.TlsPolicyRequire, + }, false), }, "add_header_action": { @@ -75,11 +90,16 @@ func resourceAwsSesReceiptRule() *schema.Resource { "header_name": { Type: schema.TypeString, Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 50), + validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z-]+$`), "must contain only alphanumeric and dash characters"), + ), }, "header_value": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(0, 2048), }, "position": { @@ -125,8 +145,9 @@ func resourceAwsSesReceiptRule() *schema.Resource { }, "topic_arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "position": { @@ -162,19 +183,25 @@ func resourceAwsSesReceiptRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "function_arn": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, }, "invocation_type": { Type: schema.TypeString, Optional: true, Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + ses.InvocationTypeEvent, + ses.InvocationTypeRequestResponse, + }, false), }, "topic_arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "position": { @@ -224,8 +251,9 @@ func resourceAwsSesReceiptRule() *schema.Resource { }, "topic_arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "position": { @@ -264,8 +292,9 @@ func resourceAwsSesReceiptRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "topic_arn": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, }, "position": { @@ -292,11 +321,15 @@ func resourceAwsSesReceiptRule() *schema.Resource { "scope": { Type: schema.TypeString, Required: true, + ValidateFunc: validation.StringInSlice([]string{ + ses.StopScopeRuleSet, + }, false), }, "topic_arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "position": { @@ -326,13 +359,15 @@ func resourceAwsSesReceiptRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "organization_arn": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, }, "topic_arn": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "position": { @@ -429,9 +464,10 @@ func resourceAwsSesReceiptRuleUpdate(d *schema.ResourceData, meta interface{}) e func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).sesconn + ruleSetName := d.Get("rule_set_name").(string) describeOpts := &ses.DescribeReceiptRuleInput{ RuleName: aws.String(d.Id()), - RuleSetName: aws.String(d.Get("rule_set_name").(string)), + RuleSetName: aws.String(ruleSetName), } response, err := conn.DescribeReceiptRule(describeOpts) @@ -450,7 +486,7 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err } d.Set("enabled", response.Rule.Enabled) - d.Set("recipients", flattenStringList(response.Rule.Recipients)) + d.Set("recipients", flattenStringSet(response.Rule.Recipients)) d.Set("scan_enabled", response.Rule.ScanEnabled) d.Set("tls_policy", response.Rule.TlsPolicy) @@ -465,8 +501,8 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err for i, element := range response.Rule.Actions { if element.AddHeaderAction != nil { addHeaderAction := map[string]interface{}{ - "header_name": *element.AddHeaderAction.HeaderName, - "header_value": *element.AddHeaderAction.HeaderValue, + "header_name": aws.StringValue(element.AddHeaderAction.HeaderName), + "header_value": aws.StringValue(element.AddHeaderAction.HeaderValue), "position": i + 1, } addHeaderActionList = append(addHeaderActionList, addHeaderAction) @@ -474,18 +510,18 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.BounceAction != nil { bounceAction := map[string]interface{}{ - "message": *element.BounceAction.Message, - "sender": *element.BounceAction.Sender, - "smtp_reply_code": *element.BounceAction.SmtpReplyCode, + "message": aws.StringValue(element.BounceAction.Message), + "sender": aws.StringValue(element.BounceAction.Sender), + "smtp_reply_code": aws.StringValue(element.BounceAction.SmtpReplyCode), "position": i + 1, } if element.BounceAction.StatusCode != nil { - bounceAction["status_code"] = *element.BounceAction.StatusCode + bounceAction["status_code"] = aws.StringValue(element.BounceAction.StatusCode) } if element.BounceAction.TopicArn != nil { - bounceAction["topic_arn"] = *element.BounceAction.TopicArn + bounceAction["topic_arn"] = aws.StringValue(element.BounceAction.TopicArn) } bounceActionList = append(bounceActionList, bounceAction) @@ -493,16 +529,16 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.LambdaAction != nil { lambdaAction := map[string]interface{}{ - "function_arn": *element.LambdaAction.FunctionArn, + "function_arn": aws.StringValue(element.LambdaAction.FunctionArn), "position": i + 1, } if element.LambdaAction.InvocationType != nil { - lambdaAction["invocation_type"] = *element.LambdaAction.InvocationType + lambdaAction["invocation_type"] = aws.StringValue(element.LambdaAction.InvocationType) } if element.LambdaAction.TopicArn != nil { - lambdaAction["topic_arn"] = *element.LambdaAction.TopicArn + lambdaAction["topic_arn"] = aws.StringValue(element.LambdaAction.TopicArn) } lambdaActionList = append(lambdaActionList, lambdaAction) @@ -510,20 +546,20 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.S3Action != nil { s3Action := map[string]interface{}{ - "bucket_name": *element.S3Action.BucketName, + "bucket_name": aws.StringValue(element.S3Action.BucketName), "position": i + 1, } if element.S3Action.KmsKeyArn != nil { - s3Action["kms_key_arn"] = *element.S3Action.KmsKeyArn + s3Action["kms_key_arn"] = aws.StringValue(element.S3Action.KmsKeyArn) } if element.S3Action.ObjectKeyPrefix != nil { - s3Action["object_key_prefix"] = *element.S3Action.ObjectKeyPrefix + s3Action["object_key_prefix"] = aws.StringValue(element.S3Action.ObjectKeyPrefix) } if element.S3Action.TopicArn != nil { - s3Action["topic_arn"] = *element.S3Action.TopicArn + s3Action["topic_arn"] = aws.StringValue(element.S3Action.TopicArn) } s3ActionList = append(s3ActionList, s3Action) @@ -531,7 +567,7 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.SNSAction != nil { snsAction := map[string]interface{}{ - "topic_arn": *element.SNSAction.TopicArn, + "topic_arn": aws.StringValue(element.SNSAction.TopicArn), "position": i + 1, } @@ -540,12 +576,12 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.StopAction != nil { stopAction := map[string]interface{}{ - "scope": *element.StopAction.Scope, + "scope": aws.StringValue(element.StopAction.Scope), "position": i + 1, } if element.StopAction.TopicArn != nil { - stopAction["topic_arn"] = *element.StopAction.TopicArn + stopAction["topic_arn"] = aws.StringValue(element.StopAction.TopicArn) } stopActionList = append(stopActionList, stopAction) @@ -553,12 +589,12 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err if element.WorkmailAction != nil { workmailAction := map[string]interface{}{ - "organization_arn": *element.WorkmailAction.OrganizationArn, + "organization_arn": aws.StringValue(element.WorkmailAction.OrganizationArn), "position": i + 1, } if element.WorkmailAction.TopicArn != nil { - workmailAction["topic_arn"] = *element.WorkmailAction.TopicArn + workmailAction["topic_arn"] = aws.StringValue(element.WorkmailAction.TopicArn) } workmailActionList = append(workmailActionList, workmailAction) @@ -597,7 +633,20 @@ func resourceAwsSesReceiptRuleRead(d *schema.ResourceData, meta interface{}) err } err = d.Set("workmail_action", workmailActionList) - return err + if err != nil { + return err + } + + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "ses", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("receipt-rule-set/%s:receipt-rule/%s", ruleSetName, d.Id()), + }.String() + d.Set("arn", arn) + + return nil } func resourceAwsSesReceiptRuleDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/aws/resource_aws_ses_receipt_rule_test.go b/aws/resource_aws_ses_receipt_rule_test.go index 25968b86788..fa4d25616ac 100644 --- a/aws/resource_aws_ses_receipt_rule_test.go +++ b/aws/resource_aws_ses_receipt_rule_test.go @@ -14,7 +14,9 @@ import ( ) func TestAccAWSSESReceiptRule_basic(t *testing.T) { - rInt := acctest.RandInt() + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_ses_receipt_rule.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -25,22 +27,25 @@ func TestAccAWSSESReceiptRule_basic(t *testing.T) { CheckDestroy: testAccCheckSESReceiptRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSESReceiptRuleBasicConfig(rInt), + Config: testAccAWSSESReceiptRuleBasicConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESReceiptRuleExists("aws_ses_receipt_rule.basic"), + testAccCheckAwsSESReceiptRuleExists(resourceName), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "ses", fmt.Sprintf("receipt-rule-set/%s:receipt-rule/%s", rName, rName)), ), }, { - ResourceName: "aws_ses_receipt_rule.basic", + ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc("aws_ses_receipt_rule.basic"), + ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc(resourceName), }, }, }) } func TestAccAWSSESReceiptRule_s3Action(t *testing.T) { - rInt := acctest.RandInt() + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_ses_receipt_rule.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -51,22 +56,24 @@ func TestAccAWSSESReceiptRule_s3Action(t *testing.T) { CheckDestroy: testAccCheckSESReceiptRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSESReceiptRuleS3ActionConfig(rInt), + Config: testAccAWSSESReceiptRuleS3ActionConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESReceiptRuleExists("aws_ses_receipt_rule.basic"), + testAccCheckAwsSESReceiptRuleExists(resourceName), ), }, { - ResourceName: "aws_ses_receipt_rule.basic", + ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc("aws_ses_receipt_rule.basic"), + ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc(resourceName), }, }, }) } func TestAccAWSSESReceiptRule_order(t *testing.T) { - rInt := acctest.RandInt() + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_ses_receipt_rule.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -77,22 +84,24 @@ func TestAccAWSSESReceiptRule_order(t *testing.T) { CheckDestroy: testAccCheckSESReceiptRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSESReceiptRuleOrderConfig(rInt), + Config: testAccAWSSESReceiptRuleOrderConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESReceiptRuleOrder("aws_ses_receipt_rule.second"), + testAccCheckAwsSESReceiptRuleOrder(resourceName), ), }, { - ResourceName: "aws_ses_receipt_rule.second", + ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc("aws_ses_receipt_rule.second"), + ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc(resourceName), }, }, }) } func TestAccAWSSESReceiptRule_actions(t *testing.T) { - rInt := acctest.RandInt() + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_ses_receipt_rule.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -103,23 +112,24 @@ func TestAccAWSSESReceiptRule_actions(t *testing.T) { CheckDestroy: testAccCheckSESReceiptRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSESReceiptRuleActionsConfig(rInt), + Config: testAccAWSSESReceiptRuleActionsConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsSESReceiptRuleActions("aws_ses_receipt_rule.actions"), + testAccCheckAwsSESReceiptRuleActions(resourceName), ), }, { - ResourceName: "aws_ses_receipt_rule.actions", + ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc("aws_ses_receipt_rule.actions"), + ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc(resourceName), }, }, }) } func TestAccAWSSESReceiptRule_disappears(t *testing.T) { - rInt := acctest.RandInt() - resourceName := "aws_ses_receipt_rule.basic" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_ses_receipt_rule.test" + ruleSetResourceName := "aws_ses_receipt_rule_set.test" resource.ParallelTest(t, resource.TestCase{ @@ -132,7 +142,7 @@ func TestAccAWSSESReceiptRule_disappears(t *testing.T) { CheckDestroy: testAccCheckSESReceiptRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSSESReceiptRuleBasicConfig(rInt), + Config: testAccAWSSESReceiptRuleBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsSESReceiptRuleExists(resourceName), testAccCheckResourceDisappears(testAccProvider, resourceAwsSesReceiptRuleSet(), ruleSetResourceName), @@ -140,7 +150,7 @@ func TestAccAWSSESReceiptRule_disappears(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: testAccAWSSESReceiptRuleBasicConfig(rInt), + Config: testAccAWSSESReceiptRuleBasicConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsSESReceiptRuleExists(resourceName), testAccCheckResourceDisappears(testAccProvider, resourceAwsSesReceiptRule(), resourceName), @@ -204,7 +214,7 @@ func testAccCheckAwsSESReceiptRuleExists(n string) resource.TestCheckFunc { return err } - if !*response.Rule.Enabled { + if !aws.BoolValue(response.Rule.Enabled) { return fmt.Errorf("Enabled (%v) was not set to true", *response.Rule.Enabled) } @@ -212,11 +222,11 @@ func testAccCheckAwsSESReceiptRuleExists(n string) resource.TestCheckFunc { return fmt.Errorf("Recipients (%v) was not set to [test@example.com]", response.Rule.Recipients) } - if !*response.Rule.ScanEnabled { + if !aws.BoolValue(response.Rule.ScanEnabled) { return fmt.Errorf("ScanEnabled (%v) was not set to true", *response.Rule.ScanEnabled) } - if *response.Rule.TlsPolicy != "Require" { + if aws.StringValue(response.Rule.TlsPolicy) != ses.TlsPolicyRequire { return fmt.Errorf("TLS Policy (%s) was not set to Require", *response.Rule.TlsPolicy) } @@ -297,25 +307,25 @@ func testAccCheckAwsSESReceiptRuleActions(n string) resource.TestCheckFunc { } addHeaderAction := actions[0].AddHeaderAction - if *addHeaderAction.HeaderName != "Another-Header" { + if aws.StringValue(addHeaderAction.HeaderName) != "Another-Header" { return fmt.Errorf("Header Name (%s) was not equal to Another-Header", *addHeaderAction.HeaderName) } - if *addHeaderAction.HeaderValue != "First" { + if aws.StringValue(addHeaderAction.HeaderValue) != "First" { return fmt.Errorf("Header Value (%s) was not equal to First", *addHeaderAction.HeaderValue) } secondAddHeaderAction := actions[1].AddHeaderAction - if *secondAddHeaderAction.HeaderName != "Added-By" { + if aws.StringValue(secondAddHeaderAction.HeaderName) != "Added-By" { return fmt.Errorf("Header Name (%s) was not equal to Added-By", *secondAddHeaderAction.HeaderName) } - if *secondAddHeaderAction.HeaderValue != "Terraform" { + if aws.StringValue(secondAddHeaderAction.HeaderValue) != "Terraform" { return fmt.Errorf("Header Value (%s) was not equal to Terraform", *secondAddHeaderAction.HeaderValue) } stopAction := actions[2].StopAction - if *stopAction.Scope != "RuleSet" { + if aws.StringValue(stopAction.Scope) != ses.StopScopeRuleSet { return fmt.Errorf("Scope (%s) was not equal to RuleSet", *stopAction.Scope) } @@ -349,34 +359,34 @@ func testAccPreCheckSESReceiptRule(t *testing.T) { func testAccAWSSESReceiptRuleBasicConfig(rInt int) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { - rule_set_name = "test-me-%d" + rule_set_name = %[1]q } -resource "aws_ses_receipt_rule" "basic" { - name = "basic" +resource "aws_ses_receipt_rule" "test" { + name = %[1]q rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name recipients = ["test@example.com"] enabled = true scan_enabled = true tls_policy = "Require" } -`, rInt) +`, rName) } -func testAccAWSSESReceiptRuleS3ActionConfig(rInt int) string { +func testAccAWSSESReceiptRuleS3ActionConfig(rName string) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { - rule_set_name = "test-me-%d" + rule_set_name = %[1]q } -resource "aws_s3_bucket" "emails" { - bucket = "ses-terraform-emails-%d" +resource "aws_s3_bucket" "test" { + bucket = %[1]q acl = "public-read-write" force_destroy = "true" } -resource "aws_ses_receipt_rule" "basic" { - name = "basic" +resource "aws_ses_receipt_rule" "test" { + name = %[1]q rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name recipients = ["test@example.com"] enabled = true @@ -388,36 +398,36 @@ resource "aws_ses_receipt_rule" "basic" { position = 1 } } -`, rInt, rInt) +`, rName) } -func testAccAWSSESReceiptRuleOrderConfig(rInt int) string { +func testAccAWSSESReceiptRuleOrderConfig(rName string) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { - rule_set_name = "test-me-%d" + rule_set_name = %[1]q } -resource "aws_ses_receipt_rule" "second" { - name = "second" +resource "aws_ses_receipt_rule" "test" { + name = %[1]q rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name - after = aws_ses_receipt_rule.first.name + after = aws_ses_receipt_rule.test1.name } -resource "aws_ses_receipt_rule" "first" { +resource "aws_ses_receipt_rule" "test1" { name = "first" rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name } -`, rInt) +`, rName) } -func testAccAWSSESReceiptRuleActionsConfig(rInt int) string { +func testAccAWSSESReceiptRuleActionsConfig(rName string) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { - rule_set_name = "test-me-%d" + rule_set_name = %[1]q } -resource "aws_ses_receipt_rule" "actions" { - name = "actions4" +resource "aws_ses_receipt_rule" "test" { + name = %[1]q rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name add_header_action { @@ -437,5 +447,5 @@ resource "aws_ses_receipt_rule" "actions" { position = 3 } } -`, rInt) +`, rName) } diff --git a/website/docs/r/ses_receipt_rule.html.markdown b/website/docs/r/ses_receipt_rule.html.markdown index ca5f459c577..62257fcd93b 100644 --- a/website/docs/r/ses_receipt_rule.html.markdown +++ b/website/docs/r/ses_receipt_rule.html.markdown @@ -100,6 +100,13 @@ WorkMail actions support the following: * `topic_arn` - (Optional) The ARN of an SNS topic to notify * `position` - (Required) The position of the action in the receipt rule +## Attributes Reference + +In addition to the arguments, which are exported, the following attributes are exported: + +* `id` - The SES receipt rule name. +* `arn` - The SES receipt rule ARN. + ## Import SES receipt rules can be imported using the ruleset name and rule name separated by `:`. From 4b30f5358e8c36e096507b638c26aec6802ca293 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Fri, 26 Jun 2020 23:02:03 +0300 Subject: [PATCH 02/10] fix order test --- aws/resource_aws_ses_receipt_rule_test.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_ses_receipt_rule_test.go b/aws/resource_aws_ses_receipt_rule_test.go index fa4d25616ac..c7c4a5cfc67 100644 --- a/aws/resource_aws_ses_receipt_rule_test.go +++ b/aws/resource_aws_ses_receipt_rule_test.go @@ -269,7 +269,8 @@ func testAccCheckAwsSESReceiptRuleOrder(n string) resource.TestCheckFunc { if len(response.Rules) != 2 { return fmt.Errorf("Number of rules (%d) was not equal to 2", len(response.Rules)) - } else if *response.Rules[0].Name != "first" || *response.Rules[1].Name != "second" { + } else if aws.StringValue(response.Rules[0].Name) != "first" || + aws.StringValue(response.Rules[1].Name) != "second" { return fmt.Errorf("Order of rules (%v) was incorrect", response.Rules) } @@ -356,7 +357,7 @@ func testAccPreCheckSESReceiptRule(t *testing.T) { } } -func testAccAWSSESReceiptRuleBasicConfig(rInt int) string { +func testAccAWSSESReceiptRuleBasicConfig(rName string) string { return fmt.Sprintf(` resource "aws_ses_receipt_rule_set" "test" { rule_set_name = %[1]q @@ -408,15 +409,9 @@ resource "aws_ses_receipt_rule_set" "test" { } resource "aws_ses_receipt_rule" "test" { - name = %[1]q - rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name - after = aws_ses_receipt_rule.test1.name -} - resource "aws_ses_receipt_rule" "test1" { name = "first" rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name -} `, rName) } From 562ff3f08a6f013bc666e2c0e029f5322f9e15cf Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 25 Jul 2020 15:44:51 +0300 Subject: [PATCH 03/10] add docs --- website/docs/index.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 5a6d9fd1726..524b5ea0610 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_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_receipt_filter` resource](/docs/providers/aws/r/ses_receipt_filter.html) + - [`aws_ses_receipt_rule` resource](/docs/providers/aws/r/ses_receipt_rule.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) From 4b93598b87d7a918c6d6e10a7494e3483dd830fe Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 12 Nov 2020 21:36:31 +0200 Subject: [PATCH 04/10] refactor --- aws/resource_aws_ses_receipt_rule.go | 28 +++++++++-------------- aws/resource_aws_ses_receipt_rule_test.go | 8 ++++++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_ses_receipt_rule.go b/aws/resource_aws_ses_receipt_rule.go index 358eee4f780..71b879698a8 100644 --- a/aws/resource_aws_ses_receipt_rule.go +++ b/aws/resource_aws_ses_receipt_rule.go @@ -57,7 +57,7 @@ func resourceAwsSesReceiptRule() *schema.Resource { "enabled": { Type: schema.TypeBool, Optional: true, - Computed: true, + Default: false, }, "recipients": { @@ -69,17 +69,14 @@ func resourceAwsSesReceiptRule() *schema.Resource { "scan_enabled": { Type: schema.TypeBool, Optional: true, - Computed: true, + Default: false, }, "tls_policy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice([]string{ - ses.TlsPolicyOptional, - ses.TlsPolicyRequire, - }, false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(ses.TlsPolicy_Values(), false), }, "add_header_action": { @@ -189,13 +186,10 @@ func resourceAwsSesReceiptRule() *schema.Resource { }, "invocation_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice([]string{ - ses.InvocationTypeEvent, - ses.InvocationTypeRequestResponse, - }, false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice(ses.InvocationType_Values(), false), }, "topic_arn": { @@ -429,7 +423,7 @@ func resourceAwsSesReceiptRuleCreate(d *schema.ResourceData, meta interface{}) e d.SetId(d.Get("name").(string)) - return resourceAwsSesReceiptRuleUpdate(d, meta) + return resourceAwsSesReceiptRuleRead(d, meta) } func resourceAwsSesReceiptRuleUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/aws/resource_aws_ses_receipt_rule_test.go b/aws/resource_aws_ses_receipt_rule_test.go index c7c4a5cfc67..9e5397b4713 100644 --- a/aws/resource_aws_ses_receipt_rule_test.go +++ b/aws/resource_aws_ses_receipt_rule_test.go @@ -395,7 +395,7 @@ resource "aws_ses_receipt_rule" "test" { tls_policy = "Require" s3_action { - bucket_name = aws_s3_bucket.emails.id + bucket_name = aws_s3_bucket.test.id position = 1 } } @@ -409,9 +409,15 @@ resource "aws_ses_receipt_rule_set" "test" { } resource "aws_ses_receipt_rule" "test" { + name = "second" + rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name + after = aws_ses_receipt_rule.test1.name +} + resource "aws_ses_receipt_rule" "test1" { name = "first" rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name +} `, rName) } From e43b9adb197458791c4d8238300510c87bc34e88 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 5 Dec 2020 21:27:48 +0200 Subject: [PATCH 05/10] lint --- website/docs/index.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 524b5ea0610..1682f614d8b 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -318,7 +318,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib - [`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_receipt_filter` resource](/docs/providers/aws/r/ses_receipt_filter.html) - - [`aws_ses_receipt_rule` resource](/docs/providers/aws/r/ses_receipt_rule.html) + - [`aws_ses_receipt_rule` resource](/docs/providers/aws/r/ses_receipt_rule.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) From c2bdf991855246e9262fabc91098a5e8996ac94e Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 11 Feb 2021 17:20:37 +0200 Subject: [PATCH 06/10] change log + validation --- .changelog/13962.txt | 8 ++++++++ aws/resource_aws_ses_receipt_rule_set.go | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changelog/13962.txt diff --git a/.changelog/13962.txt b/.changelog/13962.txt new file mode 100644 index 00000000000..9c9133aaf27 --- /dev/null +++ b/.changelog/13962.txt @@ -0,0 +1,8 @@ +```release-note:enhancement +resource/aws_ses_receipt_rule_set: Add `arn` attribute. +``` + +```release-note:enhancement +resource/aws_ses_receipt_rule_set: Add plan time validation to `name`. +``` + diff --git a/aws/resource_aws_ses_receipt_rule_set.go b/aws/resource_aws_ses_receipt_rule_set.go index 84de3716f6c..1ac89720871 100644 --- a/aws/resource_aws_ses_receipt_rule_set.go +++ b/aws/resource_aws_ses_receipt_rule_set.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "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 resourceAwsSesReceiptRuleSet() *schema.Resource { @@ -20,9 +21,10 @@ func resourceAwsSesReceiptRuleSet() *schema.Resource { Schema: map[string]*schema.Schema{ "rule_set_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringLenBetween(1, 64), }, }, } From 2f0b7675d9ab77b9479be50c9209ff01ca66eb95 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 11 Feb 2021 17:23:02 +0200 Subject: [PATCH 07/10] revert --- .changelog/13962.txt | 4 ++-- aws/resource_aws_ses_receipt_rule_set.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.changelog/13962.txt b/.changelog/13962.txt index 9c9133aaf27..e0c9b49fd06 100644 --- a/.changelog/13962.txt +++ b/.changelog/13962.txt @@ -1,8 +1,8 @@ ```release-note:enhancement -resource/aws_ses_receipt_rule_set: Add `arn` attribute. +resource/ses_receipt_rule: Add `arn` attribute. ``` ```release-note:enhancement -resource/aws_ses_receipt_rule_set: Add plan time validation to `name`. +resource/ses_receipt_rule: Add plan time validation to `name`. ``` diff --git a/aws/resource_aws_ses_receipt_rule_set.go b/aws/resource_aws_ses_receipt_rule_set.go index 1ac89720871..84de3716f6c 100644 --- a/aws/resource_aws_ses_receipt_rule_set.go +++ b/aws/resource_aws_ses_receipt_rule_set.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "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 resourceAwsSesReceiptRuleSet() *schema.Resource { @@ -21,10 +20,9 @@ func resourceAwsSesReceiptRuleSet() *schema.Resource { Schema: map[string]*schema.Schema{ "rule_set_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringLenBetween(1, 64), + Type: schema.TypeString, + Required: true, + ForceNew: true, }, }, } From 1a5e40793e790e029cc4e68cd3b3827ea0adbf62 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 11 Feb 2021 17:24:12 +0200 Subject: [PATCH 08/10] fix --- .changelog/13962.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.changelog/13962.txt b/.changelog/13962.txt index e0c9b49fd06..5b9b26e09ec 100644 --- a/.changelog/13962.txt +++ b/.changelog/13962.txt @@ -3,6 +3,9 @@ resource/ses_receipt_rule: Add `arn` attribute. ``` ```release-note:enhancement -resource/ses_receipt_rule: Add plan time validation to `name`. +resource/ses_receipt_rule: add plan time validations for `name`, `tls_policy`, `add_header_action.header_name`, +`add_header_action.header_value`, `bounce_action.topic_arn`, `lambda_action.function_arn`, `lambda_action.topic_arn`, +`lambda_action.invocation_type`, `s3_action,topic_arn`, `sns_action.topic_arn`, `stop_action.scope`, `stop_action.topic_arn`, +`workmail_action.topic_arn`, `workmail_action.organization_arn` ``` From cf5f27d6c0c37b6de3c8ba94ce459b63cbe2d9ad Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 11 Feb 2021 17:25:52 +0200 Subject: [PATCH 09/10] fix 2 --- .changelog/{13962.txt => 13960.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{13962.txt => 13960.txt} (100%) diff --git a/.changelog/13962.txt b/.changelog/13960.txt similarity index 100% rename from .changelog/13962.txt rename to .changelog/13960.txt From d3f56713e26a12eef28ee760b1711df527ab9015 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 11 Feb 2021 13:07:18 -0500 Subject: [PATCH 10/10] Apply suggestions from code review --- .changelog/13960.txt | 8 ++------ aws/resource_aws_ses_receipt_rule.go | 8 +++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.changelog/13960.txt b/.changelog/13960.txt index 5b9b26e09ec..5ec32e64167 100644 --- a/.changelog/13960.txt +++ b/.changelog/13960.txt @@ -1,11 +1,7 @@ ```release-note:enhancement -resource/ses_receipt_rule: Add `arn` attribute. +resource/aws_ses_receipt_rule: Add `arn` attribute ``` ```release-note:enhancement -resource/ses_receipt_rule: add plan time validations for `name`, `tls_policy`, `add_header_action.header_name`, -`add_header_action.header_value`, `bounce_action.topic_arn`, `lambda_action.function_arn`, `lambda_action.topic_arn`, -`lambda_action.invocation_type`, `s3_action,topic_arn`, `sns_action.topic_arn`, `stop_action.scope`, `stop_action.topic_arn`, -`workmail_action.topic_arn`, `workmail_action.organization_arn` +resource/aws_ses_receipt_rule: Add plan time validations for `name`, `tls_policy`, `add_header_action.header_name`, `add_header_action.header_value`, `bounce_action.topic_arn`, `lambda_action.function_arn`, `lambda_action.topic_arn`, `lambda_action.invocation_type`, `s3_action,topic_arn`, `sns_action.topic_arn`, `stop_action.scope`, `stop_action.topic_arn`, `workmail_action.topic_arn`, and `workmail_action.organization_arn` attributes ``` - diff --git a/aws/resource_aws_ses_receipt_rule.go b/aws/resource_aws_ses_receipt_rule.go index 71b879698a8..d8a1dfce9b9 100644 --- a/aws/resource_aws_ses_receipt_rule.go +++ b/aws/resource_aws_ses_receipt_rule.go @@ -313,11 +313,9 @@ func resourceAwsSesReceiptRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "scope": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - ses.StopScopeRuleSet, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(ses.StopScope_Values(), false), }, "topic_arn": {