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

Add import of aws_ses_active_receipt_rule_set resource #27604

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
3 changes: 3 additions & 0 deletions .changelog/27604.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ses_active_receipt_rule_set: Support import
```
36 changes: 36 additions & 0 deletions internal/service/ses/active_receipt_rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func ResourceActiveReceiptRuleSet() *schema.Resource {
ReadWithoutTimeout: resourceActiveReceiptRuleSetRead,
DeleteWithoutTimeout: resourceActiveReceiptRuleSetDelete,

Importer: &schema.ResourceImporter{
StateContext: resourceActiveReceiptRuleSetImport,
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -109,3 +113,35 @@ func resourceActiveReceiptRuleSetDelete(ctx context.Context, d *schema.ResourceD

return diags
}

func resourceActiveReceiptRuleSetImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
conn := meta.(*conns.AWSClient).SESConn(ctx)

describeOpts := &ses.DescribeActiveReceiptRuleSetInput{}

response, err := conn.DescribeActiveReceiptRuleSetWithContext(ctx, describeOpts)
if err != nil {
return nil, err
}

if response.Metadata == nil {
return nil, fmt.Errorf("no active Receipt Rule Set found")
}

if aws.StringValue(response.Metadata.Name) != d.Id() {
return nil, fmt.Errorf("SES Receipt Rule Set (%s) belonging to SES Active Receipt Rule Set not found", d.Id())
}

d.Set("rule_set_name", response.Metadata.Name)

arnValue := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Service: "ses",
Region: meta.(*conns.AWSClient).Region,
AccountID: meta.(*conns.AWSClient).AccountID,
Resource: fmt.Sprintf("receipt-rule-set/%s", d.Id()),
}.String()
d.Set("arn", arnValue)

return []*schema.ResourceData{d}, nil
}
5 changes: 5 additions & 0 deletions internal/service/ses/active_receipt_rule_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func testAccActiveReceiptRuleSet_basic(t *testing.T) {
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "ses", fmt.Sprintf("receipt-rule-set/%s", rName)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
8 changes: 8 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 @@ -30,3 +30,11 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The SES receipt rule set name.
* `arn` - The SES receipt rule set ARN.

## Import

Active SES receipt rule sets can be imported using the rule set name.

```
$ terraform import aws_ses_active_receipt_rule_set.my_rule_set my_rule_set_name
```
Loading