From a36e40052bac9372631984334edd4b1fd0f05211 Mon Sep 17 00:00:00 2001 From: Francis Chuang Date: Mon, 27 Feb 2023 12:59:07 +1100 Subject: [PATCH] Allow suppressed_reasons to be an empty list in order to disable the suppression list for a configuration set --- .changelog/29671.txt | 3 ++ internal/service/sesv2/configuration_set.go | 27 ++++++++++--- .../service/sesv2/configuration_set_test.go | 39 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 .changelog/29671.txt diff --git a/.changelog/29671.txt b/.changelog/29671.txt new file mode 100644 index 000000000000..10923b95b8e7 --- /dev/null +++ b/.changelog/29671.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/sesv2_configuration_set: Allow suppressed_reasons to be an empty list in order to disable the suppression list +``` diff --git a/internal/service/sesv2/configuration_set.go b/internal/service/sesv2/configuration_set.go index c7d6fee34ed9..661e94d2ecbf 100644 --- a/internal/service/sesv2/configuration_set.go +++ b/internal/service/sesv2/configuration_set.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/hashicorp/go-cty/cty" "log" "time" @@ -107,7 +108,6 @@ func ResourceConfigurationSet() *schema.Resource { "suppressed_reasons": { Type: schema.TypeList, Optional: true, - MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, ValidateDiagFunc: enum.Validate[types.SuppressionListReason](), @@ -160,8 +160,20 @@ func resourceConfigurationSetCreate(ctx context.Context, d *schema.ResourceData, in.SendingOptions = expandSendingOptions(v.([]interface{})[0].(map[string]interface{})) } - if v, ok := d.GetOk("suppression_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - in.SuppressionOptions = expandSuppressionOptions(v.([]interface{})[0].(map[string]interface{})) + rawConfigMap := d.GetRawConfig().AsValueMap() + if v, ok := rawConfigMap["suppression_options"]; ok && v.LengthInt() > 0 { + if v, ok := v.Index(cty.NumberIntVal(0)).AsValueMap()["suppressed_reasons"]; ok && !v.IsNull() { + + options := map[string]interface{}{ + "suppressed_reasons": []interface{}{}, + } + + for _, reason := range v.AsValueSlice() { + options["suppressed_reasons"] = append(options["suppressed_reasons"].([]interface{}), reason.AsString()) + } + + in.SuppressionOptions = expandSuppressionOptions(options) + } } if v, ok := d.GetOk("tracking_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -567,14 +579,19 @@ func expandSendingOptions(tfMap map[string]interface{}) *types.SendingOptions { } func expandSuppressionOptions(tfMap map[string]interface{}) *types.SuppressionOptions { + if tfMap == nil { return nil } a := &types.SuppressionOptions{} - if v, ok := tfMap["suppressed_reasons"].([]interface{}); ok && len(v) > 0 { - a.SuppressedReasons = expandSuppressedReasons(v) + if v, ok := tfMap["suppressed_reasons"].([]interface{}); ok { + if len(v) > 0 { + a.SuppressedReasons = expandSuppressedReasons(v) + } else { + a.SuppressedReasons = make([]types.SuppressionListReason, 0) + } } return a diff --git a/internal/service/sesv2/configuration_set_test.go b/internal/service/sesv2/configuration_set_test.go index 4d50664d899c..c319d61916db 100644 --- a/internal/service/sesv2/configuration_set_test.go +++ b/internal/service/sesv2/configuration_set_test.go @@ -215,6 +215,34 @@ func TestAccSESV2ConfigurationSet_suppressedReasons(t *testing.T) { }) } +func TestAccSESV2ConfigurationSet_suppressedReasonsEmpty(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_suppressedReasonsEmpty(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigurationSetExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "suppression_options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "suppression_options.0.suppressed_reasons.#", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccSESV2ConfigurationSet_tags(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -389,3 +417,14 @@ resource "aws_sesv2_configuration_set" "test" { } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) } + +func testAccConfigurationSetConfig_suppressedReasonsEmpty(rName string) string { + return fmt.Sprintf(` +resource "aws_sesv2_configuration_set" "test" { + configuration_set_name = %[1]q + suppression_options { + suppressed_reasons = [] + } +} +`, rName) +}