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

[wip] resource/aws_ses_receipt_rule: support import functionality #6237

Merged
merged 1 commit into from
Nov 12, 2018
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
20 changes: 20 additions & 0 deletions aws/resource_aws_ses_receipt_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"sort"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand All @@ -20,6 +21,9 @@ func resourceAwsSesReceiptRule() *schema.Resource {
Update: resourceAwsSesReceiptRuleUpdate,
Read: resourceAwsSesReceiptRuleRead,
Delete: resourceAwsSesReceiptRuleDelete,
Importer: &schema.ResourceImporter{
State: resourceAwsSesReceiptRuleImport,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -356,6 +360,22 @@ func resourceAwsSesReceiptRule() *schema.Resource {
}
}

func resourceAwsSesReceiptRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
idParts := strings.Split(d.Id(), ":")
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
return nil, fmt.Errorf("unexpected format of ID (%q), expected <ruleset-name>:<rule-name>", d.Id())
}

ruleSetName := idParts[0]
ruleName := idParts[1]

d.Set("rule_set_name", ruleSetName)
d.Set("name", ruleName)
d.SetId(ruleName)

return []*schema.ResourceData{d}, nil
}

func resourceAwsSesReceiptRuleCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sesConn

Expand Down
16 changes: 16 additions & 0 deletions aws/resource_aws_ses_receipt_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestAccAWSSESReceiptRule_basic(t *testing.T) {
testAccCheckAwsSESReceiptRuleExists("aws_ses_receipt_rule.basic"),
),
},
{
ResourceName: "aws_ses_receipt_rule.basic",
ImportState: true,
ImportStateIdFunc: testAccAwsSesReceiptRuleImportStateIdFunc("aws_ses_receipt_rule.basic"),
},
},
})
}
Expand Down Expand Up @@ -158,6 +163,17 @@ func testAccCheckAwsSESReceiptRuleExists(n string) resource.TestCheckFunc {
}
}

func testAccAwsSesReceiptRuleImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("Not Found: %s", resourceName)
}

return fmt.Sprintf("%s:%s", rs.Primary.Attributes["rule_set_name"], rs.Primary.Attributes["name"])
}
}

func testAccCheckAwsSESReceiptRuleOrder(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/ses_receipt_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ WorkMail actions support the following:
* `organization_arn` - (Required) The ARN of the WorkMail organization
* `topic_arn` - (Optional) The ARN of an SNS topic to notify
* `position` - (Required) The position of the action in the receipt rule

## Import

SES receipt rules can be imported using the ruleset name and rule name separated by `:`.

```
$ terraform import aws_ses_receipt_rule.my_rule my_rule_set:my_rule
```