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

datasource aws_ses_active_receipt_rule_set #22310

Merged
merged 5 commits into from
Dec 22, 2021
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/22310.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_ses_active_receipt_rule_set
```
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ func Provider() *schema.Provider {

"aws_ram_resource_share": ram.DataSourceResourceShare(),

"aws_ses_active_receipt_rule_set": ses.DataSourceActiveReceiptRuleSet(),

"aws_db_cluster_snapshot": rds.DataSourceClusterSnapshot(),
"aws_db_event_categories": rds.DataSourceEventCategories(),
"aws_db_instance": rds.DataSourceInstance(),
Expand Down
52 changes: 52 additions & 0 deletions internal/service/ses/active_receipt_rule_set_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ses

import (
"fmt"

"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-provider-aws/internal/conns"
)

func DataSourceActiveReceiptRuleSet() *schema.Resource {
return &schema.Resource{
Read: dataSourceActiveReceiptRuleSetRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"rule_set_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceActiveReceiptRuleSetRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).SESConn

data, err := conn.DescribeActiveReceiptRuleSet(&ses.DescribeActiveReceiptRuleSetInput{})

if err != nil {
return fmt.Errorf("error reading SES Active Receipt Rule Set: %s", err)
}

name := aws.StringValue(data.Metadata.Name)
d.SetId(name)
d.Set("rule_set_name", name)
arn := 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", name),
}.String()
d.Set("arn", arn)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ses_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/ses"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func testAccActiveReceiptRuleSetDataSource_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "data.aws_ses_active_receipt_rule_set.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
testAccPreCheck(t)
testAccPreCheckSESReceiptRule(t)
},
ErrorCheck: acctest.ErrorCheck(t, ses.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckSESActiveReceiptRuleSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccActiveReceiptRuleSetDataSourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckActiveReceiptRuleSetExists(resourceName),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "ses", fmt.Sprintf("receipt-rule-set/%s", rName)),
),
},
},
})
}

func testAccActiveReceiptRuleSetDataSourceConfig(name string) string {
return fmt.Sprintf(`
resource "aws_ses_receipt_rule_set" "test" {
rule_set_name = %[1]q
}

resource "aws_ses_active_receipt_rule_set" "test" {
rule_set_name = aws_ses_receipt_rule_set.test.rule_set_name
}

data "aws_ses_active_receipt_rule_set" "test" {
depends_on = [aws_ses_active_receipt_rule_set.test]
}
`, name)
}
25 changes: 17 additions & 8 deletions internal/service/ses/active_receipt_rule_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@ import (
// Only one SES Receipt RuleSet can be active at a time, so run serially
// locally and in TeamCity.
func TestAccSESActiveReceiptRuleSet_serial(t *testing.T) {
testFuncs := map[string]func(t *testing.T){
"basic": testAccActiveReceiptRuleSet_basic,
"disappears": testAccActiveReceiptRuleSet_disappears,
testCases := map[string]map[string]func(t *testing.T){
"Resource": {
"basic": testAccActiveReceiptRuleSet_basic,
"disappears": testAccActiveReceiptRuleSet_disappears,
},
"DataSource": {
"basic": testAccActiveReceiptRuleSetDataSource_basic,
},
}

for name, testFunc := range testFuncs {
testFunc := testFunc

t.Run(name, func(t *testing.T) {
testFunc(t)
for group, m := range testCases {
m := m
t.Run(group, func(t *testing.T) {
for name, tc := range m {
tc := tc
t.Run(name, func(t *testing.T) {
tc(t)
})
}
})
}
}
Expand Down
24 changes: 24 additions & 0 deletions website/docs/d/ses_active_receipt_rule_set.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
subcategory: "SES"
layout: "aws"
page_title: "AWS: aws_ses_active_receipt_rule_set"
description: |-
Retrieve the active SES receipt rule set
---

# Data Source: aws_ses_active_receipt_rule_set

Retrieve the active SES receipt rule set

## Example Usage

```terraform
data "aws_ses_active_receipt_rule_set" "main" {}
```

## Attributes Reference

The following attributes are exported:

* `arn` - The SES receipt rule set ARN.
* `rule_set_name` - The name of the rule set