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

r/aws_sesv2_configuration_set - add vdm_options argument #28812

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/28812.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_sesv2_configuration_set: Add `vdm_options` argument
```
153 changes: 153 additions & 0 deletions internal/service/sesv2/configuration_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,43 @@ func ResourceConfigurationSet() *schema.Resource {
},
},
},
"vdm_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dashboard_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"engagement_metrics": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: enum.Validate[types.FeatureStatus](),
},
},
},
},
"guardian_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"optimized_shared_delivery": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: enum.Validate[types.FeatureStatus](),
},
},
},
},
},
},
},
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down Expand Up @@ -169,6 +206,10 @@ func resourceConfigurationSetCreate(ctx context.Context, d *schema.ResourceData,
in.TrackingOptions = expandTrackingOptions(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk("vdm_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
in.VdmOptions = expandVDMOptions(v.([]interface{})[0].(map[string]interface{}))
}

defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{})))

Expand Down Expand Up @@ -256,6 +297,14 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m
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, ResNameConfigurationSet, 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, ResNameConfigurationSet, d.Id(), err)
Expand Down Expand Up @@ -383,6 +432,22 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData,
}
}

if d.HasChanges("vdm_options") {
in := &sesv2.PutConfigurationSetVdmOptionsInput{
ConfigurationSetName: aws.String(d.Id()),
}

if v, ok := d.GetOk("vdm_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
in.VdmOptions = expandVDMOptions(v.([]interface{})[0].(map[string]interface{}))
}

log.Printf("[DEBUG] Updating SESV2 ConfigurationSet VdmOptions (%s): %#v", d.Id(), in)
_, err := conn.PutConfigurationSetVdmOptions(ctx, in)
if err != nil {
return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err)
}
}

if d.HasChanges("tags_all") {
o, n := d.GetChange("tags_all")

Expand Down Expand Up @@ -521,6 +586,48 @@ func flattenTrackingOptions(apiObject *types.TrackingOptions) map[string]interfa
return m
}

func flattenVDMOptions(apiObject *types.VdmOptions) map[string]interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{}

if v := apiObject.DashboardOptions; v != nil {
m["dashboard_options"] = []interface{}{flattenDashboardOptions(v)}
}

if v := apiObject.GuardianOptions; v != nil {
m["guardian_options"] = []interface{}{flattenGuardianOptions(v)}
}

return m
}

func flattenDashboardOptions(apiObject *types.DashboardOptions) map[string]interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{
"engagement_metrics": string(apiObject.EngagementMetrics),
}

return m
}

func flattenGuardianOptions(apiObject *types.GuardianOptions) map[string]interface{} {
if apiObject == nil {
return nil
}

m := map[string]interface{}{
"optimized_shared_delivery": string(apiObject.OptimizedSharedDelivery),
}

return m
}

func expandDeliveryOptions(tfMap map[string]interface{}) *types.DeliveryOptions {
if tfMap == nil {
return nil
Expand Down Expand Up @@ -606,3 +713,49 @@ func expandTrackingOptions(tfMap map[string]interface{}) *types.TrackingOptions

return a
}

func expandVDMOptions(tfMap map[string]interface{}) *types.VdmOptions {
if tfMap == nil {
return nil
}

a := &types.VdmOptions{}

if v, ok := tfMap["dashboard_options"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
a.DashboardOptions = expandDashboardOptions(v[0].(map[string]interface{}))
}

if v, ok := tfMap["guardian_options"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
a.GuardianOptions = expandGuardianOptions(v[0].(map[string]interface{}))
}

return a
}

func expandDashboardOptions(tfMap map[string]interface{}) *types.DashboardOptions {
if tfMap == nil {
return nil
}

a := &types.DashboardOptions{}

if v, ok := tfMap["engagement_metrics"].(string); ok && v != "" {
a.EngagementMetrics = types.FeatureStatus(v)
}

return a
}

func expandGuardianOptions(tfMap map[string]interface{}) *types.GuardianOptions {
if tfMap == nil {
return nil
}

a := &types.GuardianOptions{}

if v, ok := tfMap["optimized_shared_delivery"].(string); ok && v != "" {
a.OptimizedSharedDelivery = types.FeatureStatus(v)
}

return a
}
104 changes: 104 additions & 0 deletions internal/service/sesv2/configuration_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,82 @@ func TestAccSESV2ConfigurationSet_suppressedReasons(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, names.SESV2EndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckConfigurationSetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccConfigurationSetConfig_engagementMetrics(rName, string(types.FeatureStatusEnabled)),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationSetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "vdm_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.dashboard_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.dashboard_options.0.engagement_metrics", string(types.FeatureStatusEnabled)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccConfigurationSetConfig_engagementMetrics(rName, string(types.FeatureStatusDisabled)),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationSetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "vdm_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.dashboard_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.dashboard_options.0.engagement_metrics", string(types.FeatureStatusDisabled)),
),
},
},
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, names.SESV2EndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckConfigurationSetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccConfigurationSetConfig_optimizedSharedDelivery(rName, string(types.FeatureStatusEnabled)),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationSetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "vdm_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.guardian_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.guardian_options.0.optimized_shared_delivery", string(types.FeatureStatusEnabled)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccConfigurationSetConfig_optimizedSharedDelivery(rName, string(types.FeatureStatusDisabled)),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationSetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "vdm_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.guardian_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vdm_options.0.guardian_options.0.optimized_shared_delivery", string(types.FeatureStatusDisabled)),
),
},
},
})
}

func TestAccSESV2ConfigurationSet_tags(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -365,6 +441,34 @@ resource "aws_sesv2_configuration_set" "test" {
`, rName, suppressedReason)
}

func testAccConfigurationSetConfig_engagementMetrics(rName, engagementMetrics string) string {
return fmt.Sprintf(`
resource "aws_sesv2_configuration_set" "test" {
configuration_set_name = %[1]q

vdm_options {
dashboard_options {
engagement_metrics = %[2]q
}
}
}
`, rName, engagementMetrics)
}

func testAccConfigurationSetConfig_optimizedSharedDelivery(rName, optimizedSharedDelivery string) string {
return fmt.Sprintf(`
resource "aws_sesv2_configuration_set" "test" {
configuration_set_name = %[1]q

vdm_options {
guardian_options {
optimized_shared_delivery = %[2]q
}
}
}
`, rName, optimizedSharedDelivery)
}

func testAccConfigurationSetConfig_tags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_sesv2_configuration_set" "test" {
Expand Down
20 changes: 17 additions & 3 deletions website/docs/r/sesv2_configuration_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following arguments are supported:
* `suppression_options` - (Optional) An object that contains information about the suppression list preferences for your account.
* `tags` - (Optional) A map of tags to assign to the service. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
* `tracking_options` - (Optional) An object that defines the open and click tracking options for emails that you send using the configuration set.
* `vdm_options` - (Optional) An object that defines the VDM settings that apply to emails that you send using the configuration set.

### delivery_options

Expand All @@ -73,11 +74,24 @@ The following arguments are supported:

### suppression_options

- `suppressed_reasons` - (Optional) A list that contains the reasons that email addresses are automatically added to the suppression list for your account. Valid values: `BOUNCE`, `COMPLAINT`.
* `suppressed_reasons` - (Optional) A list that contains the reasons that email addresses are automatically added to the suppression list for your account. Valid values: `BOUNCE`, `COMPLAINT`.

## tracking_options
### tracking_options

- `custom_redirect_domain` - (Required) The domain to use for tracking open and click events.
* `custom_redirect_domain` - (Required) The domain to use for tracking open and click events.

### vdm_options

* `dashboard_options` - (Optional) Specifies additional settings for your VDM configuration as applicable to the Dashboard.
* `guardian_options` - (Optional) Specifies additional settings for your VDM configuration as applicable to the Guardian.

### dashboard_options

* `engagement_metrics` - (Optional) Specifies the status of your VDM engagement metrics collection. Valid values: `ENABLED`, `DISABLED`.

### guardian_options

* `optimized_shared_delivery` - (Optional) Specifies the status of your VDM optimized shared delivery. Valid values: `ENABLED`, `DISABLED`.

## Attributes Reference

Expand Down