Skip to content

Commit

Permalink
Allow suppressed_reasons to be an empty list in order to disable the …
Browse files Browse the repository at this point in the history
…suppression list for a configuration set
  • Loading branch information
F21 committed Feb 27, 2023
1 parent 5acce42 commit a36e400
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/29671.txt
Original file line number Diff line number Diff line change
@@ -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
```
27 changes: 22 additions & 5 deletions internal/service/sesv2/configuration_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/hashicorp/go-cty/cty"
"log"
"time"

Expand Down Expand Up @@ -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](),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 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,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)
Expand Down Expand Up @@ -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)
}

0 comments on commit a36e400

Please sign in to comment.