-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30108 from kamilturek/f-data-aws-sesv2-configurat…
…ion-set d/aws_sesv2_configuration_set: new data source
- Loading branch information
Showing
6 changed files
with
375 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-data-source | ||
aws_sesv2_configuration_set | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
internal/service/sesv2/configuration_set_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
89
internal/service/sesv2/configuration_set_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.