Skip to content

Commit

Permalink
Merge pull request #36897 from acwwat/b-aws_sesv2_configuration_set_e…
Browse files Browse the repository at this point in the history
…vent_destination-fix_matching_event_types_diff

fix: Change event_destination.matching_event_types to Set to fix diff due to AWS-side sorting for aws_sesv2_configuration_set_event_destination
  • Loading branch information
ewbankkit authored Sep 11, 2024
2 parents 9a42dce + 5fb45e5 commit 597c672
Show file tree
Hide file tree
Showing 31 changed files with 809 additions and 843 deletions.
3 changes: 3 additions & 0 deletions .changelog/36897.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_sesv2_configuration_set_event_destination: Change `event_destination.matching_event_types` from `TypeList` to `TypeSet` as order is not significant
```
64 changes: 31 additions & 33 deletions internal/service/sesv2/account_vdm_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/sesv2"
"github.com/aws/aws-sdk-go-v2/service/sesv2/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
Expand All @@ -21,7 +20,7 @@ import (
)

// @SDKResource("aws_sesv2_account_vdm_attributes", name="Account VDM Attributes")
func ResourceAccountVDMAttributes() *schema.Resource {
func resourceAccountVDMAttributes() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAccountVDMAttributesUpdate,
ReadWithoutTimeout: resourceAccountVDMAttributesRead,
Expand Down Expand Up @@ -73,7 +72,7 @@ func ResourceAccountVDMAttributes() *schema.Resource {
}

const (
ResNameAccountVDMAttributes = "Account VDM Attributes"
resNameAccountVDMAttributes = "Account VDM Attributes"
)

func resourceAccountVDMAttributesUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand All @@ -96,11 +95,11 @@ func resourceAccountVDMAttributesUpdate(ctx context.Context, d *schema.ResourceD

out, err := conn.PutAccountVdmAttributes(ctx, in)
if err != nil {
return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameAccountVDMAttributes, "", err)
return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, resNameAccountVDMAttributes, "", err)
}

if out == nil {
return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameAccountVDMAttributes, "", errors.New("empty output"))
return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, resNameAccountVDMAttributes, "", errors.New("empty output"))
}

if d.IsNewResource() {
Expand All @@ -114,7 +113,7 @@ func resourceAccountVDMAttributesRead(ctx context.Context, d *schema.ResourceDat
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SESV2Client(ctx)

out, err := FindAccountVDMAttributes(ctx, conn)
out, err := findAccountVDMAttributes(ctx, conn)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] SESV2 AccountVDMAttributes (%s) not found, removing from state", d.Id())
Expand All @@ -123,21 +122,19 @@ func resourceAccountVDMAttributesRead(ctx context.Context, d *schema.ResourceDat
}

if err != nil {
return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameAccountVDMAttributes, d.Id(), err)
return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, resNameAccountVDMAttributes, d.Id(), err)
}

if out.DashboardAttributes != nil {
if err := d.Set("dashboard_attributes", []interface{}{flattenDashboardAttributes(out.DashboardAttributes)}); err != nil {
return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameAccountVDMAttributes, d.Id(), err)
return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, resNameAccountVDMAttributes, d.Id(), err)
}
}

if out.GuardianAttributes != nil {
if err := d.Set("guardian_attributes", []interface{}{flattenGuardianAttributes(out.GuardianAttributes)}); err != nil {
return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameAccountVDMAttributes, d.Id(), err)
return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, resNameAccountVDMAttributes, d.Id(), err)
}
}

d.Set("vdm_enabled", out.VdmEnabled)

return diags
Expand All @@ -147,46 +144,47 @@ func resourceAccountVDMAttributesDelete(ctx context.Context, d *schema.ResourceD
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SESV2Client(ctx)

log.Printf("[INFO] Deleting SESV2 AccountVDMAttributes %s", d.Id())

log.Printf("[INFO] Deleting SESV2 AccountVDMAttributes: %s", d.Id())
_, err := conn.PutAccountVdmAttributes(ctx, &sesv2.PutAccountVdmAttributesInput{
VdmAttributes: &types.VdmAttributes{
VdmEnabled: "DISABLED",
VdmEnabled: types.FeatureStatusDisabled,
},
})

if err != nil {
var nfe *types.NotFoundException
if errors.As(err, &nfe) {
return diags
}

return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameAccountVDMAttributes, d.Id(), err)
return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, resNameAccountVDMAttributes, d.Id(), err)
}

return diags
}

func FindAccountVDMAttributes(ctx context.Context, conn *sesv2.Client) (*types.VdmAttributes, error) {
in := &sesv2.GetAccountInput{}
out, err := conn.GetAccount(ctx, in)
func findAccountVDMAttributes(ctx context.Context, conn *sesv2.Client) (*types.VdmAttributes, error) {
output, err := findAccount(ctx, conn)

if err != nil {
var nfe *types.NotFoundException
if errors.As(err, &nfe) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: in,
}
}
return nil, err
}

if output.VdmAttributes == nil {
return nil, tfresource.NewEmptyResultError(nil)
}

return output.VdmAttributes, nil
}

func findAccount(ctx context.Context, conn *sesv2.Client) (*sesv2.GetAccountOutput, error) {
input := &sesv2.GetAccountInput{}
output, err := conn.GetAccount(ctx, input)

if err != nil {
return nil, err
}

if out == nil || out.VdmAttributes == nil {
return nil, tfresource.NewEmptyResultError(in)
if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return out.VdmAttributes, nil
return output, nil
}

func expandDashboardAttributes(tfMap map[string]interface{}) *types.DashboardAttributes {
Expand Down
16 changes: 10 additions & 6 deletions internal/service/sesv2/account_vdm_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package sesv2_test

import (
"context"
"errors"
"fmt"
"testing"

Expand All @@ -14,8 +13,8 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
tfsesv2 "github.com/hashicorp/terraform-provider-aws/internal/service/sesv2"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -153,16 +152,21 @@ func testAccCheckAccountVDMAttributesDestroy(ctx context.Context) resource.TestC
continue
}

out, err := tfsesv2.FindAccountVDMAttributes(ctx, conn)
output, err := tfsesv2.FindAccountVDMAttributes(ctx, conn)

if tfresource.NotFound(err) {
continue
}

if err != nil {
return err
}

if out.VdmEnabled == types.FeatureStatusDisabled {
return nil
if output.VdmEnabled == types.FeatureStatusDisabled {
continue
}

return create.Error(names.SESV2, create.ErrActionCheckingDestroyed, tfsesv2.ResNameAccountVDMAttributes, rs.Primary.ID, errors.New("not destroyed"))
return fmt.Errorf("SESv2 Account VDM Attributes %s still exists", rs.Primary.ID)
}

return nil
Expand Down
Loading

0 comments on commit 597c672

Please sign in to comment.