Skip to content

Commit

Permalink
Merge pull request #30108 from kamilturek/f-data-aws-sesv2-configurat…
Browse files Browse the repository at this point in the history
…ion-set

d/aws_sesv2_configuration_set: new data source
  • Loading branch information
ewbankkit authored Apr 17, 2023
2 parents 8dcf612 + a4a48a9 commit 204da70
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/30108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_sesv2_configuration_set
```
20 changes: 11 additions & 9 deletions internal/service/sesv2/configuration_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m
return create.DiagError(names.SESV2, create.ErrActionReading, ResNameConfigurationSet, d.Id(), err)
}

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

d.Set("arn", arn)
d.Set("arn", configurationSetNameToARN(meta, aws.ToString(out.ConfigurationSetName)))
d.Set("configuration_set_name", out.ConfigurationSetName)

if out.DeliveryOptions != nil {
Expand Down Expand Up @@ -729,3 +721,13 @@ func expandGuardianOptions(tfMap map[string]interface{}) *types.GuardianOptions

return a
}

func configurationSetNameToARN(meta interface{}, configurationSetName string) string {
return arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Service: "ses",
Region: meta.(*conns.AWSClient).Region,
AccountID: meta.(*conns.AWSClient).AccountID,
Resource: fmt.Sprintf("configuration-set/%s", configurationSetName),
}.String()
}
218 changes: 218 additions & 0 deletions internal/service/sesv2/configuration_set_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
package sesv2

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_sesv2_configuration_set")
func DataSourceConfigurationSet() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceConfigurationSetRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"configuration_set_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 64),
},
"delivery_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sending_pool_name": {
Type: schema.TypeString,
Computed: true,
},
"tls_policy": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"reputation_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"last_fresh_start": {
Type: schema.TypeString,
Computed: true,
},
"reputation_metrics_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"sending_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sending_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"suppression_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"suppressed_reasons": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"tags": tftags.TagsSchemaComputed(),
"tracking_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_redirect_domain": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"vdm_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dashboard_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"engagement_metrics": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"guardian_options": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"optimized_shared_delivery": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
},
}
}

const (
DSNameConfigurationSet = "Configuration Set Data Source"
)

func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).SESV2Client()

name := d.Get("configuration_set_name").(string)

out, err := FindConfigurationSetByID(ctx, conn, name)
if err != nil {
return create.DiagError(names.SESV2, create.ErrActionReading, DSNameConfigurationSet, name, err)
}

d.SetId(aws.ToString(out.ConfigurationSetName))

d.Set("arn", configurationSetNameToARN(meta, aws.ToString(out.ConfigurationSetName)))
d.Set("configuration_set_name", out.ConfigurationSetName)

if out.DeliveryOptions != nil {
if err := d.Set("delivery_options", []interface{}{flattenDeliveryOptions(out.DeliveryOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("delivery_options", nil)
}

if out.ReputationOptions != nil {
if err := d.Set("reputation_options", []interface{}{flattenReputationOptions(out.ReputationOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("reputation_options", nil)
}

if out.SendingOptions != nil {
if err := d.Set("sending_options", []interface{}{flattenSendingOptions(out.SendingOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("sending_options", nil)
}

if out.SuppressionOptions != nil {
if err := d.Set("suppression_options", []interface{}{flattenSuppressionOptions(out.SuppressionOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("suppression_options", nil)
}

if out.TrackingOptions != nil {
if err := d.Set("tracking_options", []interface{}{flattenTrackingOptions(out.TrackingOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("tracking_options", nil)
}

if out.VdmOptions != nil {
if err := d.Set("vdm_options", []interface{}{flattenVDMOptions(out.VdmOptions)}); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}
} else {
d.Set("vdm_options", nil)
}

tags, err := ListTags(ctx, conn, d.Get("arn").(string))
if err != nil {
return create.DiagError(names.SESV2, create.ErrActionReading, DSNameConfigurationSet, d.Id(), err)
}

ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err)
}

return nil
}
89 changes: 89 additions & 0 deletions internal/service/sesv2/configuration_set_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package sesv2_test

import (
"fmt"
"testing"

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"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccSESV2ConfigurationSetDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_sesv2_configuration_set.test"
dataSourceName := "data.aws_sesv2_configuration_set.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.SESV2EndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckConfigurationSetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccConfigurationSetDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationSetExists(ctx, dataSourceName),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "configuration_set_name", dataSourceName, "configuration_set_name"),
resource.TestCheckResourceAttrPair(resourceName, "delivery_options.#", dataSourceName, "delivery_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "delivery_options.0.sending_pool_name", dataSourceName, "delivery_options.0.sending_pool_name"),
resource.TestCheckResourceAttrPair(resourceName, "delivery_options.0.tls_policy", dataSourceName, "delivery_options.0.tls_policy"),
resource.TestCheckResourceAttrPair(resourceName, "reputation_options.#", dataSourceName, "reputation_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "reputation_options.0.last_fresh_start", dataSourceName, "reputation_options.0.last_fresh_start"),
resource.TestCheckResourceAttrPair(resourceName, "reputation_options.0.reputation_metrics_enabled", dataSourceName, "reputation_options.0.reputation_metrics_enabled"),
resource.TestCheckResourceAttrPair(resourceName, "sending_options.#", dataSourceName, "sending_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "sending_options.0.sending_enabled", dataSourceName, "sending_options.0.sending_enabled"),
resource.TestCheckResourceAttrPair(resourceName, "suppression_options.#", dataSourceName, "suppression_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "suppression_options.#", dataSourceName, "suppression_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "tags.%", dataSourceName, "tags.%"),
resource.TestCheckResourceAttrPair(resourceName, "vdm_options.#", dataSourceName, "vdm_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "vdm_options.0.dashboard_options.#", dataSourceName, "vdm_options.0.dashboard_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "vdm_options.0.dashboard_options.0.engagement_metrics", dataSourceName, "vdm_options.0.dashboard_options.0.engagement_metrics"),
resource.TestCheckResourceAttrPair(resourceName, "vdm_options.0.guardian_options.#", dataSourceName, "vdm_options.0.guardian_options.#"),
resource.TestCheckResourceAttrPair(resourceName, "vdm_options.0.guardian_options.0.optimized_shared_delivery", dataSourceName, "vdm_options.0.guardian_options.0.optimized_shared_delivery"),
),
},
},
})
}

func testAccConfigurationSetDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_sesv2_configuration_set" "test" {
configuration_set_name = %[1]q
delivery_options {
tls_policy = "REQUIRE"
}
reputation_options {
reputation_metrics_enabled = true
}
sending_options {
sending_enabled = true
}
suppression_options {
suppressed_reasons = ["BOUNCE"]
}
vdm_options {
dashboard_options {
engagement_metrics = "ENABLED"
}
guardian_options {
optimized_shared_delivery = "ENABLED"
}
}
}
data "aws_sesv2_configuration_set" "test" {
configuration_set_name = aws_sesv2_configuration_set.test.configuration_set_name
}
`, rName)
}
4 changes: 4 additions & 0 deletions internal/service/sesv2/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 204da70

Please sign in to comment.