diff --git a/.ci/semgrep/pluginsdk/diags.yml b/.ci/semgrep/pluginsdk/diags.yml index c84613a6745..10549eded98 100644 --- a/.ci/semgrep/pluginsdk/diags.yml +++ b/.ci/semgrep/pluginsdk/diags.yml @@ -2,9 +2,6 @@ rules: - id: avoid-return-diag_FromErr languages: [go] message: Prefer `sdkdiag.AppendFromErr` to `diag.FromErr` - paths: - exclude: - - internal/service/[o-s]* pattern: return diag.FromErr($ERR) fix: return sdkdiag.AppendFromErr(diags, $ERR) severity: WARNING @@ -12,9 +9,6 @@ rules: - id: avoid-append-diag_FromErr languages: [go] message: Prefer `sdkdiag.AppendFromErr` to `diag.FromErr` - paths: - exclude: - - internal/service/[o-s]* pattern: append(diags, diag.FromErr($ERR)...) fix: sdkdiag.AppendFromErr(diags, $ERR) severity: WARNING @@ -22,9 +16,6 @@ rules: - id: avoid-diag_Errorf languages: [go] message: Prefer `sdkdiag.AppendErrorf` to `diag.Errorf` - paths: - exclude: - - internal/service/[o-s]* pattern: diag.Errorf($...ARGS) fix: sdkdiag.AppendErrorf(diags, $...ARGS) severity: WARNING @@ -32,9 +23,6 @@ rules: - id: avoid-return-create_DiagError languages: [go] message: Prefer `create.AppendDiagError` to `create.DiagError` - paths: - exclude: - - internal/service/[o-s]* pattern: return create.DiagError($...ARGS) fix: return create.AppendDiagError(diags, $...ARGS) severity: WARNING @@ -42,9 +30,6 @@ rules: - id: avoid-append-create_DiagError languages: [go] message: Prefer `create.AppendDiagError` to `create.DiagError` - paths: - exclude: - - internal/service/[o-s]* pattern: append(diags, create.DiagError($...ARGS)...) fix: create.AppendDiagError(diags, $...ARGS) severity: WARNING @@ -52,9 +37,6 @@ rules: - id: append-Read-to-diags languages: [go] message: Append results of $READFN to diags instead of returning directly - paths: - exclude: - - internal/service/[o-s]* patterns: - pattern: return $READFN($...ARGS) - metavariable-regex: @@ -70,9 +52,6 @@ rules: - id: append-Update-to-diags languages: [go] message: Append results of $UPDATEFN to diags instead of returning directly - paths: - exclude: - - internal/service/[o-s]* patterns: - pattern: return $UPDATEFN($...ARGS) - metavariable-regex: @@ -93,7 +72,7 @@ rules: include: - internal/service exclude: - - internal/service/[o-s]* + - internal/service/o* patterns: - pattern: return nil - pattern-not-inside: | diff --git a/internal/service/oam/link.go b/internal/service/oam/link.go index 4324cd0aa6f..4d79a0fac2c 100644 --- a/internal/service/oam/link.go +++ b/internal/service/oam/link.go @@ -94,6 +94,7 @@ const ( ) func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) in := &oam.CreateLinkInput{ @@ -105,19 +106,20 @@ func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interf out, err := conn.CreateLink(ctx, in) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionCreating, ResNameLink, d.Get("sink_identifier").(string), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionCreating, ResNameLink, d.Get("sink_identifier").(string), err) } if out == nil || out.Id == nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionCreating, ResNameLink, d.Get("sink_identifier").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionCreating, ResNameLink, d.Get("sink_identifier").(string), errors.New("empty output")) } d.SetId(aws.ToString(out.Arn)) - return resourceLinkRead(ctx, d, meta) + return append(diags, resourceLinkRead(ctx, d, meta)...) } func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) out, err := findLinkByID(ctx, conn, d.Id()) @@ -129,7 +131,7 @@ func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interfac } if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, ResNameLink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, ResNameLink, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -144,6 +146,7 @@ func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interfac } func resourceLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) update := false @@ -161,14 +164,15 @@ func resourceLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interf log.Printf("[DEBUG] Updating ObservabilityAccessManager Link (%s): %#v", d.Id(), in) _, err := conn.UpdateLink(ctx, in) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionUpdating, ResNameLink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionUpdating, ResNameLink, d.Id(), err) } } - return resourceLinkRead(ctx, d, meta) + return append(diags, resourceLinkRead(ctx, d, meta)...) } func resourceLinkDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) log.Printf("[INFO] Deleting ObservabilityAccessManager Link %s", d.Id()) @@ -183,7 +187,7 @@ func resourceLinkDelete(ctx context.Context, d *schema.ResourceData, meta interf return nil } - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionDeleting, ResNameLink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionDeleting, ResNameLink, d.Id(), err) } return nil diff --git a/internal/service/oam/link_data_source.go b/internal/service/oam/link_data_source.go index f8bece00e08..af8b0ff3620 100644 --- a/internal/service/oam/link_data_source.go +++ b/internal/service/oam/link_data_source.go @@ -63,13 +63,14 @@ const ( ) func dataSourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) linkIdentifier := d.Get("link_identifier").(string) out, err := findLinkByID(ctx, conn, linkIdentifier) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameLink, linkIdentifier, err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameLink, linkIdentifier, err) } d.SetId(aws.ToString(out.Arn)) @@ -83,13 +84,13 @@ func dataSourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interf tags, err := listTags(ctx, conn, d.Id()) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameLink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameLink, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionSetting, DSNameLink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionSetting, DSNameLink, d.Id(), err) } return nil diff --git a/internal/service/oam/links_data_source.go b/internal/service/oam/links_data_source.go index 0b23185a7d8..d377c68687a 100644 --- a/internal/service/oam/links_data_source.go +++ b/internal/service/oam/links_data_source.go @@ -35,9 +35,10 @@ const ( ) func dataSourceLinksRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) - listLinksInput := &oam.ListLinksInput{} + listLinksInput := &oam.ListLinksInput{} paginator := oam.NewListLinksPaginator(conn, listLinksInput) var arns []string @@ -45,7 +46,7 @@ func dataSourceLinksRead(ctx context.Context, d *schema.ResourceData, meta inter page, err := paginator.NextPage(ctx) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameLinks, "", err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameLinks, "", err) } for _, listLinksItem := range page.Items { diff --git a/internal/service/oam/sink.go b/internal/service/oam/sink.go index 34f10ea54a2..851c5c0be5b 100644 --- a/internal/service/oam/sink.go +++ b/internal/service/oam/sink.go @@ -69,6 +69,7 @@ const ( ) func resourceSinkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) in := &oam.CreateSinkInput{ @@ -78,19 +79,20 @@ func resourceSinkCreate(ctx context.Context, d *schema.ResourceData, meta interf out, err := conn.CreateSink(ctx, in) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionCreating, ResNameSink, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionCreating, ResNameSink, d.Get(names.AttrName).(string), err) } if out == nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionCreating, ResNameSink, d.Get(names.AttrName).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionCreating, ResNameSink, d.Get(names.AttrName).(string), errors.New("empty output")) } d.SetId(aws.ToString(out.Arn)) - return resourceSinkRead(ctx, d, meta) + return append(diags, resourceSinkRead(ctx, d, meta)...) } func resourceSinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) out, err := findSinkByID(ctx, conn, d.Id()) @@ -102,7 +104,7 @@ func resourceSinkRead(ctx context.Context, d *schema.ResourceData, meta interfac } if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, ResNameSink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, ResNameSink, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -118,6 +120,7 @@ func resourceSinkUpdate(ctx context.Context, d *schema.ResourceData, meta interf } func resourceSinkDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) log.Printf("[INFO] Deleting ObservabilityAccessManager Sink %s", d.Id()) @@ -132,7 +135,7 @@ func resourceSinkDelete(ctx context.Context, d *schema.ResourceData, meta interf return nil } - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionDeleting, ResNameSink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionDeleting, ResNameSink, d.Id(), err) } return nil diff --git a/internal/service/oam/sink_data_source.go b/internal/service/oam/sink_data_source.go index dbd030f4cf0..d6b5362b00c 100644 --- a/internal/service/oam/sink_data_source.go +++ b/internal/service/oam/sink_data_source.go @@ -47,13 +47,14 @@ const ( ) func dataSourceSinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) sinkIdentifier := d.Get("sink_identifier").(string) out, err := findSinkByID(ctx, conn, sinkIdentifier) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameSink, sinkIdentifier, err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameSink, sinkIdentifier, err) } d.SetId(aws.ToString(out.Arn)) @@ -64,13 +65,13 @@ func dataSourceSinkRead(ctx context.Context, d *schema.ResourceData, meta interf tags, err := listTags(ctx, conn, d.Id()) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameSink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameSink, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionSetting, DSNameSink, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionSetting, DSNameSink, d.Id(), err) } return nil diff --git a/internal/service/oam/sink_policy.go b/internal/service/oam/sink_policy.go index 20d0b3a3e0c..3d53f6548f6 100644 --- a/internal/service/oam/sink_policy.go +++ b/internal/service/oam/sink_policy.go @@ -19,6 +19,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -76,13 +77,14 @@ const ( ) func resourceSinkPolicyPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) sinkIdentifier := d.Get("sink_identifier").(string) policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get(names.AttrPolicy).(string), err) + return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", d.Get(names.AttrPolicy).(string), err) } in := &oam.PutSinkPolicyInput{ @@ -92,17 +94,18 @@ func resourceSinkPolicyPut(ctx context.Context, d *schema.ResourceData, meta int _, err = conn.PutSinkPolicy(ctx, in) if err != nil { - return diag.Errorf("putting ObservabilityAccessManager Sink Policy (%s): %s", sinkIdentifier, err) + return sdkdiag.AppendErrorf(diags, "putting ObservabilityAccessManager Sink Policy (%s): %s", sinkIdentifier, err) } if d.IsNewResource() { d.SetId(sinkIdentifier) } - return resourceSinkPolicyRead(ctx, d, meta) + return append(diags, resourceSinkPolicyRead(ctx, d, meta)...) } func resourceSinkPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) out, err := findSinkPolicyByID(ctx, conn, d.Id()) @@ -114,7 +117,7 @@ func resourceSinkPolicyRead(ctx context.Context, d *schema.ResourceData, meta in } if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, ResNameSinkPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, ResNameSinkPolicy, d.Id(), err) } d.Set(names.AttrARN, out.SinkArn) @@ -123,7 +126,7 @@ func resourceSinkPolicyRead(ctx context.Context, d *schema.ResourceData, meta in policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), aws.ToString(out.Policy)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) diff --git a/internal/service/oam/sinks_data_source.go b/internal/service/oam/sinks_data_source.go index 73111ecb7cd..6c41275cfa5 100644 --- a/internal/service/oam/sinks_data_source.go +++ b/internal/service/oam/sinks_data_source.go @@ -35,6 +35,7 @@ const ( ) func dataSourceSinksRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx) listSinksInput := &oam.ListSinksInput{} @@ -45,7 +46,7 @@ func dataSourceSinksRead(ctx context.Context, d *schema.ResourceData, meta inter page, err := paginator.NextPage(ctx) if err != nil { - return create.DiagError(names.ObservabilityAccessManager, create.ErrActionReading, DSNameSinks, "", err) + return create.AppendDiagError(diags, names.ObservabilityAccessManager, create.ErrActionReading, DSNameSinks, "", err) } for _, listSinksItem := range page.Items { diff --git a/internal/service/opensearch/inbound_connection_accepter.go b/internal/service/opensearch/inbound_connection_accepter.go index 5f30ee6e69f..2fb8771d9ac 100644 --- a/internal/service/opensearch/inbound_connection_accepter.go +++ b/internal/service/opensearch/inbound_connection_accepter.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -55,6 +56,7 @@ func ResourceInboundConnectionAccepter() *schema.Resource { } func resourceInboundConnectionAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) connectionID := d.Get(names.AttrConnectionID).(string) @@ -65,19 +67,20 @@ func resourceInboundConnectionAccepterCreate(ctx context.Context, d *schema.Reso _, err := conn.AcceptInboundConnectionWithContext(ctx, input) if err != nil { - return diag.Errorf("accepting OpenSearch Inbound Connection (%s): %s", connectionID, err) + return sdkdiag.AppendErrorf(diags, "accepting OpenSearch Inbound Connection (%s): %s", connectionID, err) } d.SetId(connectionID) if _, err := waitInboundConnectionAccepted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Inbound Connection (%s) accept: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Inbound Connection (%s) accept: %s", d.Id(), err) } - return resourceInboundConnectionRead(ctx, d, meta) + return append(diags, resourceInboundConnectionRead(ctx, d, meta)...) } func resourceInboundConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) connection, err := FindInboundConnectionByID(ctx, conn, d.Id()) @@ -89,7 +92,7 @@ func resourceInboundConnectionRead(ctx context.Context, d *schema.ResourceData, } if err != nil { - return diag.Errorf("reading OpenSearch Inbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpenSearch Inbound Connection (%s): %s", d.Id(), err) } d.Set(names.AttrConnectionID, connection.ConnectionId) @@ -98,6 +101,7 @@ func resourceInboundConnectionRead(ctx context.Context, d *schema.ResourceData, } func resourceInboundConnectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) if d.Get("connection_status").(string) == opensearchservice.InboundConnectionStatusCodePendingAcceptance { @@ -107,11 +111,11 @@ func resourceInboundConnectionDelete(ctx context.Context, d *schema.ResourceData }) if err != nil { - return diag.Errorf("rejecting OpenSearch Inbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "rejecting OpenSearch Inbound Connection (%s): %s", d.Id(), err) } if _, err := waitInboundConnectionRejected(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Inbound Connection (%s) reject: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Inbound Connection (%s) reject: %s", d.Id(), err) } return nil @@ -127,11 +131,11 @@ func resourceInboundConnectionDelete(ctx context.Context, d *schema.ResourceData } if err != nil { - return diag.Errorf("deleting OpenSearch Inbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting OpenSearch Inbound Connection (%s): %s", d.Id(), err) } if _, err := waitInboundConnectionDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Inbound Connection (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Inbound Connection (%s) delete: %s", d.Id(), err) } return nil diff --git a/internal/service/opensearch/outbound_connection.go b/internal/service/opensearch/outbound_connection.go index 02b3e6feef8..4f08fa95a58 100644 --- a/internal/service/opensearch/outbound_connection.go +++ b/internal/service/opensearch/outbound_connection.go @@ -17,40 +17,13 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) // @SDKResource("aws_opensearch_outbound_connection") func ResourceOutboundConnection() *schema.Resource { - outboundConnectionDomainInfoSchema := func() *schema.Schema { - return &schema.Schema{ - Type: schema.TypeList, - Required: true, - ForceNew: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - names.AttrDomainName: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - names.AttrOwnerID: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - names.AttrRegion: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - }, - }, - } - } - return &schema.Resource{ CreateWithoutTimeout: resourceOutboundConnectionCreate, ReadWithoutTimeout: resourceOutboundConnectionRead, @@ -65,64 +38,95 @@ func ResourceOutboundConnection() *schema.Resource { Delete: schema.DefaultTimeout(5 * time.Minute), }, - Schema: map[string]*schema.Schema{ - "accept_connection": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - Default: false, - }, - "connection_alias": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "connection_mode": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(opensearchservice.ConnectionMode_Values(), false), - }, - "connection_properties": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "cross_cluster_search": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "skip_unavailable": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + SchemaFunc: func() map[string]*schema.Schema { + outboundConnectionDomainInfoSchema := func() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Required: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + names.AttrDomainName: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + names.AttrOwnerID: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + names.AttrRegion: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + }, + } + } + + return map[string]*schema.Schema{ + "accept_connection": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + }, + "connection_alias": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "connection_mode": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(opensearchservice.ConnectionMode_Values(), false), + }, + "connection_properties": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cross_cluster_search": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "skip_unavailable": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, }, }, - }, - names.AttrEndpoint: { - Type: schema.TypeString, - Computed: true, + names.AttrEndpoint: { + Type: schema.TypeString, + Computed: true, + }, }, }, }, - }, - "connection_status": { - Type: schema.TypeString, - Computed: true, - }, - "local_domain_info": outboundConnectionDomainInfoSchema(), - "remote_domain_info": outboundConnectionDomainInfoSchema(), + "connection_status": { + Type: schema.TypeString, + Computed: true, + }, + "local_domain_info": outboundConnectionDomainInfoSchema(), + "remote_domain_info": outboundConnectionDomainInfoSchema(), + } }, } } func resourceOutboundConnectionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) connectionAlias := d.Get("connection_alias").(string) @@ -137,13 +141,13 @@ func resourceOutboundConnectionCreate(ctx context.Context, d *schema.ResourceDat output, err := conn.CreateOutboundConnectionWithContext(ctx, input) if err != nil { - return diag.Errorf("creating OpenSearch Outbound Connection (%s): %s", connectionAlias, err) + return sdkdiag.AppendErrorf(diags, "creating OpenSearch Outbound Connection (%s): %s", connectionAlias, err) } d.SetId(aws.StringValue(output.ConnectionId)) if _, err := waitOutboundConnectionCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Outbound Connection (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Outbound Connection (%s) create: %s", d.Id(), err) } if d.Get("accept_connection").(bool) { @@ -154,18 +158,19 @@ func resourceOutboundConnectionCreate(ctx context.Context, d *schema.ResourceDat _, err := conn.AcceptInboundConnectionWithContext(ctx, input) if err != nil { - return diag.Errorf("accepting OpenSearch Inbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "accepting OpenSearch Inbound Connection (%s): %s", d.Id(), err) } if _, err := waitInboundConnectionAccepted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Inbound Connection (%s) accept: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Inbound Connection (%s) accept: %s", d.Id(), err) } } - return resourceOutboundConnectionRead(ctx, d, meta) + return append(diags, resourceOutboundConnectionRead(ctx, d, meta)...) } func resourceOutboundConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) connection, err := FindOutboundConnectionByID(ctx, conn, d.Id()) @@ -177,7 +182,7 @@ func resourceOutboundConnectionRead(ctx context.Context, d *schema.ResourceData, } if err != nil { - return diag.Errorf("reading OpenSearch Outbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpenSearch Outbound Connection (%s): %s", d.Id(), err) } d.Set("connection_alias", connection.ConnectionAlias) @@ -191,6 +196,7 @@ func resourceOutboundConnectionRead(ctx context.Context, d *schema.ResourceData, } func resourceOutboundConnectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpenSearchConn(ctx) log.Printf("[DEBUG] Deleting OpenSearch Outbound Connection: %s", d.Id()) @@ -203,11 +209,11 @@ func resourceOutboundConnectionDelete(ctx context.Context, d *schema.ResourceDat } if err != nil { - return diag.Errorf("deleting OpenSearch Outbound Connection (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting OpenSearch Outbound Connection (%s): %s", d.Id(), err) } if _, err := waitOutboundConnectionDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for OpenSearch Outbound Connection (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for OpenSearch Outbound Connection (%s) delete: %s", d.Id(), err) } return nil diff --git a/internal/service/opensearch/vpc_endpoint.go b/internal/service/opensearch/vpc_endpoint.go index 9fdff135e49..a3a3c500126 100644 --- a/internal/service/opensearch/vpc_endpoint.go +++ b/internal/service/opensearch/vpc_endpoint.go @@ -129,7 +129,7 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrEndpoint, endpoint.Endpoint) if endpoint.VpcOptions != nil { if err := d.Set("vpc_options", []interface{}{flattenVPCDerivedInfo(endpoint.VpcOptions)}); err != nil { - return diag.Errorf("setting vpc_options: %s", err) + return sdkdiag.AppendErrorf(diags, "setting vpc_options: %s", err) } } else { d.Set("vpc_options", nil) diff --git a/internal/service/opsworks/layers.go b/internal/service/opsworks/layers.go index 5b35a4b3042..4a6c964670b 100644 --- a/internal/service/opsworks/layers.go +++ b/internal/service/opsworks/layers.go @@ -19,6 +19,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfmaps "github.com/hashicorp/terraform-provider-aws/internal/maps" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -470,12 +471,13 @@ func (lt *opsworksLayerType) resourceSchema() *schema.Resource { } func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpsWorksConn(ctx) attributes, err := lt.Attributes.resourceDataToAPIAttributes(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } name := d.Get(names.AttrName).(string) @@ -559,7 +561,7 @@ func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("registering OpsWorks Layer (%s) ECS Cluster (%s): %s", name, arn, err) + return sdkdiag.AppendErrorf(diags, "registering OpsWorks Layer (%s) ECS Cluster (%s): %s", name, arn, err) } } @@ -567,7 +569,7 @@ func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, output, err := conn.CreateLayerWithContext(ctx, input) if err != nil { - return diag.Errorf("creating OpsWorks Layer (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating OpsWorks Layer (%s): %s", name, err) } d.SetId(aws.StringValue(output.LayerId)) @@ -580,7 +582,7 @@ func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("attaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) + return sdkdiag.AppendErrorf(diags, "attaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) } } @@ -591,7 +593,7 @@ func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, _, err := conn.SetLoadBasedAutoScalingWithContext(ctx, input) if err != nil { - return diag.Errorf("setting OpsWorks Layer (%s) load-based auto scaling configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "setting OpsWorks Layer (%s) load-based auto scaling configuration: %s", d.Id(), err) } } @@ -599,19 +601,20 @@ func (lt *opsworksLayerType) Create(ctx context.Context, d *schema.ResourceData, layer, err := FindLayerByID(ctx, conn, d.Id()) if err != nil { - return diag.Errorf("reading OpsWorks Layer (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpsWorks Layer (%s): %s", d.Id(), err) } arn := aws.StringValue(layer.Arn) if err := updateTags(ctx, conn, arn, nil, tags); err != nil { - return diag.Errorf("adding OpsWorks Layer (%s) tags: %s", arn, err) + return sdkdiag.AppendErrorf(diags, "adding OpsWorks Layer (%s) tags: %s", arn, err) } } - return lt.Read(ctx, d, meta) + return append(diags, lt.Read(ctx, d, meta)...) } func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpsWorksConn(ctx) layer, err := FindLayerByID(ctx, conn, d.Id()) @@ -623,7 +626,7 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m } if err != nil { - return diag.Errorf("reading OpsWorks Layer (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpsWorks Layer (%s): %s", d.Id(), err) } arn := aws.StringValue(layer.Arn) @@ -633,7 +636,7 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m d.Set("auto_healing", layer.EnableAutoHealing) if layer.CloudWatchLogsConfiguration != nil { if err := d.Set("cloudwatch_configuration", []interface{}{flattenCloudWatchLogsConfiguration(layer.CloudWatchLogsConfiguration)}); err != nil { - return diag.Errorf("setting cloudwatch_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting cloudwatch_configuration: %s", err) } } else { d.Set("cloudwatch_configuration", nil) @@ -657,7 +660,7 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m } else { policy, err := structure.NormalizeJsonString(aws.StringValue(layer.CustomJson)) if err != nil { - return diag.Errorf("policy contains an invalid JSON: %s", err) + return sdkdiag.AppendErrorf(diags, "policy contains an invalid JSON: %s", err) } d.Set("custom_json", policy) } @@ -670,7 +673,7 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m d.Set("instance_shutdown_timeout", layer.LifecycleEventConfiguration.Shutdown.ExecutionTimeout) } if err := d.Set("ebs_volume", flattenVolumeConfigurations(layer.VolumeConfigurations)); err != nil { - return diag.Errorf("setting ebs_volume: %s", err) + return sdkdiag.AppendErrorf(diags, "setting ebs_volume: %s", err) } d.Set("install_updates_on_boot", layer.InstallUpdatesOnBoot) d.Set(names.AttrName, layer.Name) @@ -682,7 +685,7 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m d.Set("use_ebs_optimized_instances", layer.UseEbsOptimizedInstances) if err := lt.Attributes.apiAttributesToResourceData(aws.StringValueMap(layer.Attributes), d); err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } loadBalancer, err := findElasticLoadBalancerByLayerID(ctx, conn, d.Id()) @@ -692,25 +695,26 @@ func (lt *opsworksLayerType) Read(ctx context.Context, d *schema.ResourceData, m } else if tfresource.NotFound(err) { d.Set("elastic_load_balancer", nil) } else { - return diag.Errorf("reading OpsWorks Layer (%s) load balancers: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpsWorks Layer (%s) load balancers: %s", d.Id(), err) } loadBasedAutoScalingConfiguration, err := findLoadBasedAutoScalingConfigurationByLayerID(ctx, conn, d.Id()) if err == nil { if err := d.Set("load_based_auto_scaling", []interface{}{flattenLoadBasedAutoScalingConfiguration(loadBasedAutoScalingConfiguration)}); err != nil { - return diag.Errorf("setting load_based_auto_scaling: %s", err) + return sdkdiag.AppendErrorf(diags, "setting load_based_auto_scaling: %s", err) } } else if tfresource.NotFound(err) { d.Set("load_based_auto_scaling", nil) } else { - return diag.Errorf("reading OpsWorks Layer (%s) load-based auto scaling configurations: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading OpsWorks Layer (%s) load-based auto scaling configurations: %s", d.Id(), err) } return nil } func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpsWorksConn(ctx) if d.HasChangesExcept("elastic_load_balancer", "load_based_auto_scaling", names.AttrTags, names.AttrTagsAll) { @@ -722,7 +726,7 @@ func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, attributes, err := lt.Attributes.resourceDataToAPIAttributes(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input.Attributes = aws.StringMap(attributes) @@ -823,7 +827,7 @@ func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, _, err := conn.UpdateLayerWithContext(ctx, input) if err != nil { - return diag.Errorf("updating OpsWorks Layer (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating OpsWorks Layer (%s): %s", d.Id(), err) } } @@ -837,7 +841,7 @@ func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("detaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) + return sdkdiag.AppendErrorf(diags, "detaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) } } @@ -848,7 +852,7 @@ func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("attaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) + return sdkdiag.AppendErrorf(diags, "attaching OpsWorks Layer (%s) load balancer (%s): %s", d.Id(), v, err) } } } @@ -860,14 +864,15 @@ func (lt *opsworksLayerType) Update(ctx context.Context, d *schema.ResourceData, _, err := conn.SetLoadBasedAutoScalingWithContext(ctx, input) if err != nil { - return diag.Errorf("setting OpsWorks Layer (%s) load-based auto scaling configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "setting OpsWorks Layer (%s) load-based auto scaling configuration: %s", d.Id(), err) } } - return lt.Read(ctx, d, meta) + return append(diags, lt.Read(ctx, d, meta)...) } func (lt *opsworksLayerType) Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OpsWorksConn(ctx) log.Printf("[DEBUG] Deleting OpsWorks Layer: %s", d.Id()) @@ -880,7 +885,7 @@ func (lt *opsworksLayerType) Delete(ctx context.Context, d *schema.ResourceData, } if err != nil { - return diag.Errorf("deleting OpsWorks Layer (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting OpsWorks Layer (%s): %s", d.Id(), err) } if v, ok := d.GetOk("ecs_cluster_arn"); ok { @@ -890,7 +895,7 @@ func (lt *opsworksLayerType) Delete(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("deregistering OpsWorks Layer (%s) ECS Cluster (%s): %s", d.Id(), arn, err) + return sdkdiag.AppendErrorf(diags, "deregistering OpsWorks Layer (%s) ECS Cluster (%s): %s", d.Id(), arn, err) } } diff --git a/internal/service/organizations/delegated_administrators_data_source.go b/internal/service/organizations/delegated_administrators_data_source.go index 65c0aba6e89..918a63b1490 100644 --- a/internal/service/organizations/delegated_administrators_data_source.go +++ b/internal/service/organizations/delegated_administrators_data_source.go @@ -14,6 +14,7 @@ import ( "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/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -74,6 +75,7 @@ func dataSourceDelegatedAdministrators() *schema.Resource { } func dataSourceDelegatedAdministratorsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) input := &organizations.ListDelegatedAdministratorsInput{} @@ -85,12 +87,12 @@ func dataSourceDelegatedAdministratorsRead(ctx context.Context, d *schema.Resour output, err := findDelegatedAdministrators(ctx, conn, input, tfslices.PredicateTrue[*awstypes.DelegatedAdministrator]()) if err != nil { - return diag.Errorf("reading Organizations Delegated Administrators: %s", err) + return sdkdiag.AppendErrorf(diags, "reading Organizations Delegated Administrators: %s", err) } d.SetId(meta.(*conns.AWSClient).AccountID) if err = d.Set("delegated_administrators", flattenDelegatedAdministrators(output)); err != nil { - return diag.Errorf("setting delegated_administrators: %s", err) + return sdkdiag.AppendErrorf(diags, "setting delegated_administrators: %s", err) } return nil diff --git a/internal/service/organizations/delegated_services_data_source.go b/internal/service/organizations/delegated_services_data_source.go index 990635a4d9c..5541184cb6d 100644 --- a/internal/service/organizations/delegated_services_data_source.go +++ b/internal/service/organizations/delegated_services_data_source.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -48,18 +49,19 @@ func dataSourceDelegatedServices() *schema.Resource { } func dataSourceDelegatedServicesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) accountID := d.Get(names.AttrAccountID).(string) output, err := findDelegatedServicesByAccountID(ctx, conn, accountID) if err != nil { - return diag.Errorf("reading Organizations Delegated Services (%s): %s", accountID, err) + return sdkdiag.AppendErrorf(diags, "reading Organizations Delegated Services (%s): %s", accountID, err) } d.SetId(meta.(*conns.AWSClient).AccountID) if err = d.Set("delegated_services", flattenDelegatedServices(output)); err != nil { - return diag.Errorf("setting delegated_services: %s", err) + return sdkdiag.AppendErrorf(diags, "setting delegated_services: %s", err) } return nil diff --git a/internal/service/organizations/policy.go b/internal/service/organizations/policy.go index 18bca2f7e15..411f2d786ad 100644 --- a/internal/service/organizations/policy.go +++ b/internal/service/organizations/policy.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -77,6 +78,7 @@ func resourcePolicy() *schema.Resource { } func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) name := d.Get(names.AttrName).(string) @@ -93,15 +95,16 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte }) if err != nil { - return diag.Errorf("creating Organizations Policy (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Organizations Policy (%s): %s", name, err) } d.SetId(aws.ToString(outputRaw.(*organizations.CreatePolicyOutput).Policy.PolicySummary.Id)) - return resourcePolicyRead(ctx, d, meta) + return append(diags, resourcePolicyRead(ctx, d, meta)...) } func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) policy, err := findPolicyByID(ctx, conn, d.Id()) @@ -113,7 +116,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf } if err != nil { - return diag.Errorf("reading Organizations Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Organizations Policy (%s): %s", d.Id(), err) } policySummary := policy.PolicySummary @@ -137,6 +140,7 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf } func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -159,14 +163,15 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte _, err := conn.UpdatePolicy(ctx, input) if err != nil { - return diag.Errorf("updating Organizations Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Organizations Policy (%s): %s", d.Id(), err) } } - return resourcePolicyRead(ctx, d, meta) + return append(diags, resourcePolicyRead(ctx, d, meta)...) } func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).OrganizationsClient(ctx) if v, ok := d.GetOk(names.AttrSkipDestroy); ok && v.(bool) { @@ -184,7 +189,7 @@ func resourcePolicyDelete(ctx context.Context, d *schema.ResourceData, meta inte } if err != nil { - return diag.Errorf("deleting Organizations Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Organizations Policy (%s): %s", d.Id(), err) } return nil diff --git a/internal/service/pipes/pipe.go b/internal/service/pipes/pipe.go index ccc87e4ad1b..be94830b983 100644 --- a/internal/service/pipes/pipe.go +++ b/internal/service/pipes/pipe.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/types" @@ -129,6 +130,7 @@ const ( ) func resourcePipeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).PipesClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) @@ -168,19 +170,20 @@ func resourcePipeCreate(ctx context.Context, d *schema.ResourceData, meta interf output, err := conn.CreatePipe(ctx, input) if err != nil { - return create.DiagError(names.Pipes, create.ErrActionCreating, ResNamePipe, name, err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionCreating, ResNamePipe, name, err) } d.SetId(aws.ToString(output.Name)) if _, err := waitPipeCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.Pipes, create.ErrActionWaitingForCreation, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionWaitingForCreation, ResNamePipe, d.Id(), err) } - return resourcePipeRead(ctx, d, meta) + return append(diags, resourcePipeRead(ctx, d, meta)...) } func resourcePipeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).PipesClient(ctx) output, err := findPipeByName(ctx, conn, d.Id()) @@ -188,11 +191,11 @@ func resourcePipeRead(ctx context.Context, d *schema.ResourceData, meta interfac if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EventBridge Pipes Pipe (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.Pipes, create.ErrActionReading, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionReading, ResNamePipe, d.Id(), err) } d.Set(names.AttrARN, output.Arn) @@ -201,14 +204,14 @@ func resourcePipeRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set("enrichment", output.Enrichment) if v := output.EnrichmentParameters; !types.IsZero(v) { if err := d.Set("enrichment_parameters", []interface{}{flattenPipeEnrichmentParameters(v)}); err != nil { - return diag.Errorf("setting enrichment_parameters: %s", err) + return sdkdiag.AppendErrorf(diags, "setting enrichment_parameters: %s", err) } } else { d.Set("enrichment_parameters", nil) } if v := output.LogConfiguration; !types.IsZero(v) { if err := d.Set("log_configuration", []interface{}{flattenPipeLogConfiguration(v)}); err != nil { - return diag.Errorf("setting log_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting log_configuration: %s", err) } } else { d.Set("log_configuration", nil) @@ -219,7 +222,7 @@ func resourcePipeRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set(names.AttrSource, output.Source) if v := output.SourceParameters; !types.IsZero(v) { if err := d.Set("source_parameters", []interface{}{flattenPipeSourceParameters(v)}); err != nil { - return diag.Errorf("setting source_parameters: %s", err) + return sdkdiag.AppendErrorf(diags, "setting source_parameters: %s", err) } } else { d.Set("source_parameters", nil) @@ -227,16 +230,17 @@ func resourcePipeRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set(names.AttrTarget, output.Target) if v := output.TargetParameters; !types.IsZero(v) { if err := d.Set("target_parameters", []interface{}{flattenPipeTargetParameters(v)}); err != nil { - return diag.Errorf("setting target_parameters: %s", err) + return sdkdiag.AppendErrorf(diags, "setting target_parameters: %s", err) } } else { d.Set("target_parameters", nil) } - return nil + return diags } func resourcePipeUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).PipesClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -283,18 +287,19 @@ func resourcePipeUpdate(ctx context.Context, d *schema.ResourceData, meta interf output, err := conn.UpdatePipe(ctx, input) if err != nil { - return create.DiagError(names.Pipes, create.ErrActionUpdating, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionUpdating, ResNamePipe, d.Id(), err) } if _, err := waitPipeUpdated(ctx, conn, aws.ToString(output.Name), d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.Pipes, create.ErrActionWaitingForUpdate, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionWaitingForUpdate, ResNamePipe, d.Id(), err) } } - return resourcePipeRead(ctx, d, meta) + return append(diags, resourcePipeRead(ctx, d, meta)...) } func resourcePipeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).PipesClient(ctx) log.Printf("[INFO] Deleting EventBridge Pipes Pipe: %s", d.Id()) @@ -303,18 +308,18 @@ func resourcePipeDelete(ctx context.Context, d *schema.ResourceData, meta interf }) if errs.IsA[*awstypes.NotFoundException](err) { - return nil + return diags } if err != nil { - return create.DiagError(names.Pipes, create.ErrActionDeleting, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionDeleting, ResNamePipe, d.Id(), err) } if _, err := waitPipeDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return create.DiagError(names.Pipes, create.ErrActionWaitingForDeletion, ResNamePipe, d.Id(), err) + return create.AppendDiagError(diags, names.Pipes, create.ErrActionWaitingForDeletion, ResNamePipe, d.Id(), err) } - return nil + return diags } func findPipeByName(ctx context.Context, conn *pipes.Client, name string) (*pipes.DescribePipeOutput, error) { diff --git a/internal/service/qldb/ledger.go b/internal/service/qldb/ledger.go index 75bec88f02c..ef52814cea5 100644 --- a/internal/service/qldb/ledger.go +++ b/internal/service/qldb/ledger.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -87,6 +88,7 @@ func resourceLedger() *schema.Resource { } func resourceLedgerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), "tf") @@ -104,19 +106,20 @@ func resourceLedgerCreate(ctx context.Context, d *schema.ResourceData, meta inte output, err := conn.CreateLedger(ctx, input) if err != nil { - return diag.Errorf("creating QLDB Ledger (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating QLDB Ledger (%s): %s", name, err) } d.SetId(aws.ToString(output.Name)) if _, err := waitLedgerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for QLDB Ledger (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for QLDB Ledger (%s) create: %s", d.Id(), err) } - return resourceLedgerRead(ctx, d, meta) + return append(diags, resourceLedgerRead(ctx, d, meta)...) } func resourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) ledger, err := findLedgerByName(ctx, conn, d.Id()) @@ -124,11 +127,11 @@ func resourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta interf if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QLDB Ledger %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading QLDB Ledger (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading QLDB Ledger (%s): %s", d.Id(), err) } d.Set(names.AttrARN, ledger.Arn) @@ -141,10 +144,11 @@ func resourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set(names.AttrName, ledger.Name) d.Set("permissions_mode", ledger.PermissionsMode) - return nil + return diags } func resourceLedgerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) if d.HasChange("permissions_mode") { @@ -154,7 +158,7 @@ func resourceLedgerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if _, err := conn.UpdateLedgerPermissionsMode(ctx, input); err != nil { - return diag.Errorf("updating QLDB Ledger (%s) permissions mode: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating QLDB Ledger (%s) permissions mode: %s", d.Id(), err) } } @@ -169,14 +173,15 @@ func resourceLedgerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if _, err := conn.UpdateLedger(ctx, input); err != nil { - return diag.Errorf("updating QLDB Ledger (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating QLDB Ledger (%s): %s", d.Id(), err) } } - return resourceLedgerRead(ctx, d, meta) + return append(diags, resourceLedgerRead(ctx, d, meta)...) } func resourceLedgerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) input := &qldb.DeleteLedgerInput{ @@ -189,18 +194,18 @@ func resourceLedgerDelete(ctx context.Context, d *schema.ResourceData, meta inte }) if errs.IsA[*types.ResourceNotFoundException](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting QLDB Ledger (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QLDB Ledger (%s): %s", d.Id(), err) } if _, err := waitLedgerDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for QLDB Ledger (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for QLDB Ledger (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findLedgerByName(ctx context.Context, conn *qldb.Client, name string) (*qldb.DescribeLedgerOutput, error) { diff --git a/internal/service/qldb/ledger_data_source.go b/internal/service/qldb/ledger_data_source.go index 46b736d966b..78cb68a0ccb 100644 --- a/internal/service/qldb/ledger_data_source.go +++ b/internal/service/qldb/ledger_data_source.go @@ -12,6 +12,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -52,6 +53,7 @@ func dataSourceLedger() *schema.Resource { } func dataSourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -59,7 +61,7 @@ func dataSourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta inte ledger, err := findLedgerByName(ctx, conn, name) if err != nil { - return diag.Errorf("reading QLDB Ledger (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading QLDB Ledger (%s): %s", name, err) } d.SetId(aws.ToString(ledger.Name)) @@ -76,12 +78,12 @@ func dataSourceLedgerRead(ctx context.Context, d *schema.ResourceData, meta inte tags, err := listTags(ctx, conn, d.Get(names.AttrARN).(string)) if err != nil { - return diag.Errorf("listing tags for QLDB Ledger (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing tags for QLDB Ledger (%s): %s", d.Id(), err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } - return nil + return diags } diff --git a/internal/service/qldb/stream.go b/internal/service/qldb/stream.go index bb7f3106d4c..9fa4af9c751 100644 --- a/internal/service/qldb/stream.go +++ b/internal/service/qldb/stream.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -109,6 +110,7 @@ func resourceStream() *schema.Resource { } func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) ledgerName := d.Get("ledger_name").(string) @@ -137,19 +139,20 @@ func resourceStreamCreate(ctx context.Context, d *schema.ResourceData, meta inte output, err := conn.StreamJournalToKinesis(ctx, input) if err != nil { - return diag.Errorf("creating QLDB Stream (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating QLDB Stream (%s): %s", name, err) } d.SetId(aws.ToString(output.StreamId)) if _, err := waitStreamCreated(ctx, conn, ledgerName, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for QLDB Stream (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for QLDB Stream (%s) create: %s", d.Id(), err) } - return resourceStreamRead(ctx, d, meta) + return append(diags, resourceStreamRead(ctx, d, meta)...) } func resourceStreamRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) ledgerName := d.Get("ledger_name").(string) @@ -158,11 +161,11 @@ func resourceStreamRead(ctx context.Context, d *schema.ResourceData, meta interf if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QLDB Stream %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading QLDB Stream (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading QLDB Stream (%s): %s", d.Id(), err) } d.Set(names.AttrARN, stream.Arn) @@ -178,7 +181,7 @@ func resourceStreamRead(ctx context.Context, d *schema.ResourceData, meta interf } if stream.KinesisConfiguration != nil { if err := d.Set("kinesis_configuration", []interface{}{flattenKinesisConfiguration(stream.KinesisConfiguration)}); err != nil { - return diag.Errorf("setting kinesis_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting kinesis_configuration: %s", err) } } else { d.Set("kinesis_configuration", nil) @@ -187,7 +190,7 @@ func resourceStreamRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set(names.AttrRoleARN, stream.RoleArn) d.Set("stream_name", stream.StreamName) - return nil + return diags } func resourceStreamUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -196,6 +199,7 @@ func resourceStreamUpdate(ctx context.Context, d *schema.ResourceData, meta inte } func resourceStreamDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QLDBClient(ctx) ledgerName := d.Get("ledger_name").(string) @@ -210,18 +214,18 @@ func resourceStreamDelete(ctx context.Context, d *schema.ResourceData, meta inte }) if errs.IsA[*types.ResourceNotFoundException](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting QLDB Stream (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QLDB Stream (%s): %s", d.Id(), err) } if _, err := waitStreamDeleted(ctx, conn, ledgerName, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for QLDB Stream (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for QLDB Stream (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findStreamByTwoPartKey(ctx context.Context, conn *qldb.Client, ledgerName, streamID string) (*types.JournalKinesisStreamDescription, error) { diff --git a/internal/service/quicksight/account_subscription.go b/internal/service/quicksight/account_subscription.go index 465f0c05bac..8dee6e088dd 100644 --- a/internal/service/quicksight/account_subscription.go +++ b/internal/service/quicksight/account_subscription.go @@ -139,6 +139,7 @@ const ( ) func resourceAccountSubscriptionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -196,23 +197,24 @@ func resourceAccountSubscriptionCreate(ctx context.Context, d *schema.ResourceDa out, err := conn.CreateAccountSubscriptionWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameAccountSubscription, d.Get("account_name").(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameAccountSubscription, d.Get("account_name").(string), err) } if out == nil || out.SignupResponse == nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameAccountSubscription, d.Get("account_name").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameAccountSubscription, d.Get("account_name").(string), errors.New("empty output")) } d.SetId(awsAccountId) if _, err := waitAccountSubscriptionCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForCreation, ResNameAccountSubscription, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForCreation, ResNameAccountSubscription, d.Id(), err) } - return resourceAccountSubscriptionRead(ctx, d, meta) + return append(diags, resourceAccountSubscriptionRead(ctx, d, meta)...) } func resourceAccountSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) out, err := FindAccountSubscriptionByID(ctx, conn, d.Id()) @@ -220,17 +222,17 @@ func resourceAccountSubscriptionRead(ctx context.Context, d *schema.ResourceData if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight AccountSubscription (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } // Ressource is logically deleted with UNSUBSCRIBED status if !d.IsNewResource() && aws.StringValue(out.AccountSubscriptionStatus) == statusUnsuscribed { log.Printf("[WARN] QuickSight AccountSubscription (%s) unsuscribed, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameAccountSubscription, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameAccountSubscription, d.Id(), err) } d.Set("account_name", out.AccountName) @@ -238,10 +240,11 @@ func resourceAccountSubscriptionRead(ctx context.Context, d *schema.ResourceData d.Set("notification_email", out.NotificationEmail) d.Set("account_subscription_status", out.AccountSubscriptionStatus) - return nil + return diags } func resourceAccountSubscriptionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) log.Printf("[INFO] Deleting QuickSight AccountSubscription %s", d.Id()) @@ -251,18 +254,18 @@ func resourceAccountSubscriptionDelete(ctx context.Context, d *schema.ResourceDa }) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameAccountSubscription, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameAccountSubscription, d.Id(), err) } if _, err := waitAccountSubscriptionDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForDeletion, ResNameAccountSubscription, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForDeletion, ResNameAccountSubscription, d.Id(), err) } - return nil + return diags } // Not documented on AWS diff --git a/internal/service/quicksight/analysis.go b/internal/service/quicksight/analysis.go index 88ef486ab81..73a909339cf 100644 --- a/internal/service/quicksight/analysis.go +++ b/internal/service/quicksight/analysis.go @@ -19,6 +19,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" quicksightschema "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight/schema" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -145,6 +146,7 @@ const ( ) func resourceAnalysisCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -180,22 +182,23 @@ func resourceAnalysisCreate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.CreateAnalysisWithContext(ctx, input) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameAnalysis, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameAnalysis, d.Get(names.AttrName).(string), err) } if _, err := waitAnalysisCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForCreation, ResNameAnalysis, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForCreation, ResNameAnalysis, d.Id(), err) } - return resourceAnalysisRead(ctx, d, meta) + return append(diags, resourceAnalysisRead(ctx, d, meta)...) } func resourceAnalysisRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, analysisId, err := ParseAnalysisId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } out, err := FindAnalysisByID(ctx, conn, d.Id()) @@ -203,18 +206,18 @@ func resourceAnalysisRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight Analysis (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } // Ressource is logically deleted with DELETED status if !d.IsNewResource() && aws.StringValue(out.Status) == quicksight.ResourceStatusDeleted { log.Printf("[WARN] QuickSight Analysis (%s) deleted, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameAnalysis, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameAnalysis, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -231,11 +234,11 @@ func resourceAnalysisRead(ctx context.Context, d *schema.ResourceData, meta inte }) if err != nil { - return diag.Errorf("describing QuickSight Analysis (%s) Definition: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Analysis (%s) Definition: %s", d.Id(), err) } if err := d.Set("definition", quicksightschema.FlattenAnalysisDefinition(descResp.Definition)); err != nil { - return diag.Errorf("setting definition: %s", err) + return sdkdiag.AppendErrorf(diags, "setting definition: %s", err) } permsResp, err := conn.DescribeAnalysisPermissionsWithContext(ctx, &quicksight.DescribeAnalysisPermissionsInput{ @@ -244,22 +247,23 @@ func resourceAnalysisRead(ctx context.Context, d *schema.ResourceData, meta inte }) if err != nil { - return diag.Errorf("describing QuickSight Analysis (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Analysis (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } func resourceAnalysisUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, analysisId, err := ParseAnalysisId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept(names.AttrPermissions, names.AttrTags, names.AttrTagsAll) { @@ -283,11 +287,11 @@ func resourceAnalysisUpdate(ctx context.Context, d *schema.ResourceData, meta in log.Printf("[DEBUG] Updating QuickSight Analysis (%s): %#v", d.Id(), in) _, err := conn.UpdateAnalysisWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameAnalysis, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameAnalysis, d.Id(), err) } if _, err := waitAnalysisUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForUpdate, ResNameAnalysis, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForUpdate, ResNameAnalysis, d.Id(), err) } } @@ -314,19 +318,20 @@ func resourceAnalysisUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err = conn.UpdateAnalysisPermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Analysis (%s) permissions: %s", analysisId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Analysis (%s) permissions: %s", analysisId, err) } } - return resourceAnalysisRead(ctx, d, meta) + return append(diags, resourceAnalysisRead(ctx, d, meta)...) } func resourceAnalysisDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, analysisId, err := ParseAnalysisId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &quicksight.DeleteAnalysisInput{ @@ -345,14 +350,14 @@ func resourceAnalysisDelete(ctx context.Context, d *schema.ResourceData, meta in _, err = conn.DeleteAnalysisWithContext(ctx, input) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameAnalysis, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameAnalysis, d.Id(), err) } - return nil + return diags } func FindAnalysisByID(ctx context.Context, conn *quicksight.QuickSight, id string) (*quicksight.Analysis, error) { diff --git a/internal/service/quicksight/dashboard.go b/internal/service/quicksight/dashboard.go index 67e5aa1f372..43db624087a 100644 --- a/internal/service/quicksight/dashboard.go +++ b/internal/service/quicksight/dashboard.go @@ -20,6 +20,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" quicksightschema "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight/schema" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -143,6 +144,7 @@ const ( ) func resourceDashboardCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -186,22 +188,23 @@ func resourceDashboardCreate(ctx context.Context, d *schema.ResourceData, meta i _, err := conn.CreateDashboardWithContext(ctx, input) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameDashboard, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameDashboard, d.Get(names.AttrName).(string), err) } if _, err := waitDashboardCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForCreation, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForCreation, ResNameDashboard, d.Id(), err) } - return resourceDashboardRead(ctx, d, meta) + return append(diags, resourceDashboardRead(ctx, d, meta)...) } func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dashboardId, err := ParseDashboardId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } out, err := FindDashboardByID(ctx, conn, d.Id(), DashboardLatestVersion) @@ -209,11 +212,11 @@ func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta int if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight Dashboard (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameDashboard, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -234,15 +237,15 @@ func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta int }) if err != nil { - return diag.Errorf("describing QuickSight Dashboard (%s) Definition: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Dashboard (%s) Definition: %s", d.Id(), err) } if err := d.Set("definition", quicksightschema.FlattenDashboardDefinition(descResp.Definition)); err != nil { - return diag.Errorf("setting definition: %s", err) + return sdkdiag.AppendErrorf(diags, "setting definition: %s", err) } if err := d.Set("dashboard_publish_options", quicksightschema.FlattenDashboardPublishOptions(descResp.DashboardPublishOptions)); err != nil { - return diag.Errorf("setting dashboard_publish_options: %s", err) + return sdkdiag.AppendErrorf(diags, "setting dashboard_publish_options: %s", err) } permsResp, err := conn.DescribeDashboardPermissionsWithContext(ctx, &quicksight.DescribeDashboardPermissionsInput{ @@ -251,22 +254,23 @@ func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta int }) if err != nil { - return diag.Errorf("describing QuickSight Dashboard (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Dashboard (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dashboardId, err := ParseDashboardId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept(names.AttrPermissions, names.AttrTags, names.AttrTagsAll) { @@ -295,12 +299,12 @@ func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta i log.Printf("[DEBUG] Updating QuickSight Dashboard (%s): %#v", d.Id(), in) out, err := conn.UpdateDashboardWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameDashboard, d.Id(), err) } updatedVersionNumber := extractVersionFromARN(aws.StringValue(out.VersionArn)) if _, err := waitDashboardUpdated(ctx, conn, d.Id(), updatedVersionNumber, d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForUpdate, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForUpdate, ResNameDashboard, d.Id(), err) } publishVersion := &quicksight.UpdateDashboardPublishedVersionInput{ @@ -310,7 +314,7 @@ func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta i } _, err = conn.UpdateDashboardPublishedVersionWithContext(ctx, publishVersion) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameDashboard, d.Id(), err) } } @@ -337,19 +341,20 @@ func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta i _, err = conn.UpdateDashboardPermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Dashboard (%s) permissions: %s", dashboardId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Dashboard (%s) permissions: %s", dashboardId, err) } } - return resourceDashboardRead(ctx, d, meta) + return append(diags, resourceDashboardRead(ctx, d, meta)...) } func resourceDashboardDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dashboardId, err := ParseDashboardId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[INFO] Deleting QuickSight Dashboard %s", d.Id()) @@ -359,14 +364,14 @@ func resourceDashboardDelete(ctx context.Context, d *schema.ResourceData, meta i }) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameDashboard, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameDashboard, d.Id(), err) } - return nil + return diags } // Pass version as DashboardLatestVersion for latest published version, or specify a specific version if required diff --git a/internal/service/quicksight/data_set.go b/internal/service/quicksight/data_set.go index 0a68788cae7..23623867ac0 100644 --- a/internal/service/quicksight/data_set.go +++ b/internal/service/quicksight/data_set.go @@ -19,6 +19,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -838,6 +839,7 @@ func physicalTableMapSchema() *schema.Resource { } func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -891,7 +893,7 @@ func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta int _, err := conn.CreateDataSetWithContext(ctx, input) if err != nil { - return diag.Errorf("creating QuickSight Data Set: %s", err) + return sdkdiag.AppendErrorf(diags, "creating QuickSight Data Set: %s", err) } if v, ok := d.GetOk("refresh_properties"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -903,19 +905,20 @@ func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta int _, err := conn.PutDataSetRefreshPropertiesWithContext(ctx, input) if err != nil { - return diag.Errorf("putting QuickSight Data Set Refresh Properties: %s", err) + return sdkdiag.AppendErrorf(diags, "putting QuickSight Data Set Refresh Properties: %s", err) } } - return resourceDataSetRead(ctx, d, meta) + return append(diags, resourceDataSetRead(ctx, d, meta)...) } func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dataSetId, err := ParseDataSetID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } descOpts := &quicksight.DescribeDataSetInput{ @@ -928,15 +931,15 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { log.Printf("[WARN] QuickSight Data Set (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("describing QuickSight Data Set (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Set (%s): %s", d.Id(), err) } if output == nil || output.DataSet == nil { - return diag.Errorf("describing QuickSight Data Set (%s): empty output", d.Id()) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Set (%s): empty output", d.Id()) } dataSet := output.DataSet @@ -948,39 +951,39 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("import_mode", dataSet.ImportMode) if err := d.Set("column_groups", flattenColumnGroups(dataSet.ColumnGroups)); err != nil { - return diag.Errorf("setting column_groups: %s", err) + return sdkdiag.AppendErrorf(diags, "setting column_groups: %s", err) } if err := d.Set("column_level_permission_rules", flattenColumnLevelPermissionRules(dataSet.ColumnLevelPermissionRules)); err != nil { - return diag.Errorf("setting column_level_permission_rules: %s", err) + return sdkdiag.AppendErrorf(diags, "setting column_level_permission_rules: %s", err) } if err := d.Set("data_set_usage_configuration", flattenDataSetUsageConfiguration(dataSet.DataSetUsageConfiguration)); err != nil { - return diag.Errorf("setting data_set_usage_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting data_set_usage_configuration: %s", err) } if err := d.Set("field_folders", flattenFieldFolders(dataSet.FieldFolders)); err != nil { - return diag.Errorf("setting field_folders: %s", err) + return sdkdiag.AppendErrorf(diags, "setting field_folders: %s", err) } if err := d.Set("logical_table_map", flattenLogicalTableMap(dataSet.LogicalTableMap, logicalTableMapSchema())); err != nil { - return diag.Errorf("setting logical_table_map: %s", err) + return sdkdiag.AppendErrorf(diags, "setting logical_table_map: %s", err) } if err := d.Set("output_columns", flattenOutputColumns(dataSet.OutputColumns)); err != nil { - return diag.Errorf("setting output_columns: %s", err) + return sdkdiag.AppendErrorf(diags, "setting output_columns: %s", err) } if err := d.Set("physical_table_map", flattenPhysicalTableMap(dataSet.PhysicalTableMap, physicalTableMapSchema())); err != nil { - return diag.Errorf("setting physical_table_map: %s", err) + return sdkdiag.AppendErrorf(diags, "setting physical_table_map: %s", err) } if err := d.Set("row_level_permission_data_set", flattenRowLevelPermissionDataSet(dataSet.RowLevelPermissionDataSet)); err != nil { - return diag.Errorf("setting row_level_permission_data_set: %s", err) + return sdkdiag.AppendErrorf(diags, "setting row_level_permission_data_set: %s", err) } if err := d.Set("row_level_permission_tag_configuration", flattenRowLevelPermissionTagConfiguration(dataSet.RowLevelPermissionTagConfiguration)); err != nil { - return diag.Errorf("setting row_level_permission_tag_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting row_level_permission_tag_configuration: %s", err) } permsResp, err := conn.DescribeDataSetPermissionsWithContext(ctx, &quicksight.DescribeDataSetPermissionsInput{ @@ -989,11 +992,11 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter }) if err != nil { - return diag.Errorf("describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } propsResp, err := conn.DescribeDataSetRefreshPropertiesWithContext(ctx, &quicksight.DescribeDataSetRefreshPropertiesInput{ @@ -1002,25 +1005,26 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter }) if err != nil && !(tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) || tfawserr.ErrMessageContains(err, quicksight.ErrCodeInvalidParameterValueException, "not a SPICE dataset")) { - return diag.Errorf("describing refresh properties (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing refresh properties (%s): %s", d.Id(), err) } if err == nil { if err := d.Set("refresh_properties", flattenRefreshProperties(propsResp.DataSetRefreshProperties)); err != nil { - return diag.Errorf("setting refresh properties: %s", err) + return sdkdiag.AppendErrorf(diags, "setting refresh properties: %s", err) } } - return nil + return diags } func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) if d.HasChangesExcept(names.AttrPermissions, names.AttrTags, names.AttrTagsAll, "refresh_properties") { awsAccountId, dataSetId, err := ParseDataSetID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } params := &quicksight.UpdateDataSetInput{ @@ -1047,14 +1051,14 @@ func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta int _, err = conn.UpdateDataSetWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Data Set (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Data Set (%s): %s", d.Id(), err) } } if d.HasChange(names.AttrPermissions) { awsAccountId, dataSetId, err := ParseDataSetID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } oraw, nraw := d.GetChange(names.AttrPermissions) @@ -1079,14 +1083,14 @@ func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta int _, err = conn.UpdateDataSetPermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Data Set (%s) permissions: %s", dataSetId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Data Set (%s) permissions: %s", dataSetId, err) } } if d.HasChange("refresh_properties") { awsAccountId, dataSetId, err := ParseDataSetID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } oldraw, newraw := d.GetChange("refresh_properties") @@ -1098,7 +1102,7 @@ func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta int DataSetId: aws.String(dataSetId), }) if err != nil { - return diag.Errorf("deleting QuickSight Data Set Refresh Properties (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QuickSight Data Set Refresh Properties (%s): %s", d.Id(), err) } } else { _, err = conn.PutDataSetRefreshPropertiesWithContext(ctx, &quicksight.PutDataSetRefreshPropertiesInput{ @@ -1107,21 +1111,22 @@ func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta int DataSetRefreshProperties: expandDataSetRefreshProperties(d.Get("refresh_properties").([]interface{})), }) if err != nil { - return diag.Errorf("updating QuickSight Data Set Refresh Properties (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Data Set Refresh Properties (%s): %s", d.Id(), err) } } } - return resourceDataSetRead(ctx, d, meta) + return append(diags, resourceDataSetRead(ctx, d, meta)...) } func resourceDataSetDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) log.Printf("[INFO] Deleting QuickSight Data Set %s", d.Id()) awsAccountId, dataSetId, err := ParseDataSetID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } deleteOpts := &quicksight.DeleteDataSetInput{ @@ -1132,14 +1137,14 @@ func resourceDataSetDelete(ctx context.Context, d *schema.ResourceData, meta int _, err = conn.DeleteDataSetWithContext(ctx, deleteOpts) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting QuickSight Data Set (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QuickSight Data Set (%s): %s", d.Id(), err) } - return nil + return diags } func expandDataSetColumnGroups(tfList []interface{}) []*quicksight.ColumnGroup { diff --git a/internal/service/quicksight/data_set_data_source.go b/internal/service/quicksight/data_set_data_source.go index a12c716a89c..327f3d2daf8 100644 --- a/internal/service/quicksight/data_set_data_source.go +++ b/internal/service/quicksight/data_set_data_source.go @@ -12,6 +12,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -615,6 +616,7 @@ const ( ) func dataSourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -632,7 +634,7 @@ func dataSourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta int output, err := conn.DescribeDataSetWithContext(ctx, descOpts) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, DSNameDataSet, dataSetId, err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, DSNameDataSet, dataSetId, err) } dataSet := output.DataSet @@ -646,52 +648,52 @@ func dataSourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("import_mode", dataSet.ImportMode) if err := d.Set("column_groups", flattenColumnGroups(dataSet.ColumnGroups)); err != nil { - return diag.Errorf("setting column_groups: %s", err) + return sdkdiag.AppendErrorf(diags, "setting column_groups: %s", err) } if err := d.Set("column_level_permission_rules", flattenColumnLevelPermissionRules(dataSet.ColumnLevelPermissionRules)); err != nil { - return diag.Errorf("setting column_level_permission_rules: %s", err) + return sdkdiag.AppendErrorf(diags, "setting column_level_permission_rules: %s", err) } if err := d.Set("data_set_usage_configuration", flattenDataSetUsageConfiguration(dataSet.DataSetUsageConfiguration)); err != nil { - return diag.Errorf("setting data_set_usage_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting data_set_usage_configuration: %s", err) } if err := d.Set("field_folders", flattenFieldFolders(dataSet.FieldFolders)); err != nil { - return diag.Errorf("setting field_folders: %s", err) + return sdkdiag.AppendErrorf(diags, "setting field_folders: %s", err) } if err := d.Set("logical_table_map", flattenLogicalTableMap(dataSet.LogicalTableMap, logicalTableMapDataSourceSchema())); err != nil { - return diag.Errorf("setting logical_table_map: %s", err) + return sdkdiag.AppendErrorf(diags, "setting logical_table_map: %s", err) } if err := d.Set("physical_table_map", flattenPhysicalTableMap(dataSet.PhysicalTableMap, physicalTableMapDataSourceSchema())); err != nil { - return diag.Errorf("setting physical_table_map: %s", err) + return sdkdiag.AppendErrorf(diags, "setting physical_table_map: %s", err) } if err := d.Set("row_level_permission_data_set", flattenRowLevelPermissionDataSet(dataSet.RowLevelPermissionDataSet)); err != nil { - return diag.Errorf("setting row_level_permission_data_set: %s", err) + return sdkdiag.AppendErrorf(diags, "setting row_level_permission_data_set: %s", err) } if err := d.Set("row_level_permission_tag_configuration", flattenRowLevelPermissionTagConfiguration(dataSet.RowLevelPermissionTagConfiguration)); err != nil { - return diag.Errorf("setting row_level_permission_tag_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting row_level_permission_tag_configuration: %s", err) } tags, err := listTags(ctx, conn, d.Get(names.AttrARN).(string)) if err != nil { - return diag.Errorf("listing tags for QuickSight Data Set (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing tags for QuickSight Data Set (%s): %s", d.Id(), err) } tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) //lintignore:AWSR002 if err := d.Set(names.AttrTags, tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } if err := d.Set(names.AttrTagsAll, tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) } permsResp, err := conn.DescribeDataSetPermissionsWithContext(ctx, &quicksight.DescribeDataSetPermissionsInput{ @@ -700,11 +702,11 @@ func dataSourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta int }) if err != nil { - return diag.Errorf("describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } diff --git a/internal/service/quicksight/data_source.go b/internal/service/quicksight/data_source.go index 802e9b3c850..ef4fea79d8f 100644 --- a/internal/service/quicksight/data_source.go +++ b/internal/service/quicksight/data_source.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -610,6 +611,7 @@ func ResourceDataSource() *schema.Resource { } func resourceDataSourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -646,24 +648,25 @@ func resourceDataSourceCreate(ctx context.Context, d *schema.ResourceData, meta _, err := conn.CreateDataSourceWithContext(ctx, params) if err != nil { - return diag.Errorf("creating QuickSight Data Source: %s", err) + return sdkdiag.AppendErrorf(diags, "creating QuickSight Data Source: %s", err) } d.SetId(fmt.Sprintf("%s/%s", awsAccountId, id)) if _, err := waitCreated(ctx, conn, awsAccountId, id); err != nil { - return diag.Errorf("waiting from QuickSight Data Source (%s) creation: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting from QuickSight Data Source (%s) creation: %s", d.Id(), err) } - return resourceDataSourceRead(ctx, d, meta) + return append(diags, resourceDataSourceRead(ctx, d, meta)...) } func resourceDataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dataSourceId, err := ParseDataSourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } descOpts := &quicksight.DescribeDataSourceInput{ @@ -676,15 +679,15 @@ func resourceDataSourceRead(ctx context.Context, d *schema.ResourceData, meta in if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { log.Printf("[WARN] QuickSight Data Source (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("describing QuickSight Data Source (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Source (%s): %s", d.Id(), err) } if output == nil || output.DataSource == nil { - return diag.Errorf("describing QuickSight Data Source (%s): empty output", d.Id()) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Source (%s): empty output", d.Id()) } dataSource := output.DataSource @@ -695,17 +698,17 @@ func resourceDataSourceRead(ctx context.Context, d *schema.ResourceData, meta in d.Set(names.AttrName, dataSource.Name) if err := d.Set(names.AttrParameters, flattenParameters(dataSource.DataSourceParameters)); err != nil { - return diag.Errorf("setting parameters: %s", err) + return sdkdiag.AppendErrorf(diags, "setting parameters: %s", err) } if err := d.Set("ssl_properties", flattenSSLProperties(dataSource.SslProperties)); err != nil { - return diag.Errorf("setting ssl_properties: %s", err) + return sdkdiag.AppendErrorf(diags, "setting ssl_properties: %s", err) } d.Set(names.AttrType, dataSource.Type) if err := d.Set("vpc_connection_properties", flattenVPCConnectionProperties(dataSource.VpcConnectionProperties)); err != nil { - return diag.Errorf("setting vpc_connection_properties: %s", err) + return sdkdiag.AppendErrorf(diags, "setting vpc_connection_properties: %s", err) } permsResp, err := conn.DescribeDataSourcePermissionsWithContext(ctx, &quicksight.DescribeDataSourcePermissionsInput{ @@ -714,23 +717,24 @@ func resourceDataSourceRead(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return diag.Errorf("describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err) } if err := d.Set("permission", flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permission: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permission: %s", err) } - return nil + return diags } func resourceDataSourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) if d.HasChangesExcept("permission", names.AttrTags, names.AttrTagsAll) { awsAccountId, dataSourceId, err := ParseDataSourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } params := &quicksight.UpdateDataSourceInput{ @@ -758,18 +762,18 @@ func resourceDataSourceUpdate(ctx context.Context, d *schema.ResourceData, meta _, err = conn.UpdateDataSourceWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Data Source (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Data Source (%s): %s", d.Id(), err) } if _, err := waitUpdated(ctx, conn, awsAccountId, dataSourceId); err != nil { - return diag.Errorf("waiting for QuickSight Data Source (%s) to update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for QuickSight Data Source (%s) to update: %s", d.Id(), err) } } if d.HasChange("permission") { awsAccountId, dataSourceId, err := ParseDataSourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } oraw, nraw := d.GetChange("permission") @@ -794,19 +798,20 @@ func resourceDataSourceUpdate(ctx context.Context, d *schema.ResourceData, meta _, err = conn.UpdateDataSourcePermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Data Source (%s) permissions: %s", dataSourceId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Data Source (%s) permissions: %s", dataSourceId, err) } } - return resourceDataSourceRead(ctx, d, meta) + return append(diags, resourceDataSourceRead(ctx, d, meta)...) } func resourceDataSourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, dataSourceId, err := ParseDataSourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } deleteOpts := &quicksight.DeleteDataSourceInput{ @@ -817,14 +822,14 @@ func resourceDataSourceDelete(ctx context.Context, d *schema.ResourceData, meta _, err = conn.DeleteDataSourceWithContext(ctx, deleteOpts) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting QuickSight Data Source (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QuickSight Data Source (%s): %s", d.Id(), err) } - return nil + return diags } func expandDataSourceCredentials(tfList []interface{}) *quicksight.DataSourceCredentials { diff --git a/internal/service/quicksight/folder.go b/internal/service/quicksight/folder.go index dd4b0e969c2..ca73c73dfba 100644 --- a/internal/service/quicksight/folder.go +++ b/internal/service/quicksight/folder.go @@ -20,6 +20,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -137,6 +138,7 @@ const ( ) func resourceFolderCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -169,33 +171,34 @@ func resourceFolderCreate(ctx context.Context, d *schema.ResourceData, meta inte out, err := conn.CreateFolderWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameFolder, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameFolder, d.Get(names.AttrName).(string), err) } if out == nil || out.Arn == nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameFolder, d.Get(names.AttrName).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameFolder, d.Get(names.AttrName).(string), errors.New("empty output")) } - return resourceFolderRead(ctx, d, meta) + return append(diags, resourceFolderRead(ctx, d, meta)...) } func resourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, folderId, err := ParseFolderId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } out, err := FindFolderByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight Folder (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameFolder, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameFolder, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -211,7 +214,7 @@ func resourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interf } if err := d.Set("folder_path", flex.FlattenStringList(out.FolderPath)); err != nil { - return diag.Errorf("setting folder_path: %s", err) + return sdkdiag.AppendErrorf(diags, "setting folder_path: %s", err) } permsResp, err := conn.DescribeFolderPermissionsWithContext(ctx, &quicksight.DescribeFolderPermissionsInput{ @@ -220,21 +223,22 @@ func resourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interf }) if err != nil { - return diag.Errorf("describing QuickSight Folder (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Folder (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } func resourceFolderUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, folderId, err := ParseFolderId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept("permission", names.AttrTags, names.AttrTagsAll) { @@ -247,7 +251,7 @@ func resourceFolderUpdate(ctx context.Context, d *schema.ResourceData, meta inte log.Printf("[DEBUG] Updating QuickSight Folder (%s): %#v", d.Id(), in) _, err = conn.UpdateFolderWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameFolder, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameFolder, d.Id(), err) } } @@ -274,21 +278,22 @@ func resourceFolderUpdate(ctx context.Context, d *schema.ResourceData, meta inte _, err = conn.UpdateFolderPermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Folder (%s) permissions: %s", folderId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Folder (%s) permissions: %s", folderId, err) } } - return resourceFolderRead(ctx, d, meta) + return append(diags, resourceFolderRead(ctx, d, meta)...) } func resourceFolderDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) log.Printf("[INFO] Deleting QuickSight Folder %s", d.Id()) awsAccountId, folderId, err := ParseFolderId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } _, err = conn.DeleteFolderWithContext(ctx, &quicksight.DeleteFolderInput{ @@ -297,14 +302,14 @@ func resourceFolderDelete(ctx context.Context, d *schema.ResourceData, meta inte }) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameFolder, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameFolder, d.Id(), err) } - return nil + return diags } func FindFolderByID(ctx context.Context, conn *quicksight.QuickSight, id string) (*quicksight.Folder, error) { diff --git a/internal/service/quicksight/group_membership.go b/internal/service/quicksight/group_membership.go index 92fd3c1605c..faac3ad5127 100644 --- a/internal/service/quicksight/group_membership.go +++ b/internal/service/quicksight/group_membership.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -69,6 +70,7 @@ func ResourceGroupMembership() *schema.Resource { } func resourceGroupMembershipCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountID := meta.(*conns.AWSClient).AccountID @@ -89,20 +91,21 @@ func resourceGroupMembershipCreate(ctx context.Context, d *schema.ResourceData, resp, err := conn.CreateGroupMembershipWithContext(ctx, createOpts) if err != nil { - return diag.Errorf("adding QuickSight user (%s) to group (%s): %s", memberName, groupName, err) + return sdkdiag.AppendErrorf(diags, "adding QuickSight user (%s) to group (%s): %s", memberName, groupName, err) } d.SetId(fmt.Sprintf("%s/%s/%s/%s", awsAccountID, namespace, groupName, aws.StringValue(resp.GroupMember.MemberName))) - return resourceGroupMembershipRead(ctx, d, meta) + return append(diags, resourceGroupMembershipRead(ctx, d, meta)...) } func resourceGroupMembershipRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountID, namespace, groupName, userName, err := GroupMembershipParseID(d.Id()) if err != nil { - return diag.Errorf("%s", err) + return sdkdiag.AppendErrorf(diags, "%s", err) } listInput := &quicksight.ListGroupMembershipsInput{ @@ -113,13 +116,13 @@ func resourceGroupMembershipRead(ctx context.Context, d *schema.ResourceData, me found, err := FindGroupMembership(ctx, conn, listInput, userName) if err != nil { - return diag.Errorf("listing QuickSight Group Memberships (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing QuickSight Group Memberships (%s): %s", d.Id(), err) } if !d.IsNewResource() && !found { log.Printf("[WARN] QuickSight User-group membership (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } d.Set(names.AttrAWSAccountID, awsAccountID) @@ -127,15 +130,16 @@ func resourceGroupMembershipRead(ctx context.Context, d *schema.ResourceData, me d.Set("member_name", userName) d.Set(names.AttrGroupName, groupName) - return nil + return diags } func resourceGroupMembershipDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountID, namespace, groupName, userName, err := GroupMembershipParseID(d.Id()) if err != nil { - return diag.Errorf("%s", err) + return sdkdiag.AppendErrorf(diags, "%s", err) } deleteOpts := &quicksight.DeleteGroupMembershipInput{ @@ -147,12 +151,12 @@ func resourceGroupMembershipDelete(ctx context.Context, d *schema.ResourceData, if _, err := conn.DeleteGroupMembershipWithContext(ctx, deleteOpts); err != nil { if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } - return diag.Errorf("deleting QuickSight User-group membership %s: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting QuickSight User-group membership %s: %s", d.Id(), err) } - return nil + return diags } func GroupMembershipParseID(id string) (string, string, string, string, error) { diff --git a/internal/service/quicksight/template.go b/internal/service/quicksight/template.go index 4296d991027..160362ec6d7 100644 --- a/internal/service/quicksight/template.go +++ b/internal/service/quicksight/template.go @@ -19,6 +19,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" quicksightschema "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight/schema" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -131,6 +132,7 @@ const ( ) func resourceTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -166,22 +168,23 @@ func resourceTemplateCreate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.CreateTemplateWithContext(ctx, input) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameTemplate, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameTemplate, d.Get(names.AttrName).(string), err) } if _, err := waitTemplateCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForCreation, ResNameTemplate, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForCreation, ResNameTemplate, d.Id(), err) } - return resourceTemplateRead(ctx, d, meta) + return append(diags, resourceTemplateRead(ctx, d, meta)...) } func resourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, templateId, err := ParseTemplateId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } out, err := FindTemplateByID(ctx, conn, d.Id()) @@ -189,11 +192,11 @@ func resourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight Template (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameTemplate, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameTemplate, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -214,11 +217,11 @@ func resourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta inte }) if err != nil { - return diag.Errorf("describing QuickSight Template (%s) Definition: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Template (%s) Definition: %s", d.Id(), err) } if err := d.Set("definition", quicksightschema.FlattenTemplateDefinition(descResp.Definition)); err != nil { - return diag.Errorf("setting definition: %s", err) + return sdkdiag.AppendErrorf(diags, "setting definition: %s", err) } permsResp, err := conn.DescribeTemplatePermissionsWithContext(ctx, &quicksight.DescribeTemplatePermissionsInput{ @@ -227,22 +230,23 @@ func resourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta inte }) if err != nil { - return diag.Errorf("describing QuickSight Template (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Template (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } func resourceTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, templateId, err := ParseTemplateId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept(names.AttrPermissions, names.AttrTags, names.AttrTagsAll) { @@ -263,11 +267,11 @@ func resourceTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta in log.Printf("[DEBUG] Updating QuickSight Template (%s): %#v", d.Id(), in) _, err := conn.UpdateTemplateWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameTemplate, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameTemplate, d.Id(), err) } if _, err := waitTemplateUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForUpdate, ResNameTemplate, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForUpdate, ResNameTemplate, d.Id(), err) } } @@ -294,19 +298,20 @@ func resourceTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err = conn.UpdateTemplatePermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Template (%s) permissions: %s", templateId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Template (%s) permissions: %s", templateId, err) } } - return resourceTemplateRead(ctx, d, meta) + return append(diags, resourceTemplateRead(ctx, d, meta)...) } func resourceTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, templateId, err := ParseTemplateId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[INFO] Deleting QuickSight Template %s", d.Id()) @@ -316,14 +321,14 @@ func resourceTemplateDelete(ctx context.Context, d *schema.ResourceData, meta in }) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameTemplate, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameTemplate, d.Id(), err) } - return nil + return diags } func FindTemplateByID(ctx context.Context, conn *quicksight.QuickSight, id string) (*quicksight.Template, error) { diff --git a/internal/service/quicksight/theme.go b/internal/service/quicksight/theme.go index fa27c786bf9..44318d83302 100644 --- a/internal/service/quicksight/theme.go +++ b/internal/service/quicksight/theme.go @@ -20,6 +20,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -350,6 +351,7 @@ const ( ) func resourceThemeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -382,22 +384,23 @@ func resourceThemeCreate(ctx context.Context, d *schema.ResourceData, meta inter _, err := conn.CreateThemeWithContext(ctx, input) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionCreating, ResNameTheme, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionCreating, ResNameTheme, d.Get(names.AttrName).(string), err) } if _, err := waitThemeCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForCreation, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForCreation, ResNameTheme, d.Id(), err) } - return resourceThemeRead(ctx, d, meta) + return append(diags, resourceThemeRead(ctx, d, meta)...) } func resourceThemeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, themeId, err := ParseThemeId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } out, err := FindThemeByID(ctx, conn, d.Id()) @@ -405,11 +408,11 @@ func resourceThemeRead(ctx context.Context, d *schema.ResourceData, meta interfa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] QuickSight Theme (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameTheme, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -424,7 +427,7 @@ func resourceThemeRead(ctx context.Context, d *schema.ResourceData, meta interfa d.Set("version_number", out.Version.VersionNumber) if err := d.Set(names.AttrConfiguration, flattenThemeConfiguration(out.Version.Configuration)); err != nil { - return diag.Errorf("setting configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) } permsResp, err := conn.DescribeThemePermissionsWithContext(ctx, &quicksight.DescribeThemePermissionsInput{ @@ -433,22 +436,23 @@ func resourceThemeRead(ctx context.Context, d *schema.ResourceData, meta interfa }) if err != nil { - return diag.Errorf("describing QuickSight Theme (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Theme (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } func resourceThemeUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, themeId, err := ParseThemeId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept(names.AttrPermissions, names.AttrTags, names.AttrTagsAll) { @@ -466,11 +470,11 @@ func resourceThemeUpdate(ctx context.Context, d *schema.ResourceData, meta inter log.Printf("[DEBUG] Updating QuickSight Theme (%s): %#v", d.Id(), in) _, err := conn.UpdateThemeWithContext(ctx, in) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionUpdating, ResNameTheme, d.Id(), err) } if _, err := waitThemeUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.QuickSight, create.ErrActionWaitingForUpdate, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionWaitingForUpdate, ResNameTheme, d.Id(), err) } } @@ -497,19 +501,20 @@ func resourceThemeUpdate(ctx context.Context, d *schema.ResourceData, meta inter _, err = conn.UpdateThemePermissionsWithContext(ctx, params) if err != nil { - return diag.Errorf("updating QuickSight Theme (%s) permissions: %s", themeId, err) + return sdkdiag.AppendErrorf(diags, "updating QuickSight Theme (%s) permissions: %s", themeId, err) } } - return resourceThemeRead(ctx, d, meta) + return append(diags, resourceThemeRead(ctx, d, meta)...) } func resourceThemeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId, themeId, err := ParseThemeId(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &quicksight.DeleteThemeInput{ @@ -521,14 +526,14 @@ func resourceThemeDelete(ctx context.Context, d *schema.ResourceData, meta inter _, err = conn.DeleteThemeWithContext(ctx, input) if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionDeleting, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionDeleting, ResNameTheme, d.Id(), err) } - return nil + return diags } func FindThemeByID(ctx context.Context, conn *quicksight.QuickSight, id string) (*quicksight.Theme, error) { diff --git a/internal/service/quicksight/theme_data_source.go b/internal/service/quicksight/theme_data_source.go index ad837303668..7a3e2089966 100644 --- a/internal/service/quicksight/theme_data_source.go +++ b/internal/service/quicksight/theme_data_source.go @@ -13,6 +13,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -281,6 +282,7 @@ const ( ) func dataSourceThemeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).QuickSightConn(ctx) awsAccountId := meta.(*conns.AWSClient).AccountID @@ -294,7 +296,7 @@ func dataSourceThemeRead(ctx context.Context, d *schema.ResourceData, meta inter out, err := FindThemeByID(ctx, conn, id) if err != nil { - return create.DiagError(names.QuickSight, create.ErrActionReading, ResNameTheme, d.Id(), err) + return create.AppendDiagError(diags, names.QuickSight, create.ErrActionReading, ResNameTheme, d.Id(), err) } d.SetId(id) @@ -310,7 +312,7 @@ func dataSourceThemeRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("version_number", out.Version.VersionNumber) if err := d.Set(names.AttrConfiguration, flattenThemeConfiguration(out.Version.Configuration)); err != nil { - return diag.Errorf("setting configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) } permsResp, err := conn.DescribeThemePermissionsWithContext(ctx, &quicksight.DescribeThemePermissionsInput{ @@ -319,12 +321,12 @@ func dataSourceThemeRead(ctx context.Context, d *schema.ResourceData, meta inter }) if err != nil { - return diag.Errorf("describing QuickSight Theme (%s) Permissions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "describing QuickSight Theme (%s) Permissions: %s", d.Id(), err) } if err := d.Set(names.AttrPermissions, flattenPermissions(permsResp.Permissions)); err != nil { - return diag.Errorf("setting permissions: %s", err) + return sdkdiag.AppendErrorf(diags, "setting permissions: %s", err) } - return nil + return diags } diff --git a/internal/service/rbin/rule.go b/internal/service/rbin/rule.go index b0b53e240be..22829f9ed59 100644 --- a/internal/service/rbin/rule.go +++ b/internal/service/rbin/rule.go @@ -159,6 +159,7 @@ const ( ) func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RBinClient(ctx) in := &rbin.CreateRuleInput{ @@ -177,23 +178,24 @@ func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interf out, err := conn.CreateRule(ctx, in) if err != nil { - return create.DiagError(names.RBin, create.ErrActionCreating, ResNameRule, d.Get(names.AttrResourceType).(string), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionCreating, ResNameRule, d.Get(names.AttrResourceType).(string), err) } if out == nil || out.Identifier == nil { - return create.DiagError(names.RBin, create.ErrActionCreating, ResNameRule, d.Get(names.AttrResourceType).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.RBin, create.ErrActionCreating, ResNameRule, d.Get(names.AttrResourceType).(string), errors.New("empty output")) } d.SetId(aws.ToString(out.Identifier)) if _, err := waitRuleCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.RBin, create.ErrActionWaitingForCreation, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionWaitingForCreation, ResNameRule, d.Id(), err) } - return resourceRuleRead(ctx, d, meta) + return append(diags, resourceRuleRead(ctx, d, meta)...) } func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RBinClient(ctx) out, err := findRuleByID(ctx, conn, d.Id()) @@ -201,11 +203,11 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RBin Rule (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.RBin, create.ErrActionReading, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionReading, ResNameRule, d.Id(), err) } ruleArn := awsarn.ARN{ @@ -222,17 +224,18 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set(names.AttrStatus, string(out.Status)) if err := d.Set(names.AttrResourceTags, flattenResourceTags(out.ResourceTags)); err != nil { - return create.DiagError(names.RBin, create.ErrActionSetting, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionSetting, ResNameRule, d.Id(), err) } if err := d.Set(names.AttrRetentionPeriod, flattenRetentionPeriod(out.RetentionPeriod)); err != nil { - return create.DiagError(names.RBin, create.ErrActionSetting, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionSetting, ResNameRule, d.Id(), err) } - return nil + return diags } func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RBinClient(ctx) update := false @@ -257,27 +260,27 @@ func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interf } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating RBin Rule (%s): %#v", d.Id(), in) out, err := conn.UpdateRule(ctx, in) if err != nil { - return create.DiagError(names.RBin, create.ErrActionUpdating, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionUpdating, ResNameRule, d.Id(), err) } if _, err := waitRuleUpdated(ctx, conn, aws.ToString(out.Identifier), d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.RBin, create.ErrActionWaitingForUpdate, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionWaitingForUpdate, ResNameRule, d.Id(), err) } - return resourceRuleRead(ctx, d, meta) + return append(diags, resourceRuleRead(ctx, d, meta)...) } func resourceRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - log.Printf("[INFO] Deleting RBin Rule %s", d.Id()) - + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RBinClient(ctx) + log.Printf("[INFO] Deleting RBin Rule: %s", d.Id()) _, err := conn.DeleteRule(ctx, &rbin.DeleteRuleInput{ Identifier: aws.String(d.Id()), }) @@ -285,17 +288,17 @@ func resourceRuleDelete(ctx context.Context, d *schema.ResourceData, meta interf if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.RBin, create.ErrActionDeleting, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionDeleting, ResNameRule, d.Id(), err) } if _, err := waitRuleDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return create.DiagError(names.RBin, create.ErrActionWaitingForDeletion, ResNameRule, d.Id(), err) + return create.AppendDiagError(diags, names.RBin, create.ErrActionWaitingForDeletion, ResNameRule, d.Id(), err) } - return nil + return diags } func waitRuleCreated(ctx context.Context, conn *rbin.Client, id string, timeout time.Duration) (*rbin.GetRuleOutput, error) { diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 7f4a888fc23..a7bc7b55197 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -1160,7 +1160,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RDS Cluster (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { @@ -1283,7 +1283,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter setTagsOut(ctx, dbc.TagList) - return nil + return diags } func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) { @@ -1618,7 +1618,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int ) if tfawserr.ErrCodeEquals(err, rds.ErrCodeDBClusterNotFoundFault) { - return nil + return diags } if err != nil { @@ -1629,7 +1629,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "waiting for RDS Cluster (%s) delete: %s", d.Id(), err) } - return nil + return diags } func resourceClusterImport(_ context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { diff --git a/internal/service/rds/cluster_activity_stream.go b/internal/service/rds/cluster_activity_stream.go index 05f2af56853..affd3ea4228 100644 --- a/internal/service/rds/cluster_activity_stream.go +++ b/internal/service/rds/cluster_activity_stream.go @@ -15,6 +15,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -64,6 +65,7 @@ func ResourceClusterActivityStream() *schema.Resource { } func resourceClusterActivityStreamCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) arn := d.Get(names.AttrResourceARN).(string) @@ -76,20 +78,22 @@ func resourceClusterActivityStreamCreate(ctx context.Context, d *schema.Resource } _, err := conn.StartActivityStreamWithContext(ctx, input) + if err != nil { - return diag.Errorf("creating RDS Cluster Activity Stream (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "creating RDS Cluster Activity Stream (%s): %s", arn, err) } d.SetId(arn) if err := waitActivityStreamStarted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for RDS Cluster Activity Stream (%s) start: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for RDS Cluster Activity Stream (%s) start: %s", d.Id(), err) } - return resourceClusterActivityStreamRead(ctx, d, meta) + return append(diags, resourceClusterActivityStreamRead(ctx, d, meta)...) } func resourceClusterActivityStreamRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) output, err := FindDBClusterWithActivityStream(ctx, conn, d.Id()) @@ -97,11 +101,11 @@ func resourceClusterActivityStreamRead(ctx context.Context, d *schema.ResourceDa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RDS Cluster Activity Stream (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading RDS Cluster Activity Stream (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading RDS Cluster Activity Stream (%s): %s", d.Id(), err) } d.Set("kinesis_stream_name", output.ActivityStreamKinesisStreamName) @@ -109,10 +113,11 @@ func resourceClusterActivityStreamRead(ctx context.Context, d *schema.ResourceDa d.Set(names.AttrMode, output.ActivityStreamMode) d.Set(names.AttrResourceARN, output.DBClusterArn) - return nil + return diags } func resourceClusterActivityStreamDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) log.Printf("[DEBUG] Deleting RDS Cluster Activity Stream: %s", d.Id()) @@ -121,14 +126,14 @@ func resourceClusterActivityStreamDelete(ctx context.Context, d *schema.Resource ResourceArn: aws.String(d.Id()), }) if err != nil { - return diag.Errorf("stopping RDS Cluster Activity Stream (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "stopping RDS Cluster Activity Stream (%s): %s", d.Id(), err) } if err := waitActivityStreamStopped(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for RDS Cluster Activity Stream (%s) stop: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for RDS Cluster Activity Stream (%s) stop: %s", d.Id(), err) } - return nil + return diags } func FindDBClusterWithActivityStream(ctx context.Context, conn *rds.RDS, arn string) (*rds.DBCluster, error) { diff --git a/internal/service/rds/cluster_instance.go b/internal/service/rds/cluster_instance.go index 6fb22394f04..d91da2ae775 100644 --- a/internal/service/rds/cluster_instance.go +++ b/internal/service/rds/cluster_instance.go @@ -363,7 +363,7 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RDS Cluster Instance (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { return sdkdiag.AppendErrorf(diags, "reading RDS Cluster Instance (%s): %s", d.Id(), err) @@ -430,7 +430,7 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me setTagsOut(ctx, db.TagList) - return nil + return diags } func resourceClusterInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) { @@ -538,7 +538,7 @@ func resourceClusterInstanceDelete(ctx context.Context, d *schema.ResourceData, rds.ErrCodeInvalidDBClusterStateFault, "Delete the replica cluster before deleting") if tfawserr.ErrCodeEquals(err, rds.ErrCodeDBInstanceNotFoundFault) { - return nil + return diags } if err != nil && !tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBInstanceStateFault, "is already being deleted") { @@ -549,7 +549,7 @@ func resourceClusterInstanceDelete(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "waiting for RDS Cluster Instance (%s) delete: %s", d.Id(), err) } - return nil + return diags } func clusterSetResourceDataEngineVersionFromClusterInstance(d *schema.ResourceData, c *rds.DBInstance) { diff --git a/internal/service/rds/cluster_snapshot.go b/internal/service/rds/cluster_snapshot.go index 39bc54ee35d..188112ec12f 100644 --- a/internal/service/rds/cluster_snapshot.go +++ b/internal/service/rds/cluster_snapshot.go @@ -161,7 +161,7 @@ func resourceClusterSnapshotRead(ctx context.Context, d *schema.ResourceData, me if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RDS DB Cluster Snapshot (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/rds/clusters_data_source.go b/internal/service/rds/clusters_data_source.go index a13a08d384b..f56fbccf486 100644 --- a/internal/service/rds/clusters_data_source.go +++ b/internal/service/rds/clusters_data_source.go @@ -42,6 +42,7 @@ const ( ) func dataSourceClustersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) input := &rds.DescribeDBClustersInput{} @@ -70,12 +71,12 @@ func dataSourceClustersRead(ctx context.Context, d *schema.ResourceData, meta in return !lastPage }) if err != nil { - return create.DiagError(names.RDS, create.ErrActionReading, DSNameClusters, "", err) + return create.AppendDiagError(diags, names.RDS, create.ErrActionReading, DSNameClusters, "", err) } d.SetId(meta.(*conns.AWSClient).Region) d.Set("cluster_arns", clusterArns) d.Set("cluster_identifiers", clusterIdentifiers) - return nil + return diags } diff --git a/internal/service/rds/custom_db_engine_version.go b/internal/service/rds/custom_db_engine_version.go index 4838b5a0619..b0b74e24646 100644 --- a/internal/service/rds/custom_db_engine_version.go +++ b/internal/service/rds/custom_db_engine_version.go @@ -23,6 +23,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -204,7 +205,7 @@ func resourceCustomDBEngineVersionCreate(ctx context.Context, d *schema.Resource defer conns.GlobalMutexKV.Unlock(cevMutexKey) file, err := resourceCustomDBEngineVersionLoadFileContent(filename) if err != nil { - return diag.Errorf("unable to load %q: %s", filename, err) + return sdkdiag.AppendErrorf(diags, "unable to load %q: %s", filename, err) } input.Manifest = aws.String(file) } else if v, ok := d.GetOk("manifest"); ok { @@ -213,13 +214,13 @@ func resourceCustomDBEngineVersionCreate(ctx context.Context, d *schema.Resource output, err := conn.CreateCustomDBEngineVersionWithContext(ctx, &input) if err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionCreating, ResNameCustomDBEngineVersion, fmt.Sprintf("%s:%s", aws.StringValue(output.Engine), aws.StringValue(output.EngineVersion)), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionCreating, ResNameCustomDBEngineVersion, fmt.Sprintf("%s:%s", aws.StringValue(output.Engine), aws.StringValue(output.EngineVersion)), err) } d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(output.Engine), aws.StringValue(output.EngineVersion))) if _, err := waitCustomDBEngineVersionCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionWaitingForCreation, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionWaitingForCreation, ResNameCustomDBEngineVersion, d.Id(), err) } return append(diags, resourceCustomDBEngineVersionRead(ctx, d, meta)...) @@ -237,7 +238,7 @@ func resourceCustomDBEngineVersionRead(ctx context.Context, d *schema.ResourceDa } if err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionReading, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionReading, ResNameCustomDBEngineVersion, d.Id(), err) } d.Set(names.AttrARN, out.DBEngineVersionArn) @@ -266,13 +267,13 @@ func resourceCustomDBEngineVersionUpdate(ctx context.Context, d *schema.Resource conn := meta.(*conns.AWSClient).RDSConn(ctx) if d.HasChangesExcept(names.AttrDescription, names.AttrStatus) { - return append(diags, create.DiagError(names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), errors.New("only description and status can be updated"))...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), errors.New("only description and status can be updated")) } update := false engine, engineVersion, e := customEngineVersionParseID(d.Id()) if e != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), e)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), e) } input := &rds.ModifyCustomDBEngineVersionInput{ Engine: aws.String(engine), @@ -295,14 +296,14 @@ func resourceCustomDBEngineVersionUpdate(ctx context.Context, d *schema.Resource log.Printf("[DEBUG] Updating RDS CustomDBEngineVersion (%s): %#v", d.Id(), input) output, err := conn.ModifyCustomDBEngineVersionWithContext(ctx, input) if err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), err) } if output == nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), errors.New("empty output"))...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), errors.New("empty output")) } if _, err := waitCustomDBEngineVersionUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionWaitingForUpdate, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionWaitingForUpdate, ResNameCustomDBEngineVersion, d.Id(), err) } return append(diags, resourceCustomDBEngineVersionRead(ctx, d, meta)...) @@ -316,7 +317,7 @@ func resourceCustomDBEngineVersionDelete(ctx context.Context, d *schema.Resource engine, engineVersion, e := customEngineVersionParseID(d.Id()) if e != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), e)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionUpdating, ResNameCustomDBEngineVersion, d.Id(), e) } _, err := conn.DeleteCustomDBEngineVersionWithContext(ctx, &rds.DeleteCustomDBEngineVersionInput{ Engine: aws.String(engine), @@ -328,11 +329,11 @@ func resourceCustomDBEngineVersionDelete(ctx context.Context, d *schema.Resource } if err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionDeleting, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionDeleting, ResNameCustomDBEngineVersion, d.Id(), err) } if _, err := waitCustomDBEngineVersionDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return append(diags, create.DiagError(names.RDS, create.ErrActionWaitingForDeletion, ResNameCustomDBEngineVersion, d.Id(), err)...) + return create.AppendDiagError(diags, names.RDS, create.ErrActionWaitingForDeletion, ResNameCustomDBEngineVersion, d.Id(), err) } return diags diff --git a/internal/service/rds/instance.go b/internal/service/rds/instance.go index 697fd87fc08..834de44196d 100644 --- a/internal/service/rds/instance.go +++ b/internal/service/rds/instance.go @@ -1824,7 +1824,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte if tfresource.NotFound(err) { log.Printf("[WARN] RDS DB Instance (%s) not found, removing from state", d.Get(names.AttrIdentifier).(string)) d.SetId("") - return nil + return diags } } } @@ -2518,7 +2518,7 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in } if tfawserr.ErrCodeEquals(err, rds.ErrCodeDBInstanceNotFoundFault) { - return nil + return diags } if err != nil && !tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBInstanceStateFault, "is already being deleted") { @@ -2529,7 +2529,7 @@ func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "waiting for RDS DB Instance (%s) delete: %s", d.Get(names.AttrIdentifier).(string), err) } - return nil + return diags } func resourceInstanceImport(_ context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { diff --git a/internal/service/rds/parameter_group.go b/internal/service/rds/parameter_group.go index 56d433437dd..b870ffe2bc6 100644 --- a/internal/service/rds/parameter_group.go +++ b/internal/service/rds/parameter_group.go @@ -339,7 +339,7 @@ func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, m if err != nil { return sdkdiag.AppendErrorf(diags, "deleting RDS DB Parameter Group (%s): %s", d.Id(), err) } - return nil + return diags } func FindDBParameterGroupByName(ctx context.Context, conn *rds.RDS, name string) (*rds.DBParameterGroup, error) { diff --git a/internal/service/rds/parameter_group_data_source.go b/internal/service/rds/parameter_group_data_source.go index 4370aadfd04..5fecde68904 100644 --- a/internal/service/rds/parameter_group_data_source.go +++ b/internal/service/rds/parameter_group_data_source.go @@ -68,5 +68,5 @@ func dataSourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, m d.Set(names.AttrFamily, output.DBParameterGroups[0].DBParameterGroupFamily) d.Set(names.AttrDescription, output.DBParameterGroups[0].Description) - return nil + return diags } diff --git a/internal/service/rds/reserved_instance.go b/internal/service/rds/reserved_instance.go index 2ce2bf0b5c7..45cc771a626 100644 --- a/internal/service/rds/reserved_instance.go +++ b/internal/service/rds/reserved_instance.go @@ -133,6 +133,7 @@ func ResourceReservedInstance() *schema.Resource { } func resourceReservedInstanceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) input := &rds.PurchaseReservedDBInstancesOfferingInput{ @@ -150,19 +151,20 @@ func resourceReservedInstanceCreate(ctx context.Context, d *schema.ResourceData, resp, err := conn.PurchaseReservedDBInstancesOfferingWithContext(ctx, input) if err != nil { - return create.DiagError(names.RDS, create.ErrActionCreating, ResNameReservedInstance, fmt.Sprintf("offering_id: %s, reservation_id: %s", d.Get("offering_id").(string), d.Get("reservation_id").(string)), err) + return create.AppendDiagError(diags, names.RDS, create.ErrActionCreating, ResNameReservedInstance, fmt.Sprintf("offering_id: %s, reservation_id: %s", d.Get("offering_id").(string), d.Get("reservation_id").(string)), err) } d.SetId(aws.ToString(resp.ReservedDBInstance.ReservedDBInstanceId)) if err := waitReservedInstanceCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.RDS, create.ErrActionWaitingForCreation, ResNameReservedInstance, d.Id(), err) + return create.AppendDiagError(diags, names.RDS, create.ErrActionWaitingForCreation, ResNameReservedInstance, d.Id(), err) } - return resourceReservedInstanceRead(ctx, d, meta) + return append(diags, resourceReservedInstanceRead(ctx, d, meta)...) } func resourceReservedInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) reservation, err := FindReservedDBInstanceByID(ctx, conn, d.Id()) @@ -170,11 +172,11 @@ func resourceReservedInstanceRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { create.LogNotFoundRemoveState(names.RDS, create.ErrActionReading, ResNameReservedInstance, d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.RDS, create.ErrActionReading, ResNameReservedInstance, d.Id(), err) + return create.AppendDiagError(diags, names.RDS, create.ErrActionReading, ResNameReservedInstance, d.Id(), err) } d.Set(names.AttrARN, reservation.ReservedDBInstanceArn) @@ -194,7 +196,7 @@ func resourceReservedInstanceRead(ctx context.Context, d *schema.ResourceData, m d.Set(names.AttrState, reservation.State) d.Set("usage_price", reservation.UsagePrice) - return nil + return diags } func resourceReservedInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/internal/service/rds/reserved_instance_offering_data_source.go b/internal/service/rds/reserved_instance_offering_data_source.go index d002939c321..b7eafc625d6 100644 --- a/internal/service/rds/reserved_instance_offering_data_source.go +++ b/internal/service/rds/reserved_instance_offering_data_source.go @@ -14,6 +14,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -68,6 +69,7 @@ func DataSourceReservedOffering() *schema.Resource { } func dataSourceReservedOfferingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) input := &rds.DescribeReservedDBInstancesOfferingsInput{ @@ -80,15 +82,15 @@ func dataSourceReservedOfferingRead(ctx context.Context, d *schema.ResourceData, resp, err := conn.DescribeReservedDBInstancesOfferingsWithContext(ctx, input) if err != nil { - return create.DiagError(names.RDS, create.ErrActionReading, ResNameReservedInstanceOffering, "unknown", err) + return create.AppendDiagError(diags, names.RDS, create.ErrActionReading, ResNameReservedInstanceOffering, "unknown", err) } if len(resp.ReservedDBInstancesOfferings) == 0 { - return diag.Errorf("no %s %s found matching criteria; try different search", names.RDS, ResNameReservedInstanceOffering) + return sdkdiag.AppendErrorf(diags, "no %s %s found matching criteria; try different search", names.RDS, ResNameReservedInstanceOffering) } if len(resp.ReservedDBInstancesOfferings) > 1 { - return diag.Errorf("More than one %s %s found matching criteria; try different search", names.RDS, ResNameReservedInstanceOffering) + return sdkdiag.AppendErrorf(diags, "More than one %s %s found matching criteria; try different search", names.RDS, ResNameReservedInstanceOffering) } offering := resp.ReservedDBInstancesOfferings[0] @@ -103,5 +105,5 @@ func dataSourceReservedOfferingRead(ctx context.Context, d *schema.ResourceData, d.Set("product_description", offering.ProductDescription) d.Set("offering_id", offering.ReservedDBInstancesOfferingId) - return nil + return diags } diff --git a/internal/service/rds/snapshot_copy.go b/internal/service/rds/snapshot_copy.go index cd18321b145..e3180529a51 100644 --- a/internal/service/rds/snapshot_copy.go +++ b/internal/service/rds/snapshot_copy.go @@ -201,7 +201,7 @@ func resourceSnapshotCopyRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RDS DB Snapshot (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/resourcegroups/group.go b/internal/service/resourcegroups/group.go index 44ec3624798..32d5c037d35 100644 --- a/internal/service/resourcegroups/group.go +++ b/internal/service/resourcegroups/group.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -117,6 +118,7 @@ func resourceGroup() *schema.Resource { } func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) name := d.Get(names.AttrName).(string) @@ -141,21 +143,22 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta inter output, err := conn.CreateGroup(ctx, input) if err != nil { - return diag.Errorf("creating Resource Groups Group (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Resource Groups Group (%s): %s", name, err) } d.SetId(aws.ToString(output.Group.Name)) if waitForConfigurationAttached { if _, err := waitGroupConfigurationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for Resource Groups Group (%s) configuration update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Resource Groups Group (%s) configuration update: %s", d.Id(), err) } } - return resourceGroupRead(ctx, d, meta) + return append(diags, resourceGroupRead(ctx, d, meta)...) } func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) group, err := findGroupByName(ctx, conn, d.Id()) @@ -163,11 +166,11 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Resource Groups Group %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Resource Groups Group (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Resource Groups Group (%s): %s", d.Id(), err) } arn := aws.ToString(group.GroupArn) @@ -185,7 +188,7 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa // Attempting to get the query on a configuration group returns BadRequestException. hasQuery = false } else { - return diag.Errorf("reading Resource Groups Group (%s) resource query: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Resource Groups Group (%s) resource query: %s", d.Id(), err) } } @@ -197,7 +200,7 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa // Attempting to get configuration on a query group returns BadRequestException. hasConfiguration = false } else { - return diag.Errorf("reading Resource Groups Group (%s) configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Resource Groups Group (%s) configuration: %s", d.Id(), err) } } @@ -206,24 +209,25 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa resultQuery["query"] = aws.ToString(q.GroupQuery.ResourceQuery.Query) resultQuery[names.AttrType] = q.GroupQuery.ResourceQuery.Type if err := d.Set("resource_query", []map[string]interface{}{resultQuery}); err != nil { - return diag.Errorf("setting resource_query: %s", err) + return sdkdiag.AppendErrorf(diags, "setting resource_query: %s", err) } } if hasConfiguration { if err := d.Set(names.AttrConfiguration, flattenGroupConfigurationItems(groupCfg.Configuration)); err != nil { - return diag.Errorf("setting configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) } } - return nil + return diags } func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) // Conversion between a resource-query and configuration group is not possible and vice-versa if d.HasChange(names.AttrConfiguration) && d.HasChange("resource_query") { - return diag.Errorf("conversion between resource-query and configuration group types is not possible") + return sdkdiag.AppendErrorf(diags, "conversion between resource-query and configuration group types is not possible") } if d.HasChange(names.AttrDescription) { @@ -235,7 +239,7 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter _, err := conn.UpdateGroup(ctx, input) if err != nil { - return diag.Errorf("updating Resource Groups Group (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Resource Groups Group (%s): %s", d.Id(), err) } } @@ -248,7 +252,7 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter _, err := conn.UpdateGroupQuery(ctx, input) if err != nil { - return diag.Errorf("updating Resource Groups Group (%s) resource query: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Resource Groups Group (%s) resource query: %s", d.Id(), err) } } @@ -261,18 +265,19 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter _, err := conn.PutGroupConfiguration(ctx, input) if err != nil { - return diag.Errorf("updating Resource Groups Group (%s) configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Resource Groups Group (%s) configuration: %s", d.Id(), err) } if _, err := waitGroupConfigurationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for Resource Groups Group (%s) configuration update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Resource Groups Group (%s) configuration update: %s", d.Id(), err) } } - return resourceGroupRead(ctx, d, meta) + return append(diags, resourceGroupRead(ctx, d, meta)...) } func resourceGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) log.Printf("[DEBUG] Deleting Resource Groups Group: %s", d.Id()) @@ -281,14 +286,14 @@ func resourceGroupDelete(ctx context.Context, d *schema.ResourceData, meta inter }) if errs.IsA[*types.NotFoundException](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Resource Groups Group (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Resource Groups Group (%s): %s", d.Id(), err) } - return nil + return diags } func findGroupByName(ctx context.Context, conn *resourcegroups.Client, name string) (*types.Group, error) { diff --git a/internal/service/resourcegroups/resource.go b/internal/service/resourcegroups/resource.go index 0a5ffec26fd..da00cc57b2e 100644 --- a/internal/service/resourcegroups/resource.go +++ b/internal/service/resourcegroups/resource.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -57,6 +58,7 @@ func resourceResource() *schema.Resource { } func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) groupARN := d.Get("group_arn").(string) @@ -74,19 +76,20 @@ func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta in } if err != nil { - return diag.Errorf("creating Resource Groups Resource (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating Resource Groups Resource (%s): %s", id, err) } d.SetId(id) if _, err := waitResourceCreated(ctx, conn, groupARN, resourceARN, d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Resource Groups Resource (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Resource Groups Resource (%s) create: %s", d.Id(), err) } - return resourceResourceRead(ctx, d, meta) + return append(diags, resourceResourceRead(ctx, d, meta)...) } func resourceResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) output, err := findResourceByTwoPartKey(ctx, conn, d.Get("group_arn").(string), d.Get(names.AttrResourceARN).(string)) @@ -94,20 +97,21 @@ func resourceResourceRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ResourceGroups Resource (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Resource Groups Resource (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Resource Groups Resource (%s): %s", d.Id(), err) } d.Set(names.AttrResourceARN, output.Identifier.ResourceArn) d.Set(names.AttrResourceType, output.Identifier.ResourceType) - return nil + return diags } func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ResourceGroupsClient(ctx) groupARN := d.Get("group_arn").(string) @@ -124,14 +128,14 @@ func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta in } if err != nil { - return diag.Errorf("deleting Resource Groups Resource (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Resource Groups Resource (%s): %s", d.Id(), err) } if _, err := waitResourceDeleted(ctx, conn, groupARN, resourceARN, d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Resource Groups Resource (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Resource Groups Resource (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findResourceByTwoPartKey(ctx context.Context, conn *resourcegroups.Client, groupARN, resourceARN string) (*types.ListGroupResourcesItem, error) { diff --git a/internal/service/rolesanywhere/profile.go b/internal/service/rolesanywhere/profile.go index 89a5cbe2c22..83390f896bc 100644 --- a/internal/service/rolesanywhere/profile.go +++ b/internal/service/rolesanywhere/profile.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -80,6 +81,7 @@ func ResourceProfile() *schema.Resource { } func resourceProfileCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) name := d.Get(names.AttrName).(string) @@ -113,15 +115,16 @@ func resourceProfileCreate(ctx context.Context, d *schema.ResourceData, meta int output, err := conn.CreateProfile(ctx, input) if err != nil { - return diag.Errorf("creating RolesAnywhere Profile (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating RolesAnywhere Profile (%s): %s", name, err) } d.SetId(aws.StringValue(output.Profile.ProfileId)) - return resourceProfileRead(ctx, d, meta) + return append(diags, resourceProfileRead(ctx, d, meta)...) } func resourceProfileRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) profile, err := FindProfileByID(ctx, conn, d.Id()) @@ -129,11 +132,11 @@ func resourceProfileRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RolesAnywhere Profile (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading RolesAnywhere Profile (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading RolesAnywhere Profile (%s): %s", d.Id(), err) } d.Set(names.AttrARN, profile.ProfileArn) @@ -145,13 +148,14 @@ func resourceProfileRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("role_arns", profile.RoleArns) d.Set("session_policy", profile.SessionPolicy) - return nil + return diags } func resourceProfileUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) - if d.HasChangesExcept(names.AttrEnabled, names.AttrTagsAll) { + if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &rolesanywhere.UpdateProfileInput{ ProfileId: aws.String(d.Id()), } @@ -179,7 +183,7 @@ func resourceProfileUpdate(ctx context.Context, d *schema.ResourceData, meta int log.Printf("[DEBUG] Updating RolesAnywhere Profile (%s): %#v", d.Id(), input) _, err := conn.UpdateProfile(ctx, input) if err != nil { - return diag.Errorf("updating RolesAnywhere Profile (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RolesAnywhere Profile (%s): %s", d.Id(), err) } } @@ -188,20 +192,21 @@ func resourceProfileUpdate(ctx context.Context, d *schema.ResourceData, meta int if n == true { err := enableProfile(ctx, d.Id(), meta) if err != nil { - diag.Errorf("enabling RolesAnywhere Profile (%s): %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Profile (%s): %s", d.Id(), err) } } else { err := disableProfile(ctx, d.Id(), meta) if err != nil { - diag.Errorf("disabling RolesAnywhere Profile (%s): %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Profile (%s): %s", d.Id(), err) } } } - return resourceProfileRead(ctx, d, meta) + return append(diags, resourceProfileRead(ctx, d, meta)...) } func resourceProfileDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) log.Printf("[DEBUG] Deleting RolesAnywhere Profile (%s)", d.Id()) @@ -211,14 +216,14 @@ func resourceProfileDelete(ctx context.Context, d *schema.ResourceData, meta int var resourceNotFoundException *types.ResourceNotFoundException if errors.As(err, &resourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting RolesAnywhere Profile: (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting RolesAnywhere Profile: (%s): %s", d.Id(), err) } - return nil + return diags } func disableProfile(ctx context.Context, profileId string, meta interface{}) error { diff --git a/internal/service/rolesanywhere/trust_anchor.go b/internal/service/rolesanywhere/trust_anchor.go index 4790603691f..7f3a1511a64 100644 --- a/internal/service/rolesanywhere/trust_anchor.go +++ b/internal/service/rolesanywhere/trust_anchor.go @@ -15,6 +15,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -91,6 +92,7 @@ func ResourceTrustAnchor() *schema.Resource { } func resourceTrustAnchorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) name := d.Get(names.AttrName).(string) @@ -105,15 +107,16 @@ func resourceTrustAnchorCreate(ctx context.Context, d *schema.ResourceData, meta output, err := conn.CreateTrustAnchor(ctx, input) if err != nil { - return diag.Errorf("creating RolesAnywhere Trust Anchor (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating RolesAnywhere Trust Anchor (%s): %s", name, err) } d.SetId(aws.StringValue(output.TrustAnchor.TrustAnchorId)) - return resourceTrustAnchorRead(ctx, d, meta) + return append(diags, resourceTrustAnchorRead(ctx, d, meta)...) } func resourceTrustAnchorRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) trustAnchor, err := FindTrustAnchorByID(ctx, conn, d.Id()) @@ -121,11 +124,11 @@ func resourceTrustAnchorRead(ctx context.Context, d *schema.ResourceData, meta i if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] RolesAnywhere Trust Anchor (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) } d.Set(names.AttrARN, trustAnchor.TrustAnchorArn) @@ -133,13 +136,14 @@ func resourceTrustAnchorRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrName, trustAnchor.Name) if err := d.Set(names.AttrSource, flattenSource(trustAnchor.Source)); err != nil { - return diag.Errorf("setting source: %s", err) + return sdkdiag.AppendErrorf(diags, "setting source: %s", err) } - return nil + return diags } func resourceTrustAnchorUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -153,27 +157,28 @@ func resourceTrustAnchorUpdate(ctx context.Context, d *schema.ResourceData, meta _, err := conn.UpdateTrustAnchor(ctx, input) if err != nil { - return diag.Errorf("updating RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) } if d.HasChange(names.AttrEnabled) { _, n := d.GetChange(names.AttrEnabled) if n == true { if err := enableTrustAnchor(ctx, d.Id(), meta); err != nil { - diag.Errorf("enabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "enabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) } } else { if err := disableTrustAnchor(ctx, d.Id(), meta); err != nil { - diag.Errorf("disabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "disabling RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) } } } } - return resourceTrustAnchorRead(ctx, d, meta) + return append(diags, resourceTrustAnchorRead(ctx, d, meta)...) } func resourceTrustAnchorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RolesAnywhereClient(ctx) log.Printf("[DEBUG] Deleting RolesAnywhere Trust Anchor (%s)", d.Id()) @@ -183,14 +188,14 @@ func resourceTrustAnchorDelete(ctx context.Context, d *schema.ResourceData, meta var resourceNotFoundException *types.ResourceNotFoundException if errors.As(err, &resourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting RolesAnywhere Trust Anchor (%s): %s", d.Id(), err) } - return nil + return diags } func flattenSource(apiObject *types.Source) []interface{} { diff --git a/internal/service/route53/query_log.go b/internal/service/route53/query_log.go index f58bfc51576..1d447f84e78 100644 --- a/internal/service/route53/query_log.go +++ b/internal/service/route53/query_log.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -53,6 +54,7 @@ func resourceQueryLog() *schema.Resource { } func resourceQueryLogCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53Client(ctx) input := &route53.CreateQueryLoggingConfigInput{ @@ -63,15 +65,16 @@ func resourceQueryLogCreate(ctx context.Context, d *schema.ResourceData, meta in output, err := conn.CreateQueryLoggingConfig(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Query Logging Config: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Query Logging Config: %s", err) } d.SetId(aws.ToString(output.QueryLoggingConfig.Id)) - return resourceQueryLogRead(ctx, d, meta) + return append(diags, resourceQueryLogRead(ctx, d, meta)...) } func resourceQueryLogRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53Client(ctx) output, err := findQueryLoggingConfigByID(ctx, conn, d.Id()) @@ -79,11 +82,11 @@ func resourceQueryLogRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Query Logging Config %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Query Logging Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Query Logging Config (%s): %s", d.Id(), err) } arn := arn.ARN{ @@ -95,10 +98,11 @@ func resourceQueryLogRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set(names.AttrCloudWatchLogGroupARN, output.CloudWatchLogsLogGroupArn) d.Set("zone_id", output.HostedZoneId) - return nil + return diags } func resourceQueryLogDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53Client(ctx) log.Printf("[DEBUG] Deleting Route53 Query Logging Config: %s", d.Id()) @@ -107,14 +111,14 @@ func resourceQueryLogDelete(ctx context.Context, d *schema.ResourceData, meta in }) if errs.IsA[*awstypes.NoSuchQueryLoggingConfig](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Query Logging Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Query Logging Config (%s): %s", d.Id(), err) } - return nil + return diags } func findQueryLoggingConfigByID(ctx context.Context, conn *route53.Client, id string) (*awstypes.QueryLoggingConfig, error) { diff --git a/internal/service/route53/traffic_policy_document_data_source.go b/internal/service/route53/traffic_policy_document_data_source.go index 34c721c07cd..76adc515602 100644 --- a/internal/service/route53/traffic_policy_document_data_source.go +++ b/internal/service/route53/traffic_policy_document_data_source.go @@ -13,6 +13,7 @@ import ( "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/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -266,6 +267,7 @@ func dataSourceTrafficPolicyDocument() *schema.Resource { } func dataSourceTrafficPolicyDocumentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics trafficDoc := &route53TrafficPolicyDoc{} if v, ok := d.GetOk(names.AttrEndpoint); ok { @@ -289,7 +291,7 @@ func dataSourceTrafficPolicyDocumentRead(ctx context.Context, d *schema.Resource jsonDoc, err := json.Marshal(trafficDoc) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } jsonString := string(jsonDoc) @@ -297,7 +299,7 @@ func dataSourceTrafficPolicyDocumentRead(ctx context.Context, d *schema.Resource d.SetId(strconv.Itoa(schema.HashString(jsonString))) - return nil + return diags } func expandDataTrafficPolicyEndpointDoc(tfMap map[string]interface{}) *trafficPolicyEndpoint { diff --git a/internal/service/route53domains/registered_domain.go b/internal/service/route53domains/registered_domain.go index af9d64f2335..8c83bc178f1 100644 --- a/internal/service/route53domains/registered_domain.go +++ b/internal/service/route53domains/registered_domain.go @@ -361,7 +361,7 @@ func resourceRegisteredDomainRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route 53 Domains Domain %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/route53resolver/config.go b/internal/service/route53resolver/config.go index 1442c7f12d8..f5289628d14 100644 --- a/internal/service/route53resolver/config.go +++ b/internal/service/route53resolver/config.go @@ -15,6 +15,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -51,6 +52,7 @@ func ResourceConfig() *schema.Resource { } func resourceConfigCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) autodefinedReverseFlag := d.Get("autodefined_reverse_flag").(string) @@ -62,19 +64,20 @@ func resourceConfigCreate(ctx context.Context, d *schema.ResourceData, meta inte output, err := conn.UpdateResolverConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Config: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Config: %s", err) } d.SetId(aws.StringValue(output.ResolverConfig.Id)) if _, err = waitAutodefinedReverseUpdated(ctx, conn, d.Id(), autodefinedReverseFlag); err != nil { - return diag.Errorf("waiting for Route53 Resolver Config (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Config (%s) create: %s", d.Id(), err) } - return resourceConfigRead(ctx, d, meta) + return append(diags, resourceConfigRead(ctx, d, meta)...) } func resourceConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) resolverConfig, err := FindResolverConfigByID(ctx, conn, d.Id()) @@ -82,11 +85,11 @@ func resourceConfigRead(ctx context.Context, d *schema.ResourceData, meta interf if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Config (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Config (%s): %s", d.Id(), err) } var autodefinedReverseFlag string @@ -99,10 +102,11 @@ func resourceConfigRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set(names.AttrOwnerID, resolverConfig.OwnerId) d.Set(names.AttrResourceID, resolverConfig.ResourceId) - return nil + return diags } func resourceConfigUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) autodefinedReverseFlag := d.Get("autodefined_reverse_flag").(string) @@ -114,14 +118,14 @@ func resourceConfigUpdate(ctx context.Context, d *schema.ResourceData, meta inte _, err := conn.UpdateResolverConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Config: %s", err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Config: %s", err) } if _, err = waitAutodefinedReverseUpdated(ctx, conn, d.Id(), autodefinedReverseFlag); err != nil { - return diag.Errorf("waiting for Route53 Resolver Config (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Config (%s) update: %s", d.Id(), err) } - return resourceConfigRead(ctx, d, meta) + return append(diags, resourceConfigRead(ctx, d, meta)...) } func FindResolverConfigByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverConfig, error) { diff --git a/internal/service/route53resolver/dnssec_config.go b/internal/service/route53resolver/dnssec_config.go index a759b9cf012..66ab196b49e 100644 --- a/internal/service/route53resolver/dnssec_config.go +++ b/internal/service/route53resolver/dnssec_config.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -55,6 +56,7 @@ func ResourceDNSSECConfig() *schema.Resource { } func resourceDNSSECConfigCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.UpdateResolverDnssecConfigInput{ @@ -65,19 +67,20 @@ func resourceDNSSECConfigCreate(ctx context.Context, d *schema.ResourceData, met output, err := conn.UpdateResolverDnssecConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver DNSSEC Config: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver DNSSEC Config: %s", err) } d.SetId(aws.StringValue(output.ResolverDNSSECConfig.Id)) if _, err := waitDNSSECConfigCreated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver DNSSEC Config (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver DNSSEC Config (%s) create: %s", d.Id(), err) } - return resourceDNSSECConfigRead(ctx, d, meta) + return append(diags, resourceDNSSECConfigRead(ctx, d, meta)...) } func resourceDNSSECConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) dnssecConfig, err := FindResolverDNSSECConfigByID(ctx, conn, d.Id()) @@ -85,11 +88,11 @@ func resourceDNSSECConfigRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver DNSSEC Config (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver DNSSEC Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver DNSSEC Config (%s): %s", d.Id(), err) } ownerID := aws.StringValue(dnssecConfig.OwnerId) @@ -106,10 +109,11 @@ func resourceDNSSECConfigRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrResourceID, resourceID) d.Set("validation_status", dnssecConfig.ValidationStatus) - return nil + return diags } func resourceDNSSECConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver DNSSEC Config: %s", d.Id()) @@ -120,18 +124,18 @@ func resourceDNSSECConfigDelete(ctx context.Context, d *schema.ResourceData, met if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeAccessDeniedException) { // VPC doesn't exist. - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver DNSSEC Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver DNSSEC Config (%s): %s", d.Id(), err) } if _, err = waitDNSSECConfigDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver DNSSEC Config (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver DNSSEC Config (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindResolverDNSSECConfigByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverDnssecConfig, error) { diff --git a/internal/service/route53resolver/endpoint.go b/internal/service/route53resolver/endpoint.go index 2531180774d..36d7a6477b5 100644 --- a/internal/service/route53resolver/endpoint.go +++ b/internal/service/route53resolver/endpoint.go @@ -21,6 +21,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -126,6 +127,7 @@ func ResourceEndpoint() *schema.Resource { } func resourceEndpointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.CreateResolverEndpointInput{ @@ -151,19 +153,20 @@ func resourceEndpointCreate(ctx context.Context, d *schema.ResourceData, meta in output, err := conn.CreateResolverEndpointWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Endpoint: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Endpoint: %s", err) } d.SetId(aws.StringValue(output.ResolverEndpoint.Id)) if _, err := waitEndpointCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Endpoint (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Endpoint (%s) create: %s", d.Id(), err) } - return resourceEndpointRead(ctx, d, meta) + return append(diags, resourceEndpointRead(ctx, d, meta)...) } func resourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) ep, err := FindResolverEndpointByID(ctx, conn, d.Id()) @@ -171,11 +174,11 @@ func resourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Endpoint (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Endpoint (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Endpoint (%s): %s", d.Id(), err) } arn := aws.StringValue(ep.Arn) @@ -190,17 +193,18 @@ func resourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta inte ipAddresses, err := findResolverEndpointIPAddressesByID(ctx, conn, d.Id()) if err != nil { - return diag.Errorf("listing Route53 Resolver Endpoint (%s) IP addresses: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Endpoint (%s) IP addresses: %s", d.Id(), err) } if err := d.Set(names.AttrIPAddress, schema.NewSet(endpointHashIPAddress, flattenEndpointIPAddresses(ipAddresses))); err != nil { - return diag.Errorf("setting ip_address: %s", err) + return sdkdiag.AppendErrorf(diags, "setting ip_address: %s", err) } - return nil + return diags } func resourceEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) if d.HasChanges(names.AttrName, "protocols", "resolver_endpoint_type") { @@ -223,11 +227,11 @@ func resourceEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.UpdateResolverEndpointWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Endpoint (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Endpoint (%s): %s", d.Id(), err) } if _, err := waitEndpointUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) } } @@ -248,11 +252,11 @@ func resourceEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.AssociateResolverEndpointIpAddressWithContext(ctx, input) if err != nil { - return diag.Errorf("associating Route53 Resolver Endpoint (%s) IP address: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "associating Route53 Resolver Endpoint (%s) IP address: %s", d.Id(), err) } if _, err := waitEndpointUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) } } @@ -265,19 +269,20 @@ func resourceEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta in _, err := conn.DisassociateResolverEndpointIpAddressWithContext(ctx, input) if err != nil { - return diag.Errorf("disassociating Route53 Resolver Endpoint (%s) IP address: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "disassociating Route53 Resolver Endpoint (%s) IP address: %s", d.Id(), err) } if _, err := waitEndpointUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Endpoint (%s) update: %s", d.Id(), err) } } } - return resourceEndpointRead(ctx, d, meta) + return append(diags, resourceEndpointRead(ctx, d, meta)...) } func resourceEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Endpoint: %s", d.Id()) @@ -286,18 +291,18 @@ func resourceEndpointDelete(ctx context.Context, d *schema.ResourceData, meta in }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Endpoint (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Endpoint (%s): %s", d.Id(), err) } if _, err := waitEndpointDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Endpoint (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Endpoint (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindResolverEndpointByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverEndpoint, error) { diff --git a/internal/service/route53resolver/endpoint_data_source.go b/internal/service/route53resolver/endpoint_data_source.go index 7ca75b0454b..1467e03fe54 100644 --- a/internal/service/route53resolver/endpoint_data_source.go +++ b/internal/service/route53resolver/endpoint_data_source.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -81,6 +82,7 @@ func DataSourceEndpoint() *schema.Resource { } func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) endpointID := d.Get("resolver_endpoint_id").(string) @@ -111,13 +113,13 @@ func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return diag.Errorf("listing Route53 Resolver Endpoints: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Endpoints: %s", err) } if n := len(endpoints); n == 0 { - return diag.Errorf("no Route53 Resolver Endpoint matched") + return sdkdiag.AppendErrorf(diags, "no Route53 Resolver Endpoint matched") } else if n > 1 { - return diag.Errorf("%d Route53 Resolver Endpoints matched; use additional constraints to reduce matches to a single Endpoint", n) + return sdkdiag.AppendErrorf(diags, "%d Route53 Resolver Endpoints matched; use additional constraints to reduce matches to a single Endpoint", n) } ep := endpoints[0] @@ -134,7 +136,7 @@ func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta in ipAddresses, err := findResolverEndpointIPAddressesByID(ctx, conn, d.Id()) if err != nil { - return diag.Errorf("listing Route53 Resolver Endpoint (%s) IP addresses: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Endpoint (%s) IP addresses: %s", d.Id(), err) } var ips []*string @@ -145,7 +147,7 @@ func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta in d.Set(names.AttrIPAddresses, aws.StringValueSlice(ips)) - return nil + return diags } func buildR53ResolverTagFilters(set *schema.Set) []*route53resolver.Filter { diff --git a/internal/service/route53resolver/firewall_config.go b/internal/service/route53resolver/firewall_config.go index 1f628967fa1..b7964b6e490 100644 --- a/internal/service/route53resolver/firewall_config.go +++ b/internal/service/route53resolver/firewall_config.go @@ -14,6 +14,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -51,6 +52,7 @@ func ResourceFirewallConfig() *schema.Resource { } func resourceFirewallConfigCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.UpdateFirewallConfigInput{ @@ -64,15 +66,16 @@ func resourceFirewallConfigCreate(ctx context.Context, d *schema.ResourceData, m output, err := conn.UpdateFirewallConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Firewall Config: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Firewall Config: %s", err) } d.SetId(aws.StringValue(output.FirewallConfig.Id)) - return resourceFirewallConfigRead(ctx, d, meta) + return append(diags, resourceFirewallConfigRead(ctx, d, meta)...) } func resourceFirewallConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallConfig, err := FindFirewallConfigByID(ctx, conn, d.Id()) @@ -80,21 +83,22 @@ func resourceFirewallConfigRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Firewall Config (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Config (%s): %s", d.Id(), err) } d.Set("firewall_fail_open", firewallConfig.FirewallFailOpen) d.Set(names.AttrOwnerID, firewallConfig.OwnerId) d.Set(names.AttrResourceID, firewallConfig.ResourceId) - return nil + return diags } func resourceFirewallConfigUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.UpdateFirewallConfigInput{ @@ -108,13 +112,14 @@ func resourceFirewallConfigUpdate(ctx context.Context, d *schema.ResourceData, m _, err := conn.UpdateFirewallConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Firewall Config: %s", err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Firewall Config: %s", err) } - return resourceFirewallConfigRead(ctx, d, meta) + return append(diags, resourceFirewallConfigRead(ctx, d, meta)...) } func resourceFirewallConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Firewall Config: %s", d.Id()) @@ -124,10 +129,10 @@ func resourceFirewallConfigDelete(ctx context.Context, d *schema.ResourceData, m }) if err != nil { - return diag.Errorf("deleting Route53 Resolver Firewall Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Firewall Config (%s): %s", d.Id(), err) } - return nil + return diags } func FindFirewallConfigByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.FirewallConfig, error) { diff --git a/internal/service/route53resolver/firewall_config_data_source.go b/internal/service/route53resolver/firewall_config_data_source.go index 2ae511175ef..254049665fb 100644 --- a/internal/service/route53resolver/firewall_config_data_source.go +++ b/internal/service/route53resolver/firewall_config_data_source.go @@ -13,6 +13,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -40,13 +41,14 @@ func DataSourceFirewallConfig() *schema.Resource { } func dataSourceFirewallConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) id := d.Get(names.AttrResourceID).(string) firewallConfig, err := findFirewallConfigByResourceID(ctx, conn, id) if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Config (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Config (%s): %s", id, err) } d.SetId(aws.StringValue(firewallConfig.Id)) @@ -54,7 +56,7 @@ func dataSourceFirewallConfigRead(ctx context.Context, d *schema.ResourceData, m d.Set(names.AttrOwnerID, firewallConfig.OwnerId) d.Set(names.AttrResourceID, firewallConfig.ResourceId) - return nil + return diags } func findFirewallConfigByResourceID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.FirewallConfig, error) { diff --git a/internal/service/route53resolver/firewall_domain_list.go b/internal/service/route53resolver/firewall_domain_list.go index fd1d05a903b..3915e5d3105 100644 --- a/internal/service/route53resolver/firewall_domain_list.go +++ b/internal/service/route53resolver/firewall_domain_list.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -62,6 +63,7 @@ func ResourceFirewallDomainList() *schema.Resource { } func resourceFirewallDomainListCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) name := d.Get(names.AttrName).(string) @@ -74,7 +76,7 @@ func resourceFirewallDomainListCreate(ctx context.Context, d *schema.ResourceDat output, err := conn.CreateFirewallDomainListWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Firewall Domain List (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Firewall Domain List (%s): %s", name, err) } d.SetId(aws.StringValue(output.FirewallDomainList.Id)) @@ -87,18 +89,19 @@ func resourceFirewallDomainListCreate(ctx context.Context, d *schema.ResourceDat }) if err != nil { - return diag.Errorf("updating Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) } if _, err = waitFirewallDomainListUpdated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Domain List (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Domain List (%s) update: %s", d.Id(), err) } } - return resourceFirewallDomainListRead(ctx, d, meta) + return append(diags, resourceFirewallDomainListRead(ctx, d, meta)...) } func resourceFirewallDomainListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallDomainList, err := FindFirewallDomainListByID(ctx, conn, d.Id()) @@ -106,11 +109,11 @@ func resourceFirewallDomainListRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Firewall Domain List (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Domain List (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Domain List (%s): %s", d.Id(), err) } arn := aws.StringValue(firewallDomainList.Arn) @@ -133,15 +136,16 @@ func resourceFirewallDomainListRead(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("listing Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) } d.Set("domains", aws.StringValueSlice(output)) - return nil + return diags } func resourceFirewallDomainListUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) if d.HasChange("domains") { @@ -170,18 +174,19 @@ func resourceFirewallDomainListUpdate(ctx context.Context, d *schema.ResourceDat }) if err != nil { - return diag.Errorf("updating Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Firewall Domain List (%s) domains: %s", d.Id(), err) } if _, err = waitFirewallDomainListUpdated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Domain List (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Domain List (%s) update: %s", d.Id(), err) } } - return resourceFirewallDomainListRead(ctx, d, meta) + return append(diags, resourceFirewallDomainListRead(ctx, d, meta)...) } func resourceFirewallDomainListDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Firewall Domain List: %s", d.Id()) @@ -190,18 +195,18 @@ func resourceFirewallDomainListDelete(ctx context.Context, d *schema.ResourceDat }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Firewall Domain List (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Firewall Domain List (%s): %s", d.Id(), err) } if _, err = waitFirewallDomainListDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Domain List (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Domain List (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindFirewallDomainListByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.FirewallDomainList, error) { diff --git a/internal/service/route53resolver/firewall_domain_list_data_source.go b/internal/service/route53resolver/firewall_domain_list_data_source.go index d96b1f912ac..915d4caee5e 100644 --- a/internal/service/route53resolver/firewall_domain_list_data_source.go +++ b/internal/service/route53resolver/firewall_domain_list_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -64,13 +65,14 @@ func DataSourceFirewallDomainList() *schema.Resource { } func dataSourceFirewallDomainListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) id := d.Get("firewall_domain_list_id").(string) firewallDomainList, err := FindFirewallDomainListByID(ctx, conn, id) if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Domain List (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Domain List (%s): %s", id, err) } d.SetId(aws.StringValue(firewallDomainList.Id)) @@ -85,5 +87,5 @@ func dataSourceFirewallDomainListRead(ctx context.Context, d *schema.ResourceDat d.Set(names.AttrStatus, firewallDomainList.Status) d.Set(names.AttrStatusMessage, firewallDomainList.StatusMessage) - return nil + return diags } diff --git a/internal/service/route53resolver/firewall_rule.go b/internal/service/route53resolver/firewall_rule.go index 9b5eecdc534..f7dd14bd412 100644 --- a/internal/service/route53resolver/firewall_rule.go +++ b/internal/service/route53resolver/firewall_rule.go @@ -18,6 +18,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -86,6 +87,7 @@ func ResourceFirewallRule() *schema.Resource { } func resourceFirewallRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallDomainListID := d.Get("firewall_domain_list_id").(string) @@ -120,21 +122,22 @@ func resourceFirewallRuleCreate(ctx context.Context, d *schema.ResourceData, met _, err := conn.CreateFirewallRuleWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Firewall Rule (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Firewall Rule (%s): %s", name, err) } d.SetId(ruleID) - return resourceFirewallRuleRead(ctx, d, meta) + return append(diags, resourceFirewallRuleRead(ctx, d, meta)...) } func resourceFirewallRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallRuleGroupID, firewallDomainListID, err := FirewallRuleParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } firewallRule, err := FindFirewallRuleByTwoPartKey(ctx, conn, firewallRuleGroupID, firewallDomainListID) @@ -142,11 +145,11 @@ func resourceFirewallRuleRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Firewall Rule (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) } d.Set(names.AttrAction, firewallRule.Action) @@ -159,16 +162,17 @@ func resourceFirewallRuleRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrName, firewallRule.Name) d.Set(names.AttrPriority, firewallRule.Priority) - return nil + return diags } func resourceFirewallRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallRuleGroupID, firewallDomainListID, err := FirewallRuleParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &route53resolver.UpdateFirewallRuleInput{ @@ -198,19 +202,20 @@ func resourceFirewallRuleUpdate(ctx context.Context, d *schema.ResourceData, met _, err = conn.UpdateFirewallRuleWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) } - return resourceFirewallRuleRead(ctx, d, meta) + return append(diags, resourceFirewallRuleRead(ctx, d, meta)...) } func resourceFirewallRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallRuleGroupID, firewallDomainListID, err := FirewallRuleParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting Route53 Resolver Firewall Rule: %s", d.Id()) @@ -220,14 +225,14 @@ func resourceFirewallRuleDelete(ctx context.Context, d *schema.ResourceData, met }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Firewall Rule (%s): %s", d.Id(), err) } - return nil + return diags } const firewallRuleIDSeparator = ":" diff --git a/internal/service/route53resolver/firewall_rule_group.go b/internal/service/route53resolver/firewall_rule_group.go index 1a04cfb9c4e..e87dea418d0 100644 --- a/internal/service/route53resolver/firewall_rule_group.go +++ b/internal/service/route53resolver/firewall_rule_group.go @@ -15,6 +15,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -62,6 +63,7 @@ func ResourceFirewallRuleGroup() *schema.Resource { } func resourceFirewallRuleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) name := d.Get(names.AttrName).(string) @@ -74,15 +76,16 @@ func resourceFirewallRuleGroupCreate(ctx context.Context, d *schema.ResourceData output, err := conn.CreateFirewallRuleGroupWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Firewall Rule Group (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Firewall Rule Group (%s): %s", name, err) } d.SetId(aws.StringValue(output.FirewallRuleGroup.Id)) - return resourceFirewallRuleGroupRead(ctx, d, meta) + return append(diags, resourceFirewallRuleGroupRead(ctx, d, meta)...) } func resourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) ruleGroup, err := FindFirewallRuleGroupByID(ctx, conn, d.Id()) @@ -90,11 +93,11 @@ func resourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Firewall Rule Group (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rule Group (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rule Group (%s): %s", d.Id(), err) } arn := aws.StringValue(ruleGroup.Arn) @@ -103,7 +106,7 @@ func resourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrOwnerID, ruleGroup.OwnerId) d.Set("share_status", ruleGroup.ShareStatus) - return nil + return diags } func resourceFirewallRuleGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -112,6 +115,7 @@ func resourceFirewallRuleGroupUpdate(ctx context.Context, d *schema.ResourceData } func resourceFirewallRuleGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Firewall Rule Group: %s", d.Id()) @@ -120,14 +124,14 @@ func resourceFirewallRuleGroupDelete(ctx context.Context, d *schema.ResourceData }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Firewall Rule Group (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Firewall Rule Group (%s): %s", d.Id(), err) } - return nil + return diags } func FindFirewallRuleGroupByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.FirewallRuleGroup, error) { diff --git a/internal/service/route53resolver/firewall_rule_group_association.go b/internal/service/route53resolver/firewall_rule_group_association.go index 68504d9540c..959fa337c40 100644 --- a/internal/service/route53resolver/firewall_rule_group_association.go +++ b/internal/service/route53resolver/firewall_rule_group_association.go @@ -18,6 +18,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -76,6 +77,7 @@ func ResourceFirewallRuleGroupAssociation() *schema.Resource { } func resourceFirewallRuleGroupAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) name := d.Get(names.AttrName).(string) @@ -95,19 +97,20 @@ func resourceFirewallRuleGroupAssociationCreate(ctx context.Context, d *schema.R output, err := conn.AssociateFirewallRuleGroupWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Firewall Rule Group Association (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Firewall Rule Group Association (%s): %s", name, err) } d.SetId(aws.StringValue(output.FirewallRuleGroupAssociation.Id)) if _, err := waitFirewallRuleGroupAssociationCreated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Rule Group Association (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Rule Group Association (%s) create: %s", d.Id(), err) } - return resourceFirewallRuleGroupAssociationRead(ctx, d, meta) + return append(diags, resourceFirewallRuleGroupAssociationRead(ctx, d, meta)...) } func resourceFirewallRuleGroupAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) ruleGroupAssociation, err := FindFirewallRuleGroupAssociationByID(ctx, conn, d.Id()) @@ -115,11 +118,11 @@ func resourceFirewallRuleGroupAssociationRead(ctx context.Context, d *schema.Res if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Firewall Rule Group Association (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) } arn := aws.StringValue(ruleGroupAssociation.Arn) @@ -130,10 +133,11 @@ func resourceFirewallRuleGroupAssociationRead(ctx context.Context, d *schema.Res d.Set(names.AttrPriority, ruleGroupAssociation.Priority) d.Set(names.AttrVPCID, ruleGroupAssociation.VpcId) - return nil + return diags } func resourceFirewallRuleGroupAssociationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) if d.HasChanges(names.AttrName, "mutation_protection", names.AttrPriority) { @@ -150,18 +154,19 @@ func resourceFirewallRuleGroupAssociationUpdate(ctx context.Context, d *schema.R _, err := conn.UpdateFirewallRuleGroupAssociationWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) } if _, err := waitFirewallRuleGroupAssociationUpdated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Rule Group Association (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Rule Group Association (%s) update: %s", d.Id(), err) } } - return resourceFirewallRuleGroupAssociationRead(ctx, d, meta) + return append(diags, resourceFirewallRuleGroupAssociationRead(ctx, d, meta)...) } func resourceFirewallRuleGroupAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Firewall Rule Group Association: %s", d.Id()) @@ -170,18 +175,18 @@ func resourceFirewallRuleGroupAssociationDelete(ctx context.Context, d *schema.R }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Firewall Rule Group Association (%s): %s", d.Id(), err) } if _, err := waitFirewallRuleGroupAssociationDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Firewall Rule Group Association (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Firewall Rule Group Association (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindFirewallRuleGroupAssociationByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.FirewallRuleGroupAssociation, error) { diff --git a/internal/service/route53resolver/firewall_rule_group_association_data_source.go b/internal/service/route53resolver/firewall_rule_group_association_data_source.go index 78e8b761541..0da7ec15e36 100644 --- a/internal/service/route53resolver/firewall_rule_group_association_data_source.go +++ b/internal/service/route53resolver/firewall_rule_group_association_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -76,13 +77,14 @@ func DataSourceFirewallRuleGroupAssociation() *schema.Resource { } func dataSourceRuleGroupAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) id := d.Get("firewall_rule_group_association_id").(string) ruleGroupAssociation, err := FindFirewallRuleGroupAssociationByID(ctx, conn, id) if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rule Group Association (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rule Group Association (%s): %s", id, err) } d.SetId(aws.StringValue(ruleGroupAssociation.Id)) @@ -100,5 +102,5 @@ func dataSourceRuleGroupAssociationRead(ctx context.Context, d *schema.ResourceD d.Set(names.AttrStatusMessage, ruleGroupAssociation.StatusMessage) d.Set(names.AttrVPCID, ruleGroupAssociation.VpcId) - return nil + return diags } diff --git a/internal/service/route53resolver/firewall_rule_group_data_source.go b/internal/service/route53resolver/firewall_rule_group_data_source.go index 2f9516f9e83..d5b34a999a0 100644 --- a/internal/service/route53resolver/firewall_rule_group_data_source.go +++ b/internal/service/route53resolver/firewall_rule_group_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -68,13 +69,14 @@ func DataSourceFirewallRuleGroup() *schema.Resource { } func dataSourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) id := d.Get("firewall_rule_group_id").(string) ruleGroup, err := FindFirewallRuleGroupByID(ctx, conn, id) if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rule Group (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rule Group (%s): %s", id, err) } d.SetId(aws.StringValue(ruleGroup.Id)) @@ -90,5 +92,5 @@ func dataSourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData d.Set(names.AttrStatus, ruleGroup.Status) d.Set(names.AttrStatusMessage, ruleGroup.StatusMessage) - return nil + return diags } diff --git a/internal/service/route53resolver/firewall_rules_data_source.go b/internal/service/route53resolver/firewall_rules_data_source.go index 993c8f4836f..5b73e9d7fc9 100644 --- a/internal/service/route53resolver/firewall_rules_data_source.go +++ b/internal/service/route53resolver/firewall_rules_data_source.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -93,6 +94,7 @@ func DataSourceResolverFirewallRules() *schema.Resource { } func dataSourceResolverFirewallFirewallRulesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) firewallRuleGroupID := d.Get("firewall_rule_group_id").(string) @@ -109,22 +111,22 @@ func dataSourceResolverFirewallFirewallRulesRead(ctx context.Context, d *schema. }) if err != nil { - return diag.Errorf("reading Route53 Resolver Firewall Rules (%s): %s", firewallRuleGroupID, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Firewall Rules (%s): %s", firewallRuleGroupID, err) } if n := len(rules); n == 0 { - return diag.Errorf("no Route53 Resolver Firewall Rules matched") + return sdkdiag.AppendErrorf(diags, "no Route53 Resolver Firewall Rules matched") } else if n > 1 { - return diag.Errorf("%d Route53 Resolver Firewall Rules matched; use additional constraints to reduce matches to a single Firewall Rule", n) + return sdkdiag.AppendErrorf(diags, "%d Route53 Resolver Firewall Rules matched; use additional constraints to reduce matches to a single Firewall Rule", n) } if err := d.Set("firewall_rules", flattenFirewallRules(rules)); err != nil { - return diag.Errorf("setting firewall_rules: %s", err) + return sdkdiag.AppendErrorf(diags, "setting firewall_rules: %s", err) } d.SetId(firewallRuleGroupID) - return nil + return diags } func flattenFirewallRules(apiObjects []*route53resolver.FirewallRule) []interface{} { diff --git a/internal/service/route53resolver/query_log_config.go b/internal/service/route53resolver/query_log_config.go index 51502036a21..998fc59927c 100644 --- a/internal/service/route53resolver/query_log_config.go +++ b/internal/service/route53resolver/query_log_config.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -69,6 +70,7 @@ func ResourceQueryLogConfig() *schema.Resource { } func resourceQueryLogConfigCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) name := d.Get(names.AttrName).(string) @@ -82,19 +84,20 @@ func resourceQueryLogConfigCreate(ctx context.Context, d *schema.ResourceData, m output, err := conn.CreateResolverQueryLogConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Query Log Config (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Query Log Config (%s): %s", name, err) } d.SetId(aws.StringValue(output.ResolverQueryLogConfig.Id)) if _, err := waitQueryLogConfigCreated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Query Log Config (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Query Log Config (%s) create: %s", d.Id(), err) } - return resourceQueryLogConfigRead(ctx, d, meta) + return append(diags, resourceQueryLogConfigRead(ctx, d, meta)...) } func resourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) queryLogConfig, err := FindResolverQueryLogConfigByID(ctx, conn, d.Id()) @@ -102,11 +105,11 @@ func resourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Query Log Config (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Query Log Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Query Log Config (%s): %s", d.Id(), err) } arn := aws.StringValue(queryLogConfig.Arn) @@ -116,7 +119,7 @@ func resourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, met d.Set(names.AttrOwnerID, queryLogConfig.OwnerId) d.Set("share_status", queryLogConfig.ShareStatus) - return nil + return diags } func resourceQueryLogConfigUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -125,6 +128,7 @@ func resourceQueryLogConfigUpdate(ctx context.Context, d *schema.ResourceData, m } func resourceQueryLogConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Query Log Config: %s", d.Id()) @@ -133,18 +137,18 @@ func resourceQueryLogConfigDelete(ctx context.Context, d *schema.ResourceData, m }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Query Log Config (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Query Log Config (%s): %s", d.Id(), err) } if _, err := waitQueryLogConfigDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Query Log Config (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Query Log Config (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindResolverQueryLogConfigByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverQueryLogConfig, error) { diff --git a/internal/service/route53resolver/query_log_config_association.go b/internal/service/route53resolver/query_log_config_association.go index 12969aca70e..1f1838074f7 100644 --- a/internal/service/route53resolver/query_log_config_association.go +++ b/internal/service/route53resolver/query_log_config_association.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -47,6 +48,7 @@ func ResourceQueryLogConfigAssociation() *schema.Resource { } func resourceQueryLogConfigAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.AssociateResolverQueryLogConfigInput{ @@ -57,19 +59,20 @@ func resourceQueryLogConfigAssociationCreate(ctx context.Context, d *schema.Reso output, err := conn.AssociateResolverQueryLogConfigWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Query Log Config Association: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Query Log Config Association: %s", err) } d.SetId(aws.StringValue(output.ResolverQueryLogConfigAssociation.Id)) if _, err := waitQueryLogConfigAssociationCreated(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Query Log Config Association (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Query Log Config Association (%s) create: %s", d.Id(), err) } - return resourceQueryLogConfigAssociationRead(ctx, d, meta) + return append(diags, resourceQueryLogConfigAssociationRead(ctx, d, meta)...) } func resourceQueryLogConfigAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) queryLogConfigAssociation, err := FindResolverQueryLogConfigAssociationByID(ctx, conn, d.Id()) @@ -77,20 +80,21 @@ func resourceQueryLogConfigAssociationRead(ctx context.Context, d *schema.Resour if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Query Log Config Association (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Query Log Config Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Query Log Config Association (%s): %s", d.Id(), err) } d.Set("resolver_query_log_config_id", queryLogConfigAssociation.ResolverQueryLogConfigId) d.Set(names.AttrResourceID, queryLogConfigAssociation.ResourceId) - return nil + return diags } func resourceQueryLogConfigAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Query Log Config Association: %s", d.Id()) @@ -100,18 +104,18 @@ func resourceQueryLogConfigAssociationDelete(ctx context.Context, d *schema.Reso }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Query Log Config Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Query Log Config Association (%s): %s", d.Id(), err) } if _, err := waitQueryLogConfigAssociationDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for Route53 Resolver Query Log Config Association (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Query Log Config Association (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindResolverQueryLogConfigAssociationByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverQueryLogConfigAssociation, error) { diff --git a/internal/service/route53resolver/query_log_config_data_source.go b/internal/service/route53resolver/query_log_config_data_source.go index 8b60ed9e396..ac8dbc1eb10 100644 --- a/internal/service/route53resolver/query_log_config_data_source.go +++ b/internal/service/route53resolver/query_log_config_data_source.go @@ -13,6 +13,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" @@ -60,6 +61,7 @@ const ( ) func dataSourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) configID := d.Get("resolver_query_log_config_id").(string) @@ -91,14 +93,14 @@ func dataSourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, m }) if err != nil { - return diag.Errorf("listing Route53 resolver Query Logging Configurations: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Route53 resolver Query Logging Configurations: %s", err) } if n := len(configs); n == 0 { - return create.DiagError(names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned no results, "+ + return create.AppendDiagError(diags, names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned no results, "+ "please change your search criteria and try again")) } else if n > 1 { - return create.DiagError(names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned more than one result, "+ + return create.AppendDiagError(diags, names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned more than one result, "+ "please try more specific search criteria")) } @@ -119,7 +121,7 @@ func dataSourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, m tags, err := listTags(ctx, conn, arn) if err != nil { - return create.DiagError(names.AppConfig, create.ErrActionReading, DSNameQueryLogConfig, configID, err) + return create.AppendDiagError(diags, names.AppConfig, create.ErrActionReading, DSNameQueryLogConfig, configID, err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -127,9 +129,9 @@ func dataSourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, m //lintignore:AWSR002 if err := d.Set(names.AttrTags, tags.Map()); err != nil { - return create.DiagError(names.AppConfig, create.ErrActionSetting, DSNameQueryLogConfig, configID, err) + return create.AppendDiagError(diags, names.AppConfig, create.ErrActionSetting, DSNameQueryLogConfig, configID, err) } } - return nil + return diags } diff --git a/internal/service/route53resolver/rule.go b/internal/service/route53resolver/rule.go index e44df688565..1038e11d05d 100644 --- a/internal/service/route53resolver/rule.go +++ b/internal/service/route53resolver/rule.go @@ -20,6 +20,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -117,6 +118,7 @@ func ResourceRule() *schema.Resource { } func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.CreateResolverRuleInput{ @@ -141,19 +143,20 @@ func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interf output, err := conn.CreateResolverRuleWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Rule: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Rule: %s", err) } d.SetId(aws.StringValue(output.ResolverRule.Id)) if _, err := waitRuleCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Rule (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Rule (%s) create: %s", d.Id(), err) } - return resourceRuleRead(ctx, d, meta) + return append(diags, resourceRuleRead(ctx, d, meta)...) } func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) rule, err := FindResolverRuleByID(ctx, conn, d.Id()) @@ -161,11 +164,11 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Rule (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Rule (%s): %s", d.Id(), err) } arn := aws.StringValue(rule.Arn) @@ -179,13 +182,14 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set("rule_type", rule.RuleType) d.Set("share_status", rule.ShareStatus) if err := d.Set("target_ip", flattenRuleTargetIPs(rule.TargetIps)); err != nil { - return diag.Errorf("setting target_ip: %s", err) + return sdkdiag.AppendErrorf(diags, "setting target_ip: %s", err) } - return nil + return diags } func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) if d.HasChanges(names.AttrName, "resolver_endpoint_id", "target_ip") { @@ -209,18 +213,19 @@ func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interf _, err := conn.UpdateResolverRuleWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Route53 Resolver Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Route53 Resolver Rule (%s): %s", d.Id(), err) } if _, err := waitRuleUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Rule (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Rule (%s) update: %s", d.Id(), err) } } - return resourceRuleRead(ctx, d, meta) + return append(diags, resourceRuleRead(ctx, d, meta)...) } func resourceRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Rule: %s", d.Id()) @@ -229,18 +234,18 @@ func resourceRuleDelete(ctx context.Context, d *schema.ResourceData, meta interf }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Rule (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Rule (%s): %s", d.Id(), err) } if _, err := waitRuleDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Rule (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Rule (%s) delete: %s", d.Id(), err) } - return nil + return diags } func resourceRuleCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { diff --git a/internal/service/route53resolver/rule_association.go b/internal/service/route53resolver/rule_association.go index 077d99f63aa..787c45d58b7 100644 --- a/internal/service/route53resolver/rule_association.go +++ b/internal/service/route53resolver/rule_association.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -61,6 +62,7 @@ func ResourceRuleAssociation() *schema.Resource { } func resourceRuleAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.AssociateResolverRuleInput{ @@ -75,19 +77,20 @@ func resourceRuleAssociationCreate(ctx context.Context, d *schema.ResourceData, output, err := conn.AssociateResolverRuleWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Route53 Resolver Rule Association: %s", err) + return sdkdiag.AppendErrorf(diags, "creating Route53 Resolver Rule Association: %s", err) } d.SetId(aws.StringValue(output.ResolverRuleAssociation.Id)) if _, err := waitRuleAssociationCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Rule Association (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Rule Association (%s) create: %s", d.Id(), err) } - return resourceRuleAssociationRead(ctx, d, meta) + return append(diags, resourceRuleAssociationRead(ctx, d, meta)...) } func resourceRuleAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) ruleAssociation, err := FindResolverRuleAssociationByID(ctx, conn, d.Id()) @@ -95,21 +98,22 @@ func resourceRuleAssociationRead(ctx context.Context, d *schema.ResourceData, me if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route53 Resolver Rule Association (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Route53 Resolver Rule Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Rule Association (%s): %s", d.Id(), err) } d.Set(names.AttrName, ruleAssociation.Name) d.Set("resolver_rule_id", ruleAssociation.ResolverRuleId) d.Set(names.AttrVPCID, ruleAssociation.VPCId) - return nil + return diags } func resourceRuleAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) log.Printf("[DEBUG] Deleting Route53 Resolver Rule Association: %s", d.Id()) @@ -119,18 +123,18 @@ func resourceRuleAssociationDelete(ctx context.Context, d *schema.ResourceData, }) if tfawserr.ErrCodeEquals(err, route53resolver.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Route53 Resolver Rule Association (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Route53 Resolver Rule Association (%s): %s", d.Id(), err) } if _, err := waitRuleAssociationDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Route53 Resolver Rule Association (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Route53 Resolver Rule Association (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindResolverRuleAssociationByID(ctx context.Context, conn *route53resolver.Route53Resolver, id string) (*route53resolver.ResolverRuleAssociation, error) { diff --git a/internal/service/route53resolver/rule_data_source.go b/internal/service/route53resolver/rule_data_source.go index aa7b47de16c..5ea54388eaf 100644 --- a/internal/service/route53resolver/rule_data_source.go +++ b/internal/service/route53resolver/rule_data_source.go @@ -12,6 +12,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -73,6 +74,7 @@ func DataSourceRule() *schema.Resource { } func dataSourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -83,7 +85,7 @@ func dataSourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interf rule, err = FindResolverRuleByID(ctx, conn, id) if err != nil { - return diag.Errorf("reading Route53 Resolver Rule (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "reading Route53 Resolver Rule (%s): %s", id, err) } } else { input := &route53resolver.ListResolverRulesInput{ @@ -102,13 +104,13 @@ func dataSourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interf }) if err != nil { - return diag.Errorf("listing Route53 Resolver Rules: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Rules: %s", err) } if n := len(rules); n == 0 { - return diag.Errorf("no Route53 Resolver Rules matched") + return sdkdiag.AppendErrorf(diags, "no Route53 Resolver Rules matched") } else if n > 1 { - return diag.Errorf("%d Route53 Resolver Rules matched; use additional constraints to reduce matches to a single Rule", n) + return sdkdiag.AppendErrorf(diags, "%d Route53 Resolver Rules matched; use additional constraints to reduce matches to a single Rule", n) } rule = rules[0] @@ -132,15 +134,15 @@ func dataSourceRuleRead(ctx context.Context, d *schema.ResourceData, meta interf tags, err := listTags(ctx, conn, arn) if err != nil { - return diag.Errorf("listing tags for Route53 Resolver Rule (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "listing tags for Route53 Resolver Rule (%s): %s", arn, err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } } - return nil + return diags } func buildAttributeFilterList(attrs map[string]string) []*route53resolver.Filter { diff --git a/internal/service/route53resolver/rules_data_source.go b/internal/service/route53resolver/rules_data_source.go index eeee670fecd..735e9d214dc 100644 --- a/internal/service/route53resolver/rules_data_source.go +++ b/internal/service/route53resolver/rules_data_source.go @@ -13,6 +13,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -61,6 +62,7 @@ func DataSourceRules() *schema.Resource { } func dataSourceRulesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53ResolverConn(ctx) input := &route53resolver.ListResolverRulesInput{} @@ -91,12 +93,12 @@ func dataSourceRulesRead(ctx context.Context, d *schema.ResourceData, meta inter }) if err != nil { - return diag.Errorf("listing Route53 Resolver Rules: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Route53 Resolver Rules: %s", err) } d.SetId(meta.(*conns.AWSClient).Region) d.Set("resolver_rule_ids", aws.StringValueSlice(ruleIDs)) - return nil + return diags } diff --git a/internal/service/rum/app_monitor.go b/internal/service/rum/app_monitor.go index 5face412c10..6e08f781085 100644 --- a/internal/service/rum/app_monitor.go +++ b/internal/service/rum/app_monitor.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -149,6 +150,7 @@ func ResourceAppMonitor() *schema.Resource { } func resourceAppMonitorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) name := d.Get(names.AttrName).(string) @@ -170,15 +172,16 @@ func resourceAppMonitorCreate(ctx context.Context, d *schema.ResourceData, meta _, err := conn.CreateAppMonitorWithContext(ctx, input) if err != nil { - return diag.Errorf("creating CloudWatch RUM App Monitor (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating CloudWatch RUM App Monitor (%s): %s", name, err) } d.SetId(name) - return resourceAppMonitorRead(ctx, d, meta) + return append(diags, resourceAppMonitorRead(ctx, d, meta)...) } func resourceAppMonitorRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) appMon, err := FindAppMonitorByName(ctx, conn, d.Id()) @@ -186,19 +189,19 @@ func resourceAppMonitorRead(ctx context.Context, d *schema.ResourceData, meta in if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] CloudWatch RUM App Monitor %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading CloudWatch RUM App Monitor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading CloudWatch RUM App Monitor (%s): %s", d.Id(), err) } if err := d.Set("app_monitor_configuration", []interface{}{flattenAppMonitorConfiguration(appMon.AppMonitorConfiguration)}); err != nil { - return diag.Errorf("setting app_monitor_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting app_monitor_configuration: %s", err) } if err := d.Set("custom_events", []interface{}{flattenCustomEvents(appMon.CustomEvents)}); err != nil { - return diag.Errorf("setting custom_events: %s", err) + return sdkdiag.AppendErrorf(diags, "setting custom_events: %s", err) } d.Set("app_monitor_id", appMon.Id) @@ -217,10 +220,11 @@ func resourceAppMonitorRead(ctx context.Context, d *schema.ResourceData, meta in setTagsOut(ctx, appMon.Tags) - return nil + return diags } func resourceAppMonitorUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -247,14 +251,15 @@ func resourceAppMonitorUpdate(ctx context.Context, d *schema.ResourceData, meta _, err := conn.UpdateAppMonitorWithContext(ctx, input) if err != nil { - return diag.Errorf("updating CloudWatch RUM App Monitor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating CloudWatch RUM App Monitor (%s): %s", d.Id(), err) } } - return resourceAppMonitorRead(ctx, d, meta) + return append(diags, resourceAppMonitorRead(ctx, d, meta)...) } func resourceAppMonitorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) log.Printf("[DEBUG] Deleting CloudWatch RUM App Monitor: %s", d.Id()) @@ -263,14 +268,14 @@ func resourceAppMonitorDelete(ctx context.Context, d *schema.ResourceData, meta }) if tfawserr.ErrCodeEquals(err, cloudwatchrum.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting CloudWatch RUM App Monitor (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting CloudWatch RUM App Monitor (%s): %s", d.Id(), err) } - return nil + return diags } func FindAppMonitorByName(ctx context.Context, conn *cloudwatchrum.CloudWatchRUM, name string) (*cloudwatchrum.AppMonitor, error) { diff --git a/internal/service/rum/metrics_destination.go b/internal/service/rum/metrics_destination.go index 63f37d017d5..8104fe459de 100644 --- a/internal/service/rum/metrics_destination.go +++ b/internal/service/rum/metrics_destination.go @@ -15,6 +15,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -57,6 +58,7 @@ func ResourceMetricsDestination() *schema.Resource { } func resourceMetricsDestinationPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) name := d.Get("app_monitor_name").(string) @@ -76,17 +78,18 @@ func resourceMetricsDestinationPut(ctx context.Context, d *schema.ResourceData, _, err := conn.PutRumMetricsDestinationWithContext(ctx, input) if err != nil { - return diag.Errorf("putting CloudWatch RUM Metrics Destination (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "putting CloudWatch RUM Metrics Destination (%s): %s", name, err) } if d.IsNewResource() { d.SetId(name) } - return resourceMetricsDestinationRead(ctx, d, meta) + return append(diags, resourceMetricsDestinationRead(ctx, d, meta)...) } func resourceMetricsDestinationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) dest, err := FindMetricsDestinationByName(ctx, conn, d.Id()) @@ -94,11 +97,11 @@ func resourceMetricsDestinationRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] CloudWatch RUM Metrics Destination %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading CloudWatch RUM Metrics Destination (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading CloudWatch RUM Metrics Destination (%s): %s", d.Id(), err) } d.Set("app_monitor_name", d.Id()) @@ -106,10 +109,11 @@ func resourceMetricsDestinationRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrDestinationARN, dest.DestinationArn) d.Set(names.AttrIAMRoleARN, dest.IamRoleArn) - return nil + return diags } func resourceMetricsDestinationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RUMConn(ctx) input := &cloudwatchrum.DeleteRumMetricsDestinationInput{ @@ -125,14 +129,14 @@ func resourceMetricsDestinationDelete(ctx context.Context, d *schema.ResourceDat _, err := conn.DeleteRumMetricsDestinationWithContext(ctx, input) if tfawserr.ErrCodeEquals(err, cloudwatchrum.ErrCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting CloudWatch RUM Metrics Destination (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting CloudWatch RUM Metrics Destination (%s): %s", d.Id(), err) } - return nil + return diags } func FindMetricsDestinationByName(ctx context.Context, conn *cloudwatchrum.CloudWatchRUM, name string) (*cloudwatchrum.MetricDestinationSummary, error) { diff --git a/internal/service/s3/bucket.go b/internal/service/s3/bucket.go index 4052c5cddb2..9bd8d859b33 100644 --- a/internal/service/s3/bucket.go +++ b/internal/service/s3/bucket.go @@ -835,7 +835,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set(names.AttrPolicy, nil) default: - return diag.Errorf("reading S3 Bucket (%s) policy: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) policy: %s", d.Id(), err) } // @@ -859,7 +859,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("grant", nil) default: - return diag.Errorf("reading S3 Bucket (%s) ACL: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) ACL: %s", d.Id(), err) } // @@ -883,7 +883,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeNoSuchCORSConfiguration, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("cors_rule", nil) default: - return diag.Errorf("reading S3 Bucket (%s) CORS configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) CORS configuration: %s", d.Id(), err) } // @@ -911,7 +911,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("website", nil) default: - return diag.Errorf("reading S3 Bucket (%s) website configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) website configuration: %s", d.Id(), err) } // @@ -935,7 +935,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("versioning", nil) default: - return diag.Errorf("reading S3 Bucket (%s) versioning: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) versioning: %s", d.Id(), err) } // @@ -957,7 +957,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented, errCodeUnsupportedArgument, errCodeUnsupportedOperation): d.Set("acceleration_status", nil) default: - return diag.Errorf("reading S3 Bucket (%s) accelerate configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) accelerate configuration: %s", d.Id(), err) } // @@ -979,7 +979,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("request_payer", nil) default: - return diag.Errorf("reading S3 Bucket (%s) request payment configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) request payment configuration: %s", d.Id(), err) } // @@ -1003,7 +1003,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("logging", nil) default: - return diag.Errorf("reading S3 Bucket (%s) logging: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) logging: %s", d.Id(), err) } // @@ -1027,7 +1027,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("lifecycle_rule", nil) default: - return diag.Errorf("reading S3 Bucket (%s) lifecycle configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) lifecycle configuration: %s", d.Id(), err) } // @@ -1051,7 +1051,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented): d.Set("replication_configuration", nil) default: - return diag.Errorf("reading S3 Bucket (%s) replication configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) replication configuration: %s", d.Id(), err) } // @@ -1075,7 +1075,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf case tfresource.NotFound(err), tfawserr.ErrCodeEquals(err, errCodeMethodNotAllowed, errCodeNotImplemented, errCodeXNotImplemented, errCodeUnsupportedOperation): d.Set("server_side_encryption_configuration", nil) default: - return diag.Errorf("reading S3 Bucket (%s) server-side encryption configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) server-side encryption configuration: %s", d.Id(), err) } // @@ -1102,7 +1102,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("object_lock_enabled", nil) default: if partition := meta.(*conns.AWSClient).Partition; partition == names.StandardPartitionID || partition == names.USGovCloudPartitionID { - return diag.Errorf("reading S3 Bucket (%s) object lock configuration: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) object lock configuration: %s", d.Id(), err) } log.Printf("[WARN] Unable to read S3 Bucket (%s) Object Lock Configuration: %s", d.Id(), err) d.Set("object_lock_configuration", nil) @@ -1566,7 +1566,7 @@ func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta inte } if n, err := emptyBucket(ctx, conn, d.Id(), objectLockEnabled); err != nil { - return diag.Errorf("emptying S3 Bucket (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "emptying S3 Bucket (%s): %s", d.Id(), err) } else { log.Printf("[DEBUG] Deleted %d S3 objects", n) } diff --git a/internal/service/s3/bucket_accelerate_configuration.go b/internal/service/s3/bucket_accelerate_configuration.go index b1f86d36f14..d18b9d08244 100644 --- a/internal/service/s3/bucket_accelerate_configuration.go +++ b/internal/service/s3/bucket_accelerate_configuration.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -57,6 +58,7 @@ func resourceBucketAccelerateConfiguration() *schema.Resource { } func resourceBucketAccelerateConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -80,7 +82,7 @@ func resourceBucketAccelerateConfigurationCreate(ctx context.Context, d *schema. } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Accelerate Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Accelerate Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -90,18 +92,19 @@ func resourceBucketAccelerateConfigurationCreate(ctx context.Context, d *schema. }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Accelerate Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Accelerate Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketAccelerateConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketAccelerateConfigurationRead(ctx, d, meta)...) } func resourceBucketAccelerateConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := findBucketAccelerateConfiguration(ctx, conn, bucket, expectedBucketOwner) @@ -109,26 +112,27 @@ func resourceBucketAccelerateConfigurationRead(ctx context.Context, d *schema.Re if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Accelerate Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) d.Set(names.AttrStatus, output.Status) - return nil + return diags } func resourceBucketAccelerateConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketAccelerateConfigurationInput{ @@ -144,18 +148,19 @@ func resourceBucketAccelerateConfigurationUpdate(ctx context.Context, d *schema. _, err = conn.PutBucketAccelerateConfiguration(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) } - return resourceBucketAccelerateConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketAccelerateConfigurationRead(ctx, d, meta)...) } func resourceBucketAccelerateConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketAccelerateConfigurationInput{ @@ -172,16 +177,16 @@ func resourceBucketAccelerateConfigurationDelete(ctx context.Context, d *schema. _, err = conn.PutBucketAccelerateConfiguration(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Accelerate Configuration (%s): %s", d.Id(), err) } // Don't wait for the accelerate configuration to disappear as it still exists after suspension. - return nil + return diags } func findBucketAccelerateConfiguration(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) (*s3.GetBucketAccelerateConfigurationOutput, error) { diff --git a/internal/service/s3/bucket_acl.go b/internal/service/s3/bucket_acl.go index a8a820dbd1e..a3f3838f7b9 100644 --- a/internal/service/s3/bucket_acl.go +++ b/internal/service/s3/bucket_acl.go @@ -21,6 +21,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -148,6 +149,7 @@ func resourceBucketACL() *schema.Resource { } func resourceBucketACLCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -176,7 +178,7 @@ func resourceBucketACLCreate(ctx context.Context, d *schema.ResourceData, meta i } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) ACL: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) ACL: %s", bucket, err) } d.SetId(BucketACLCreateResourceID(bucket, expectedBucketOwner, acl)) @@ -186,18 +188,19 @@ func resourceBucketACLCreate(ctx context.Context, d *schema.ResourceData, meta i }) if err != nil { - return diag.Errorf("waiting for S3 Bucket ACL (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket ACL (%s) create: %s", d.Id(), err) } - return resourceBucketACLRead(ctx, d, meta) + return append(diags, resourceBucketACLRead(ctx, d, meta)...) } func resourceBucketACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, acl, err := BucketACLParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } bucketACL, err := findBucketACL(ctx, conn, bucket, expectedBucketOwner) @@ -205,29 +208,30 @@ func resourceBucketACLRead(ctx context.Context, d *schema.ResourceData, meta int if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket ACL (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket ACL (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket ACL (%s): %s", d.Id(), err) } if err := d.Set("access_control_policy", flattenBucketACL(bucketACL)); err != nil { - return diag.Errorf("setting access_control_policy: %s", err) + return sdkdiag.AppendErrorf(diags, "setting access_control_policy: %s", err) } d.Set("acl", acl) d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) - return nil + return diags } func resourceBucketACLUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, acl, err := BucketACLParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketAclInput{ @@ -249,7 +253,7 @@ func resourceBucketACLUpdate(ctx context.Context, d *schema.ResourceData, meta i _, err = conn.PutBucketAcl(ctx, input) if err != nil { - return diag.Errorf("updating S3 bucket ACL (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 bucket ACL (%s): %s", d.Id(), err) } if d.HasChange("acl") { @@ -257,7 +261,7 @@ func resourceBucketACLUpdate(ctx context.Context, d *schema.ResourceData, meta i d.SetId(BucketACLCreateResourceID(bucket, expectedBucketOwner, acl)) } - return resourceBucketACLRead(ctx, d, meta) + return append(diags, resourceBucketACLRead(ctx, d, meta)...) } func findBucketACL(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) (*s3.GetBucketAclOutput, error) { diff --git a/internal/service/s3/bucket_analytics_configuration.go b/internal/service/s3/bucket_analytics_configuration.go index 0e45efb5fa6..08aa87b2117 100644 --- a/internal/service/s3/bucket_analytics_configuration.go +++ b/internal/service/s3/bucket_analytics_configuration.go @@ -164,7 +164,7 @@ func resourceBucketAnalyticsConfigurationPut(ctx context.Context, d *schema.Reso } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Analytics Configuration (%s): %s", bucket, name, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Analytics Configuration (%s): %s", bucket, name, err) } if d.IsNewResource() { @@ -196,11 +196,11 @@ func resourceBucketAnalyticsConfigurationRead(ctx context.Context, d *schema.Res if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Analytics Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Analytics Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Analytics Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) @@ -246,7 +246,7 @@ func resourceBucketAnalyticsConfigurationDelete(ctx context.Context, d *schema.R return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Analytics Configuration (%s) delete: %s", d.Id(), err) } - return nil + return diags } func BucketAnalyticsConfigurationParseID(id string) (string, string, error) { diff --git a/internal/service/s3/bucket_cors_configuration.go b/internal/service/s3/bucket_cors_configuration.go index 611c8d42730..d824498d4c4 100644 --- a/internal/service/s3/bucket_cors_configuration.go +++ b/internal/service/s3/bucket_cors_configuration.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -90,6 +91,7 @@ func resourceBucketCorsConfiguration() *schema.Resource { } func resourceBucketCorsConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -113,7 +115,7 @@ func resourceBucketCorsConfigurationCreate(ctx context.Context, d *schema.Resour } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) CORS Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) CORS Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -123,18 +125,19 @@ func resourceBucketCorsConfigurationCreate(ctx context.Context, d *schema.Resour }) if err != nil { - return diag.Errorf("waiting for S3 Bucket CORS Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket CORS Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketCorsConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketCorsConfigurationRead(ctx, d, meta)...) } func resourceBucketCorsConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } corsRules, err := findCORSRules(ctx, conn, bucket, expectedBucketOwner) @@ -142,28 +145,29 @@ func resourceBucketCorsConfigurationRead(ctx context.Context, d *schema.Resource if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket CORS Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket CORS Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket CORS Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) if err := d.Set("cors_rule", flattenCORSRules(corsRules)); err != nil { - return diag.Errorf("setting cors_rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting cors_rule: %s", err) } d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) - return nil + return diags } func resourceBucketCorsConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketCorsInput{ @@ -179,18 +183,19 @@ func resourceBucketCorsConfigurationUpdate(ctx context.Context, d *schema.Resour _, err = conn.PutBucketCors(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket CORS Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket CORS Configuration (%s): %s", d.Id(), err) } - return resourceBucketCorsConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketCorsConfigurationRead(ctx, d, meta)...) } func resourceBucketCorsConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.DeleteBucketCorsInput{ @@ -203,11 +208,11 @@ func resourceBucketCorsConfigurationDelete(ctx context.Context, d *schema.Resour _, err = conn.DeleteBucketCors(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchCORSConfiguration) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket CORS Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket CORS Configuration (%s): %s", d.Id(), err) } _, err = tfresource.RetryUntilNotFound(ctx, bucketPropagationTimeout, func() (interface{}, error) { @@ -215,10 +220,10 @@ func resourceBucketCorsConfigurationDelete(ctx context.Context, d *schema.Resour }) if err != nil { - return diag.Errorf("waiting for S3 Bucket CORS Configuration (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket CORS Configuration (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findCORSRules(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) ([]types.CORSRule, error) { diff --git a/internal/service/s3/bucket_inventory.go b/internal/service/s3/bucket_inventory.go index 59db666e145..96ac6163041 100644 --- a/internal/service/s3/bucket_inventory.go +++ b/internal/service/s3/bucket_inventory.go @@ -225,7 +225,7 @@ func resourceBucketInventoryPut(ctx context.Context, d *schema.ResourceData, met } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Inventory: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Inventory: %s", bucket, err) } if d.IsNewResource() { @@ -257,11 +257,11 @@ func resourceBucketInventoryRead(ctx context.Context, d *schema.ResourceData, me if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Inventory (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Inventory (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Inventory (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) diff --git a/internal/service/s3/bucket_lifecycle_configuration.go b/internal/service/s3/bucket_lifecycle_configuration.go index 02c3f61cdc9..9cf2fe74edb 100644 --- a/internal/service/s3/bucket_lifecycle_configuration.go +++ b/internal/service/s3/bucket_lifecycle_configuration.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2/types/nullable" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -256,6 +257,7 @@ func resourceBucketLifecycleConfiguration() *schema.Resource { } func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -280,7 +282,7 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Lifecycle Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Lifecycle Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -288,18 +290,19 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R _, err = waitLifecycleRulesEquals(ctx, conn, bucket, expectedBucketOwner, rules, d.Timeout(schema.TimeoutCreate)) if err != nil { - diag.Errorf("waiting for S3 Bucket Lifecycle Configuration (%s) create: %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketLifecycleConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...) } func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } const ( @@ -338,28 +341,29 @@ func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.Res if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Lifecycle Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) if err := d.Set(names.AttrRule, flattenLifecycleRules(ctx, output)); err != nil { - return diag.Errorf("setting rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting rule: %s", err) } - return nil + return diags } func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } rules := expandLifecycleRules(ctx, d.Get(names.AttrRule).([]interface{})) @@ -378,24 +382,25 @@ func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.R }, errCodeNoSuchLifecycleConfiguration) if err != nil { - return diag.Errorf("updating S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } _, err = waitLifecycleRulesEquals(ctx, conn, bucket, expectedBucketOwner, rules, d.Timeout(schema.TimeoutUpdate)) if err != nil { - diag.Errorf("waiting for S3 Bucket Lifecycle Configuration (%s) update: %s", d.Id(), err) + sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) update: %s", d.Id(), err) } - return resourceBucketLifecycleConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...) } func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.DeleteBucketLifecycleInput{ @@ -408,11 +413,11 @@ func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.R _, err = conn.DeleteBucketLifecycle(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchLifecycleConfiguration) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } _, err = tfresource.RetryUntilNotFound(ctx, bucketPropagationTimeout, func() (interface{}, error) { @@ -420,10 +425,10 @@ func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.R }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Lifecyle Configuration (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecyle Configuration (%s) delete: %s", d.Id(), err) } - return nil + return diags } // suppressMissingFilterConfigurationBlock suppresses the diff that results from an omitted diff --git a/internal/service/s3/bucket_logging.go b/internal/service/s3/bucket_logging.go index 00d821b76cd..49f0c2e5ffc 100644 --- a/internal/service/s3/bucket_logging.go +++ b/internal/service/s3/bucket_logging.go @@ -182,10 +182,10 @@ func resourceBucketLoggingCreate(ctx context.Context, d *schema.ResourceData, me }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Logging (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Logging (%s) create: %s", d.Id(), err) } - return resourceBucketLoggingRead(ctx, d, meta) + return append(diags, resourceBucketLoggingRead(ctx, d, meta)...) } func resourceBucketLoggingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -263,7 +263,7 @@ func resourceBucketLoggingUpdate(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Logging (%s): %s", d.Id(), err) } - return resourceBucketLoggingRead(ctx, d, meta) + return append(diags, resourceBucketLoggingRead(ctx, d, meta)...) } func resourceBucketLoggingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -286,7 +286,7 @@ func resourceBucketLoggingDelete(ctx context.Context, d *schema.ResourceData, me _, err = conn.PutBucketLogging(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket) { - return nil + return diags } if err != nil { @@ -295,7 +295,7 @@ func resourceBucketLoggingDelete(ctx context.Context, d *schema.ResourceData, me // Don't wait for the logging to disappear as it still exists after update. - return nil + return diags } func findLoggingEnabled(ctx context.Context, conn *s3.Client, bucketName, expectedBucketOwner string) (*types.LoggingEnabled, error) { diff --git a/internal/service/s3/bucket_metric.go b/internal/service/s3/bucket_metric.go index 39f98855d7e..d2096c8f9f8 100644 --- a/internal/service/s3/bucket_metric.go +++ b/internal/service/s3/bucket_metric.go @@ -142,11 +142,11 @@ func resourceBucketMetricRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Metric (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Metric (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Metric (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) diff --git a/internal/service/s3/bucket_notification.go b/internal/service/s3/bucket_notification.go index 6e2ff2d162c..8fee05584cf 100644 --- a/internal/service/s3/bucket_notification.go +++ b/internal/service/s3/bucket_notification.go @@ -313,7 +313,7 @@ func resourceBucketNotificationPut(ctx context.Context, d *schema.ResourceData, } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Notification: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Notification: %s", bucket, err) } if d.IsNewResource() { @@ -324,7 +324,7 @@ func resourceBucketNotificationPut(ctx context.Context, d *schema.ResourceData, }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Notification (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Notification (%s) create: %s", d.Id(), err) } } @@ -375,11 +375,11 @@ func resourceBucketNotificationDelete(ctx context.Context, d *schema.ResourceDat _, err := conn.PutBucketNotificationConfiguration(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Notification (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Notification (%s): %s", d.Id(), err) } // Don't wait for the notification configuration to disappear as it still exists after update. diff --git a/internal/service/s3/bucket_object_lock_configuration.go b/internal/service/s3/bucket_object_lock_configuration.go index 50cf3f1993b..7b25c3094be 100644 --- a/internal/service/s3/bucket_object_lock_configuration.go +++ b/internal/service/s3/bucket_object_lock_configuration.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -98,6 +99,7 @@ func resourceBucketObjectLockConfiguration() *schema.Resource { } func resourceBucketObjectLockConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -132,7 +134,7 @@ func resourceBucketObjectLockConfigurationCreate(ctx context.Context, d *schema. } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Object Lock Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Object Lock Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -142,18 +144,19 @@ func resourceBucketObjectLockConfigurationCreate(ctx context.Context, d *schema. }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Object Lock Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Object Lock Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketObjectLockConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketObjectLockConfigurationRead(ctx, d, meta)...) } func resourceBucketObjectLockConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } objLockConfig, err := findObjectLockConfiguration(ctx, conn, bucket, expectedBucketOwner) @@ -161,29 +164,30 @@ func resourceBucketObjectLockConfigurationRead(ctx context.Context, d *schema.Re if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Object Lock Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) d.Set("object_lock_enabled", objLockConfig.ObjectLockEnabled) if err := d.Set(names.AttrRule, flattenObjectLockRule(objLockConfig.Rule)); err != nil { - return diag.Errorf("setting rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting rule: %s", err) } - return nil + return diags } func resourceBucketObjectLockConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutObjectLockConfigurationInput{ @@ -210,18 +214,19 @@ func resourceBucketObjectLockConfigurationUpdate(ctx context.Context, d *schema. _, err = conn.PutObjectLockConfiguration(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) } - return resourceBucketObjectLockConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketObjectLockConfigurationRead(ctx, d, meta)...) } func resourceBucketObjectLockConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutObjectLockConfigurationInput{ @@ -243,16 +248,16 @@ func resourceBucketObjectLockConfigurationDelete(ctx context.Context, d *schema. _, err = conn.PutObjectLockConfiguration(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeObjectLockConfigurationNotFoundError) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Object Lock Configuration (%s): %s", d.Id(), err) } // Don't wait for the object lock configuration to disappear as may still exist. - return nil + return diags } func findObjectLockConfiguration(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) (*types.ObjectLockConfiguration, error) { diff --git a/internal/service/s3/bucket_policy.go b/internal/service/s3/bucket_policy.go index e39cff1edf6..57e7d14c117 100644 --- a/internal/service/s3/bucket_policy.go +++ b/internal/service/s3/bucket_policy.go @@ -112,7 +112,7 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta } if err != nil { - return diag.Errorf("reading S3 Bucket Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Policy (%s): %s", d.Id(), err) } policy, err = verify.PolicyToSet(d.Get(names.AttrPolicy).(string), policy) diff --git a/internal/service/s3/bucket_policy_data_source.go b/internal/service/s3/bucket_policy_data_source.go index 9b5781012a7..2f3f99888f4 100644 --- a/internal/service/s3/bucket_policy_data_source.go +++ b/internal/service/s3/bucket_policy_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -32,23 +33,23 @@ func dataSourceBucketPolicy() *schema.Resource { } func dataSourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) name := d.Get(names.AttrBucket).(string) - policy, err := findBucketPolicy(ctx, conn, name) if err != nil { - return diag.Errorf("reading S3 Bucket (%s) Policy: %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) Policy: %s", name, err) } policy, err = structure.NormalizeJsonString(policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.SetId(name) d.Set(names.AttrPolicy, policy) - return nil + return diags } diff --git a/internal/service/s3/bucket_request_payment_configuration.go b/internal/service/s3/bucket_request_payment_configuration.go index 4b910e48c33..d9043faaf52 100644 --- a/internal/service/s3/bucket_request_payment_configuration.go +++ b/internal/service/s3/bucket_request_payment_configuration.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -57,6 +58,7 @@ func resourceBucketRequestPaymentConfiguration() *schema.Resource { } func resourceBucketRequestPaymentConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -80,7 +82,7 @@ func resourceBucketRequestPaymentConfigurationCreate(ctx context.Context, d *sch } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Request Payment Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Request Payment Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -90,18 +92,19 @@ func resourceBucketRequestPaymentConfigurationCreate(ctx context.Context, d *sch }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Request Payment Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Request Payment Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketRequestPaymentConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketRequestPaymentConfigurationRead(ctx, d, meta)...) } func resourceBucketRequestPaymentConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := findBucketRequestPayment(ctx, conn, bucket, expectedBucketOwner) @@ -109,26 +112,27 @@ func resourceBucketRequestPaymentConfigurationRead(ctx context.Context, d *schem if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Request Payment Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) d.Set("payer", output.Payer) - return nil + return diags } func resourceBucketRequestPaymentConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketRequestPaymentInput{ @@ -144,18 +148,19 @@ func resourceBucketRequestPaymentConfigurationUpdate(ctx context.Context, d *sch _, err = conn.PutBucketRequestPayment(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) } - return resourceBucketRequestPaymentConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketRequestPaymentConfigurationRead(ctx, d, meta)...) } func resourceBucketRequestPaymentConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketRequestPaymentInput{ @@ -173,16 +178,16 @@ func resourceBucketRequestPaymentConfigurationDelete(ctx context.Context, d *sch _, err = conn.PutBucketRequestPayment(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Request Payment Configuration (%s): %s", d.Id(), err) } // Don't wait for the request payment configuration to disappear as it still exists after reset. - return nil + return diags } func findBucketRequestPayment(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) (*s3.GetBucketRequestPaymentOutput, error) { diff --git a/internal/service/s3/bucket_server_side_encryption_configuration.go b/internal/service/s3/bucket_server_side_encryption_configuration.go index 1ddcb36fdb9..e675d20de1e 100644 --- a/internal/service/s3/bucket_server_side_encryption_configuration.go +++ b/internal/service/s3/bucket_server_side_encryption_configuration.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -82,6 +83,7 @@ func resourceBucketServerSideEncryptionConfiguration() *schema.Resource { } func resourceBucketServerSideEncryptionConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -105,7 +107,7 @@ func resourceBucketServerSideEncryptionConfigurationCreate(ctx context.Context, } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Server-side Encryption Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Server-side Encryption Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -115,18 +117,19 @@ func resourceBucketServerSideEncryptionConfigurationCreate(ctx context.Context, }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Server-side Encryption Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Server-side Encryption Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketServerSideEncryptionConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketServerSideEncryptionConfigurationRead(ctx, d, meta)...) } func resourceBucketServerSideEncryptionConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } sse, err := findServerSideEncryptionConfiguration(ctx, conn, bucket, expectedBucketOwner) @@ -134,28 +137,29 @@ func resourceBucketServerSideEncryptionConfigurationRead(ctx context.Context, d if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Server-side Encryption Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) if err := d.Set(names.AttrRule, flattenServerSideEncryptionRules(sse.Rules)); err != nil { - return diag.Errorf("setting rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting rule: %s", err) } - return nil + return diags } func resourceBucketServerSideEncryptionConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketEncryptionInput{ @@ -173,18 +177,19 @@ func resourceBucketServerSideEncryptionConfigurationUpdate(ctx context.Context, }, errCodeNoSuchBucket, errCodeOperationAborted) if err != nil { - return diag.Errorf("updating S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) } - return resourceBucketServerSideEncryptionConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketServerSideEncryptionConfigurationRead(ctx, d, meta)...) } func resourceBucketServerSideEncryptionConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.DeleteBucketEncryptionInput{ @@ -197,16 +202,16 @@ func resourceBucketServerSideEncryptionConfigurationDelete(ctx context.Context, _, err = conn.DeleteBucketEncryption(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeServerSideEncryptionConfigurationNotFound) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Server-side Encryption Configuration (%s): %s", d.Id(), err) } // Don't wait for the SSE configuration to disappear as the bucket now always has one. - return nil + return diags } func findServerSideEncryptionConfiguration(ctx context.Context, conn *s3.Client, bucketName, expectedBucketOwner string) (*types.ServerSideEncryptionConfiguration, error) { diff --git a/internal/service/s3/bucket_versioning.go b/internal/service/s3/bucket_versioning.go index 932ce153cf4..e94cca2439b 100644 --- a/internal/service/s3/bucket_versioning.go +++ b/internal/service/s3/bucket_versioning.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -100,6 +101,7 @@ func resourceBucketVersioning() *schema.Resource { } func resourceBucketVersioningCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -133,7 +135,7 @@ func resourceBucketVersioningCreate(ctx context.Context, d *schema.ResourceData, } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Versioning: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Versioning: %s", bucket, err) } } else { log.Printf("[DEBUG] Creating S3 bucket versioning for unversioned bucket: %s", bucket) @@ -143,15 +145,16 @@ func resourceBucketVersioningCreate(ctx context.Context, d *schema.ResourceData, // Waiting for the versioning configuration to appear is done in resource Read. - return resourceBucketVersioningRead(ctx, d, meta) + return append(diags, resourceBucketVersioningRead(ctx, d, meta)...) } func resourceBucketVersioningRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := waitForBucketVersioningStatus(ctx, conn, bucket, expectedBucketOwner) @@ -159,28 +162,29 @@ func resourceBucketVersioningRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Versioning (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Versioning (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Versioning (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) if err := d.Set("versioning_configuration", flattenVersioning(output)); err != nil { - return diag.Errorf("setting versioning_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting versioning_configuration: %s", err) } - return nil + return diags } func resourceBucketVersioningUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketVersioningInput{ @@ -198,23 +202,24 @@ func resourceBucketVersioningUpdate(ctx context.Context, d *schema.ResourceData, _, err = conn.PutBucketVersioning(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket Versioning (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Versioning (%s): %s", d.Id(), err) } - return resourceBucketVersioningRead(ctx, d, meta) + return append(diags, resourceBucketVersioningRead(ctx, d, meta)...) } func resourceBucketVersioningDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) if v := expandBucketVersioningConfiguration(d.Get("versioning_configuration").([]interface{})); v != nil && string(v.Status) == bucketVersioningStatusDisabled { log.Printf("[DEBUG] Removing S3 bucket versioning for unversioned bucket (%s) from state", d.Id()) - return nil + return diags } bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.PutBucketVersioningInput{ @@ -232,21 +237,21 @@ func resourceBucketVersioningDelete(ctx context.Context, d *schema.ResourceData, _, err = conn.PutBucketVersioning(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket) { - return nil + return diags } if tfawserr.ErrMessageContains(err, errCodeInvalidBucketState, "An Object Lock configuration is present on this bucket, so the versioning state cannot be changed") { log.Printf("[WARN] S3 bucket versioning cannot be suspended with Object Lock Configuration present on bucket (%s), removing from state", bucket) - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Versioning (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Versioning (%s): %s", d.Id(), err) } // Don't wait for the versioning configuration to disappear as it still exists after suspension. - return nil + return diags } func expandBucketVersioningConfiguration(l []interface{}) *types.VersioningConfiguration { diff --git a/internal/service/s3/bucket_website_configuration.go b/internal/service/s3/bucket_website_configuration.go index 525024a3619..b85050b181e 100644 --- a/internal/service/s3/bucket_website_configuration.go +++ b/internal/service/s3/bucket_website_configuration.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -180,6 +181,7 @@ func resourceBucketWebsiteConfiguration() *schema.Resource { } func resourceBucketWebsiteConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) websiteConfig := &types.WebsiteConfiguration{} @@ -203,7 +205,7 @@ func resourceBucketWebsiteConfigurationCreate(ctx context.Context, d *schema.Res if v, ok := d.GetOk("routing_rules"); ok { var unmarshalledRules []types.RoutingRule if err := json.Unmarshal([]byte(v.(string)), &unmarshalledRules); err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } websiteConfig.RoutingRules = unmarshalledRules } @@ -227,7 +229,7 @@ func resourceBucketWebsiteConfigurationCreate(ctx context.Context, d *schema.Res } if err != nil { - return diag.Errorf("creating S3 Bucket (%s) Website Configuration: %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Website Configuration: %s", bucket, err) } d.SetId(CreateResourceID(bucket, expectedBucketOwner)) @@ -237,18 +239,19 @@ func resourceBucketWebsiteConfigurationCreate(ctx context.Context, d *schema.Res }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Website Configuration (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Website Configuration (%s) create: %s", d.Id(), err) } - return resourceBucketWebsiteConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketWebsiteConfigurationRead(ctx, d, meta)...) } func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := findBucketWebsite(ctx, conn, bucket, expectedBucketOwner) @@ -256,31 +259,31 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Bucket Website Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Bucket Website Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket Website Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, bucket) if err := d.Set("error_document", flattenErrorDocument(output.ErrorDocument)); err != nil { - return diag.Errorf("setting error_document: %s", err) + return sdkdiag.AppendErrorf(diags, "setting error_document: %s", err) } d.Set(names.AttrExpectedBucketOwner, expectedBucketOwner) if err := d.Set("index_document", flattenIndexDocument(output.IndexDocument)); err != nil { - return diag.Errorf("setting index_document: %s", err) + return sdkdiag.AppendErrorf(diags, "setting index_document: %s", err) } if err := d.Set("redirect_all_requests_to", flattenRedirectAllRequestsTo(output.RedirectAllRequestsTo)); err != nil { - return diag.Errorf("setting redirect_all_requests_to: %s", err) + return sdkdiag.AppendErrorf(diags, "setting redirect_all_requests_to: %s", err) } if err := d.Set("routing_rule", flattenRoutingRules(output.RoutingRules)); err != nil { - return diag.Errorf("setting routing_rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting routing_rule: %s", err) } if output.RoutingRules != nil { rr, err := normalizeRoutingRules(output.RoutingRules) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set("routing_rules", rr) } else { @@ -288,22 +291,23 @@ func resourceBucketWebsiteConfigurationRead(ctx context.Context, d *schema.Resou } if output, err := findBucketLocation(ctx, conn, bucket, expectedBucketOwner); err != nil { - return diag.Errorf("reading S3 Bucket (%s) Location: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Bucket (%s) Location: %s", d.Id(), err) } else { endpoint, domain := bucketWebsiteEndpointAndDomain(bucket, string(output.LocationConstraint)) d.Set("website_domain", domain) d.Set("website_endpoint", endpoint) } - return nil + return diags } func resourceBucketWebsiteConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } websiteConfig := &types.WebsiteConfiguration{} @@ -326,7 +330,7 @@ func resourceBucketWebsiteConfigurationUpdate(ctx context.Context, d *schema.Res } else { var unmarshalledRules []types.RoutingRule if err := json.Unmarshal([]byte(d.Get("routing_rules").(string)), &unmarshalledRules); err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } websiteConfig.RoutingRules = unmarshalledRules } @@ -339,7 +343,7 @@ func resourceBucketWebsiteConfigurationUpdate(ctx context.Context, d *schema.Res if v, ok := d.GetOk("routing_rules"); ok { var unmarshalledRules []types.RoutingRule if err := json.Unmarshal([]byte(v.(string)), &unmarshalledRules); err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } websiteConfig.RoutingRules = unmarshalledRules } @@ -356,18 +360,19 @@ func resourceBucketWebsiteConfigurationUpdate(ctx context.Context, d *schema.Res _, err = conn.PutBucketWebsite(ctx, input) if err != nil { - return diag.Errorf("updating S3 Bucket Website Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Bucket Website Configuration (%s): %s", d.Id(), err) } - return resourceBucketWebsiteConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketWebsiteConfigurationRead(ctx, d, meta)...) } func resourceBucketWebsiteConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3Client(ctx) bucket, expectedBucketOwner, err := ParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3.DeleteBucketWebsiteInput{ @@ -380,11 +385,11 @@ func resourceBucketWebsiteConfigurationDelete(ctx context.Context, d *schema.Res _, err = conn.DeleteBucketWebsite(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchWebsiteConfiguration) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Bucket Website Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Bucket Website Configuration (%s): %s", d.Id(), err) } _, err = tfresource.RetryUntilNotFound(ctx, bucketPropagationTimeout, func() (interface{}, error) { @@ -392,10 +397,10 @@ func resourceBucketWebsiteConfigurationDelete(ctx context.Context, d *schema.Res }) if err != nil { - return diag.Errorf("waiting for S3 Bucket Website Configuration (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Website Configuration (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findBucketWebsite(ctx context.Context, conn *s3.Client, bucket, expectedBucketOwner string) (*s3.GetBucketWebsiteOutput, error) { diff --git a/internal/service/s3control/access_point.go b/internal/service/s3control/access_point.go index 584ccd378dd..92e4e096333 100644 --- a/internal/service/s3control/access_point.go +++ b/internal/service/s3control/access_point.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -158,6 +159,7 @@ func resourceAccessPoint() *schema.Resource { } func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -186,17 +188,17 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta output, err := conn.CreateAccessPoint(ctx, input) if err != nil { - return diag.Errorf("creating S3 Access Point (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Access Point (%s): %s", name, err) } resourceID, err := AccessPointCreateResourceID(aws.ToString(output.AccessPointArn)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } accountID, name, err = AccessPointParseResourceID(resourceID) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.SetId(resourceID) @@ -204,7 +206,7 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk(names.AttrPolicy); ok && v.(string) != "" && v.(string) != "{}" { policy, err := structure.NormalizeJsonString(v.(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointPolicyInput{ @@ -216,19 +218,20 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { - return diag.Errorf("creating S3 Access Point (%s) policy: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "creating S3 Access Point (%s) policy: %s", d.Id(), err) } } - return resourceAccessPointRead(ctx, d, meta) + return append(diags, resourceAccessPointRead(ctx, d, meta)...) } func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := findAccessPointByTwoPartKey(ctx, conn, accountID, name) @@ -236,11 +239,11 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Access Point (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Access Point (%s): %s", d.Id(), err) } s3OnOutposts := arn.IsARN(name) @@ -248,7 +251,7 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i if s3OnOutposts { accessPointARN, err := arn.Parse(name) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } // https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3onoutposts.html#amazons3onoutposts-resources-for-iam-policies. @@ -290,14 +293,14 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("network_origin", output.NetworkOrigin) if output.PublicAccessBlockConfiguration != nil { if err := d.Set("public_access_block_configuration", []interface{}{flattenPublicAccessBlockConfiguration(output.PublicAccessBlockConfiguration)}); err != nil { - return diag.Errorf("setting public_access_block_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting public_access_block_configuration: %s", err) } } else { d.Set("public_access_block_configuration", nil) } if output.VpcConfiguration != nil { if err := d.Set(names.AttrVPCConfiguration, []interface{}{flattenVPCConfiguration(output.VpcConfiguration)}); err != nil { - return diag.Errorf("setting vpc_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting vpc_configuration: %s", err) } } else { d.Set(names.AttrVPCConfiguration, nil) @@ -314,7 +317,7 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) @@ -322,25 +325,26 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("has_public_access_policy", false) d.Set(names.AttrPolicy, nil) } else { - return diag.Errorf("reading S3 Access Point (%s) policy: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Access Point (%s) policy: %s", d.Id(), err) } - return nil + return diags } func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChange(names.AttrPolicy) { if v, ok := d.GetOk(names.AttrPolicy); ok && v.(string) != "" && v.(string) != "{}" { policy, err := structure.NormalizeJsonString(v.(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointPolicyInput{ @@ -352,7 +356,7 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { - return diag.Errorf("updating S3 Access Point (%s) policy: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Access Point (%s) policy: %s", d.Id(), err) } } else { input := &s3control.DeleteAccessPointPolicyInput{ @@ -363,20 +367,21 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta _, err := conn.DeleteAccessPointPolicy(ctx, input) if err != nil { - return diag.Errorf("deleting S3 Access Point (%s) policy: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Access Point (%s) policy: %s", d.Id(), err) } } } - return resourceAccessPointRead(ctx, d, meta) + return append(diags, resourceAccessPointRead(ctx, d, meta)...) } func resourceAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Access Point: %s", d.Id()) @@ -386,14 +391,14 @@ func resourceAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Access Point (%s): %s", d.Id(), err) } - return nil + return diags } func findAccessPointByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*s3control.GetAccessPointOutput, error) { @@ -456,7 +461,7 @@ func AccessPointParseResourceID(id string) (string, string, error) { return v.AccountID, id, nil } - parts := strings.Split(id, multiRegionAccessPointResourceIDSeparator) + parts := strings.Split(id, accessPointResourceIDSeparator) if len(parts) == 2 && parts[0] != "" && parts[1] != "" { return parts[0], parts[1], nil diff --git a/internal/service/s3control/access_point_policy.go b/internal/service/s3control/access_point_policy.go index de79d6a69a0..87604d42a27 100644 --- a/internal/service/s3control/access_point_policy.go +++ b/internal/service/s3control/access_point_policy.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -61,21 +62,22 @@ func resourceAccessPointPolicy() *schema.Resource { } func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) resourceID, err := AccessPointCreateResourceID(d.Get("access_point_arn").(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } accountID, name, err := AccessPointParseResourceID(resourceID) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointPolicyInput{ @@ -87,20 +89,21 @@ func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { - return diag.Errorf("creating S3 Access Point (%s) Policy: %s", resourceID, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Access Point (%s) Policy: %s", resourceID, err) } d.SetId(resourceID) - return resourceAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceAccessPointPolicyRead(ctx, d, meta)...) } func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policy, status, err := findAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) @@ -108,11 +111,11 @@ func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Access Point Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Access Point Policy (%s): %s", d.Id(), err) } d.Set("has_public_access_policy", status.IsPublic) @@ -120,7 +123,7 @@ func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, if policy != "" { policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) @@ -128,20 +131,21 @@ func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrPolicy, "") } - return nil + return diags } func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointPolicyInput{ @@ -153,18 +157,19 @@ func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { - return diag.Errorf("updating S3 Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Access Point Policy (%s): %s", d.Id(), err) } - return resourceAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceAccessPointPolicyRead(ctx, d, meta)...) } func resourceAccessPointPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Access Point Policy: %s", d.Id()) @@ -174,14 +179,14 @@ func resourceAccessPointPolicyDelete(ctx context.Context, d *schema.ResourceData }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Access Point Policy (%s): %s", d.Id(), err) } - return nil + return diags } func resourceAccessPointPolicyImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { diff --git a/internal/service/s3control/account_public_access_block.go b/internal/service/s3control/account_public_access_block.go index c48b12dbf30..82830a525e4 100644 --- a/internal/service/s3control/account_public_access_block.go +++ b/internal/service/s3control/account_public_access_block.go @@ -18,6 +18,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -68,6 +69,7 @@ func resourceAccountPublicAccessBlock() *schema.Resource { } func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -88,7 +90,7 @@ func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.Resou _, err := conn.PutPublicAccessBlock(ctx, input) if err != nil { - return diag.Errorf("creating S3 Account Public Access Block (%s): %s", accountID, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Account Public Access Block (%s): %s", accountID, err) } d.SetId(accountID) @@ -98,13 +100,14 @@ func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.Resou }) if err != nil { - return diag.Errorf("waiting for S3 Account Public Access Block (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Account Public Access Block (%s) create: %s", d.Id(), err) } - return resourceAccountPublicAccessBlockRead(ctx, d, meta) + return append(diags, resourceAccountPublicAccessBlockRead(ctx, d, meta)...) } func resourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) output, err := findPublicAccessBlockByAccountID(ctx, conn, d.Id()) @@ -112,11 +115,11 @@ func resourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resourc if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Account Public Access Block (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Account Public Access Block (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Account Public Access Block (%s): %s", d.Id(), err) } d.Set(names.AttrAccountID, d.Id()) @@ -125,10 +128,11 @@ func resourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resourc d.Set("ignore_public_acls", output.IgnorePublicAcls) d.Set("restrict_public_buckets", output.RestrictPublicBuckets) - return nil + return diags } func resourceAccountPublicAccessBlockUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) publicAccessBlockConfiguration := &types.PublicAccessBlockConfiguration{ @@ -145,17 +149,18 @@ func resourceAccountPublicAccessBlockUpdate(ctx context.Context, d *schema.Resou _, err := conn.PutPublicAccessBlock(ctx, input) if err != nil { - return diag.Errorf("updating S3 Account Public Access Block (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Account Public Access Block (%s): %s", d.Id(), err) } if _, err := waitPublicAccessBlockEqual(ctx, conn, d.Id(), publicAccessBlockConfiguration); err != nil { - return diag.Errorf("waiting for S3 Account Public Access Block (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Account Public Access Block (%s) update: %s", d.Id(), err) } - return resourceAccountPublicAccessBlockRead(ctx, d, meta) + return append(diags, resourceAccountPublicAccessBlockRead(ctx, d, meta)...) } func resourceAccountPublicAccessBlockDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) log.Printf("[DEBUG] Deleting S3 Account Public Access Block: %s", d.Id()) @@ -164,14 +169,14 @@ func resourceAccountPublicAccessBlockDelete(ctx context.Context, d *schema.Resou }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchPublicAccessBlockConfiguration) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Account Public Access Block (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Account Public Access Block (%s): %s", d.Id(), err) } - return nil + return diags } func findPublicAccessBlockByAccountID(ctx context.Context, conn *s3control.Client, accountID string) (*types.PublicAccessBlockConfiguration, error) { diff --git a/internal/service/s3control/account_public_access_block_data_source.go b/internal/service/s3control/account_public_access_block_data_source.go index 75c8ce8e764..4f43908828c 100644 --- a/internal/service/s3control/account_public_access_block_data_source.go +++ b/internal/service/s3control/account_public_access_block_data_source.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -45,6 +46,7 @@ func dataSourceAccountPublicAccessBlock() *schema.Resource { } func dataSourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -55,7 +57,7 @@ func dataSourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resou output, err := findPublicAccessBlockByAccountID(ctx, conn, accountID) if err != nil { - return diag.Errorf("reading S3 Account Public Access Block (%s): %s", accountID, err) + return sdkdiag.AppendErrorf(diags, "reading S3 Account Public Access Block (%s): %s", accountID, err) } d.SetId(accountID) @@ -64,5 +66,5 @@ func dataSourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resou d.Set("ignore_public_acls", output.IgnorePublicAcls) d.Set("restrict_public_buckets", output.RestrictPublicBuckets) - return nil + return diags } diff --git a/internal/service/s3control/bucket.go b/internal/service/s3control/bucket.go index 71d0db65263..228da2a6a2b 100644 --- a/internal/service/s3control/bucket.go +++ b/internal/service/s3control/bucket.go @@ -21,6 +21,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -84,6 +85,7 @@ func resourceBucket() *schema.Resource { } func resourceBucketCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get(names.AttrBucket).(string) @@ -95,34 +97,35 @@ func resourceBucketCreate(ctx context.Context, d *schema.ResourceData, meta inte output, err := conn.CreateBucket(ctx, input) if err != nil { - return diag.Errorf("creating S3 Control Bucket (%s): %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Control Bucket (%s): %s", bucket, err) } d.SetId(aws.ToString(output.BucketArn)) if tags := keyValueTagsS3(ctx, getTagsInS3(ctx)); len(tags) > 0 { if err := bucketUpdateTags(ctx, conn, d.Id(), nil, tags); err != nil { - return diag.Errorf("adding S3 Control Bucket (%s) tags: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "adding S3 Control Bucket (%s) tags: %s", d.Id(), err) } } - return resourceBucketRead(ctx, d, meta) + return append(diags, resourceBucketRead(ctx, d, meta)...) } func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } // ARN resource format: outpost//bucket/ arnResourceParts := strings.Split(parsedArn.Resource, "/") if parsedArn.AccountID == "" || len(arnResourceParts) != 4 { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } output, err := findBucketByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) @@ -130,11 +133,11 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Control Bucket (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Control Bucket (%s): %s", d.Id(), err) } d.Set(names.AttrARN, d.Id()) @@ -148,35 +151,37 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf tags, err := bucketListTags(ctx, conn, d.Id()) if err != nil { - return diag.Errorf("listing tags for S3 Control Bucket (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing tags for S3 Control Bucket (%s): %s", d.Id(), err) } setTagsOutS3(ctx, tagsS3(tags)) - return nil + return diags } func resourceBucketUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) if d.HasChange(names.AttrTagsAll) { o, n := d.GetChange(names.AttrTagsAll) if err := bucketUpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return diag.Errorf("updating S3 Control Bucket (%s) tags: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Control Bucket (%s) tags: %s", d.Id(), err) } } - return resourceBucketRead(ctx, d, meta) + return append(diags, resourceBucketRead(ctx, d, meta)...) } func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.DeleteBucketInput{ @@ -193,14 +198,14 @@ func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta inte }, errCodeInvalidBucketState) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchOutpost) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Control Bucket (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Control Bucket (%s): %s", d.Id(), err) } - return nil + return diags } func findBucketByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketOutput, error) { diff --git a/internal/service/s3control/bucket_lifecycle_configuration.go b/internal/service/s3control/bucket_lifecycle_configuration.go index d0e7043848a..bf1d1bcd889 100644 --- a/internal/service/s3control/bucket_lifecycle_configuration.go +++ b/internal/service/s3control/bucket_lifecycle_configuration.go @@ -19,6 +19,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -128,18 +129,18 @@ func resourceBucketLifecycleConfiguration() *schema.Resource { } func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get(names.AttrBucket).(string) - parsedArn, err := arn.Parse(bucket) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if parsedArn.AccountID == "" { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } input := &s3control.PutBucketLifecycleConfigurationInput{ @@ -153,25 +154,26 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R _, err = conn.PutBucketLifecycleConfiguration(ctx, input) if err != nil { - return diag.Errorf("creating S3 Control Bucket Lifecycle Configuration (%s): %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Control Bucket Lifecycle Configuration (%s): %s", bucket, err) } d.SetId(bucket) - return resourceBucketLifecycleConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...) } func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if parsedArn.AccountID == "" { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } output, err := findBucketLifecycleConfigurationByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) @@ -179,33 +181,34 @@ func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.Res if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket Lifecycle Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, d.Id()) if err := d.Set(names.AttrRule, flattenLifecycleRules(ctx, output.Rules)); err != nil { - return diag.Errorf("setting rule: %s", err) + return sdkdiag.AppendErrorf(diags, "setting rule: %s", err) } - return nil + return diags } func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if parsedArn.AccountID == "" { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } input := &s3control.PutBucketLifecycleConfigurationInput{ @@ -219,23 +222,24 @@ func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.R _, err = conn.PutBucketLifecycleConfiguration(ctx, input) if err != nil { - return diag.Errorf("updating S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } - return resourceBucketLifecycleConfigurationRead(ctx, d, meta) + return append(diags, resourceBucketLifecycleConfigurationRead(ctx, d, meta)...) } func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if parsedArn.AccountID == "" { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } log.Printf("[DEBUG] Deleting S3 Control Bucket Lifecycle Configuration: %s", d.Id()) @@ -245,14 +249,14 @@ func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.R }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchLifecycleConfiguration, errCodeNoSuchOutpost) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) } - return nil + return diags } func findBucketLifecycleConfigurationByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketLifecycleConfigurationOutput, error) { diff --git a/internal/service/s3control/bucket_policy.go b/internal/service/s3control/bucket_policy.go index dc84241f5b5..ff1fe7431fa 100644 --- a/internal/service/s3control/bucket_policy.go +++ b/internal/service/s3control/bucket_policy.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -57,13 +58,14 @@ func resourceBucketPolicy() *schema.Resource { } func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get(names.AttrBucket).(string) policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutBucketPolicyInput{ @@ -74,24 +76,25 @@ func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, met _, err = conn.PutBucketPolicy(ctx, input) if err != nil { - return diag.Errorf("creating S3 Control Bucket Policy (%s): %s", bucket, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Control Bucket Policy (%s): %s", bucket, err) } d.SetId(bucket) - return resourceBucketPolicyRead(ctx, d, meta) + return append(diags, resourceBucketPolicyRead(ctx, d, meta)...) } func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if parsedArn.AccountID == "" { - return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) + return sdkdiag.AppendErrorf(diags, "parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } output, err := findBucketPolicyByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) @@ -99,11 +102,11 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Control Bucket Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Control Bucket Policy (%s): %s", d.Id(), err) } d.Set(names.AttrBucket, d.Id()) @@ -111,7 +114,7 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta if output.Policy != nil { policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), aws.ToString(output.Policy)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) @@ -119,15 +122,16 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrPolicy, "") } - return nil + return diags } func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutBucketPolicyInput{ @@ -138,19 +142,20 @@ func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, met _, err = conn.PutBucketPolicy(ctx, input) if err != nil { - return diag.Errorf("updating S3 Control Bucket Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Control Bucket Policy (%s): %s", d.Id(), err) } - return resourceBucketPolicyRead(ctx, d, meta) + return append(diags, resourceBucketPolicyRead(ctx, d, meta)...) } func resourceBucketPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Control Bucket Policy: %s", d.Id()) @@ -160,14 +165,14 @@ func resourceBucketPolicyDelete(ctx context.Context, d *schema.ResourceData, met }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchBucketPolicy, errCodeNoSuchOutpost) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Control Bucket Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Control Bucket Policy (%s): %s", d.Id(), err) } - return nil + return diags } func findBucketPolicyByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketPolicyOutput, error) { diff --git a/internal/service/s3control/multi_region_access_point.go b/internal/service/s3control/multi_region_access_point.go index 4ef6f74bc56..65f22733d00 100644 --- a/internal/service/s3control/multi_region_access_point.go +++ b/internal/service/s3control/multi_region_access_point.go @@ -20,6 +20,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -151,6 +152,7 @@ func resourceMultiRegionAccessPoint() *schema.Resource { } func resourceMultiRegionAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -173,24 +175,25 @@ func resourceMultiRegionAccessPointCreate(ctx context.Context, d *schema.Resourc }) if err != nil { - return diag.Errorf("creating S3 Multi-Region Access Point (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Multi-Region Access Point (%s): %s", id, err) } d.SetId(id) if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for S3 Multi-Region Access Point (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Multi-Region Access Point (%s) create: %s", d.Id(), err) } - return resourceMultiRegionAccessPointRead(ctx, d, meta) + return append(diags, resourceMultiRegionAccessPointRead(ctx, d, meta)...) } func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } accessPoint, err := findMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) @@ -198,11 +201,11 @@ func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceD if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Multi-Region Access Point (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Multi-Region Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Multi-Region Access Point (%s): %s", d.Id(), err) } alias := aws.ToString(accessPoint.Alias) @@ -216,21 +219,22 @@ func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceD d.Set(names.AttrAlias, alias) d.Set(names.AttrARN, arn) if err := d.Set("details", []interface{}{flattenMultiRegionAccessPointReport(accessPoint)}); err != nil { - return diag.Errorf("setting details: %s", err) + return sdkdiag.AppendErrorf(diags, "setting details: %s", err) } // https://docs.aws.amazon.com/AmazonS3/latest/userguide//MultiRegionAccessPointRequests.html#MultiRegionAccessPointHostnames. d.Set(names.AttrDomainName, meta.(*conns.AWSClient).PartitionHostname(ctx, alias+".accesspoint.s3-global")) d.Set(names.AttrStatus, accessPoint.Status) - return nil + return diags } func resourceMultiRegionAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.DeleteMultiRegionAccessPointInput{ @@ -247,18 +251,18 @@ func resourceMultiRegionAccessPointDelete(ctx context.Context, d *schema.Resourc }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchMultiRegionAccessPoint) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Multi-Region Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Multi-Region Access Point (%s): %s", d.Id(), err) } if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for S3 Multi-Region Access Point (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Multi-Region Access Point (%s) delete: %s", d.Id(), err) } - return nil + return diags } func findMultiRegionAccessPointByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.MultiRegionAccessPointReport, error) { diff --git a/internal/service/s3control/multi_region_access_point_data_source.go b/internal/service/s3control/multi_region_access_point_data_source.go index dd41fd9fef8..4c82271dd7f 100644 --- a/internal/service/s3control/multi_region_access_point_data_source.go +++ b/internal/service/s3control/multi_region_access_point_data_source.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -102,6 +103,7 @@ func dataSourceMultiRegionAccessPoint() *schema.Resource { } func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -113,7 +115,7 @@ func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.Re accessPoint, err := findMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) if err != nil { - return diag.Errorf("reading S3 Multi Region Access Point (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading S3 Multi Region Access Point (%s): %s", name, err) } d.SetId(MultiRegionAccessPointCreateResourceID(accountID, name)) @@ -136,5 +138,5 @@ func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.Re d.Set("regions", flattenRegionReports(accessPoint.Regions)) d.Set(names.AttrStatus, accessPoint.Status) - return nil + return diags } diff --git a/internal/service/s3control/multi_region_access_point_policy.go b/internal/service/s3control/multi_region_access_point_policy.go index 7e7726abae0..975f9f11e29 100644 --- a/internal/service/s3control/multi_region_access_point_policy.go +++ b/internal/service/s3control/multi_region_access_point_policy.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -88,6 +89,7 @@ func resourceMultiRegionAccessPointPolicy() *schema.Resource { } func resourceMultiRegionAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -110,24 +112,25 @@ func resourceMultiRegionAccessPointPolicyCreate(ctx context.Context, d *schema.R }) if err != nil { - return diag.Errorf("creating S3 Multi-Region Access Point (%s) Policy: %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Multi-Region Access Point (%s) Policy: %s", id, err) } d.SetId(id) if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for S3 Multi-Region Access Point Policy (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Multi-Region Access Point Policy (%s) create: %s", d.Id(), err) } - return resourceMultiRegionAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceMultiRegionAccessPointPolicyRead(ctx, d, meta)...) } func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policyDocument, err := findMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx, conn, accountID, name) @@ -135,11 +138,11 @@ func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.Res if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Multi-Region Access Point Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Multi-Region Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Multi-Region Access Point Policy (%s): %s", d.Id(), err) } d.Set(names.AttrAccountID, accountID) @@ -150,7 +153,7 @@ func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.Res } if err := d.Set("details", []interface{}{flattenMultiRegionAccessPointPolicyDocument(name, policyDocument, oldDetails)}); err != nil { - return diag.Errorf("setting details: %s", err) + return sdkdiag.AppendErrorf(diags, "setting details: %s", err) } } else { d.Set("details", nil) @@ -166,15 +169,16 @@ func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.Res d.Set("proposed", nil) } - return nil + return diags } func resourceMultiRegionAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, _, err := MultiRegionAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutMultiRegionAccessPointPolicyInput{ @@ -191,14 +195,14 @@ func resourceMultiRegionAccessPointPolicyUpdate(ctx context.Context, d *schema.R }) if err != nil { - return diag.Errorf("updating S3 Multi-Region Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Multi-Region Access Point Policy (%s): %s", d.Id(), err) } if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutUpdate)); err != nil { - return diag.Errorf("waiting for S3 Multi-Region Access Point Policy (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for S3 Multi-Region Access Point Policy (%s) update: %s", d.Id(), err) } - return resourceMultiRegionAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceMultiRegionAccessPointPolicyRead(ctx, d, meta)...) } func findMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.MultiRegionAccessPointPolicyDocument, error) { diff --git a/internal/service/s3control/object_lambda_access_point.go b/internal/service/s3control/object_lambda_access_point.go index 77ec5648cb7..ae5507dccd6 100644 --- a/internal/service/s3control/object_lambda_access_point.go +++ b/internal/service/s3control/object_lambda_access_point.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -133,6 +134,7 @@ func resourceObjectLambdaAccessPoint() *schema.Resource { } func resourceObjectLambdaAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -153,20 +155,21 @@ func resourceObjectLambdaAccessPointCreate(ctx context.Context, d *schema.Resour _, err := conn.CreateAccessPointForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("creating S3 Object Lambda Access Point (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Object Lambda Access Point (%s): %s", id, err) } d.SetId(id) - return resourceObjectLambdaAccessPointRead(ctx, d, meta) + return append(diags, resourceObjectLambdaAccessPointRead(ctx, d, meta)...) } func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } outputConfiguration, err := findObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name) @@ -174,11 +177,11 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Object Lambda Access Point (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) } d.Set(names.AttrAccountID, accountID) @@ -192,27 +195,28 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource }.String() d.Set(names.AttrARN, arn) if err := d.Set(names.AttrConfiguration, []interface{}{flattenObjectLambdaConfiguration(outputConfiguration)}); err != nil { - return diag.Errorf("setting configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) } d.Set(names.AttrName, name) outputAlias, err := findObjectLambdaAccessPointAliasByTwoPartKey(ctx, conn, accountID, name) if err != nil { - return diag.Errorf("reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) } d.Set(names.AttrAlias, outputAlias.Value) - return nil + return diags } func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointConfigurationForObjectLambdaInput{ @@ -227,18 +231,19 @@ func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.Resour _, err = conn.PutAccessPointConfigurationForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("updating S3 Object Lambda Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Object Lambda Access Point (%s): %s", d.Id(), err) } - return resourceObjectLambdaAccessPointRead(ctx, d, meta) + return append(diags, resourceObjectLambdaAccessPointRead(ctx, d, meta)...) } func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Object Lambda Access Point: %s", d.Id()) @@ -248,14 +253,14 @@ func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.Resour }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Object Lambda Access Point (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Object Lambda Access Point (%s): %s", d.Id(), err) } - return nil + return diags } func findObjectLambdaAccessPointConfigurationByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.ObjectLambdaConfiguration, error) { diff --git a/internal/service/s3control/object_lambda_access_point_policy.go b/internal/service/s3control/object_lambda_access_point_policy.go index 4e129dc98d6..cbadf48daa4 100644 --- a/internal/service/s3control/object_lambda_access_point_policy.go +++ b/internal/service/s3control/object_lambda_access_point_policy.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -66,11 +67,12 @@ func resourceObjectLambdaAccessPointPolicy() *schema.Resource { } func resourceObjectLambdaAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } accountID := meta.(*conns.AWSClient).AccountID @@ -88,20 +90,21 @@ func resourceObjectLambdaAccessPointPolicyCreate(ctx context.Context, d *schema. _, err = conn.PutAccessPointPolicyForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("creating S3 Object Lambda Access Point (%s) Policy: %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Object Lambda Access Point (%s) Policy: %s", id, err) } d.SetId(id) - return resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta)...) } func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policy, status, err := findObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) @@ -109,11 +112,11 @@ func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.Re if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Object Lambda Access Point Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) } d.Set(names.AttrAccountID, accountID) @@ -123,7 +126,7 @@ func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.Re if policy != "" { policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) @@ -131,20 +134,21 @@ func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.Re d.Set(names.AttrPolicy, "") } - return nil + return diags } func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &s3control.PutAccessPointPolicyForObjectLambdaInput{ @@ -156,18 +160,19 @@ func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema. _, err = conn.PutAccessPointPolicyForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("updating S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) } - return resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta) + return append(diags, resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta)...) } func resourceObjectLambdaAccessPointPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Object Lambda Access Point Policy: %s", d.Id()) @@ -177,14 +182,14 @@ func resourceObjectLambdaAccessPointPolicyDelete(ctx context.Context, d *schema. }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) } - return nil + return diags } func findObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (string, *types.PolicyStatus, error) { diff --git a/internal/service/s3control/storage_lens_configuration.go b/internal/service/s3control/storage_lens_configuration.go index cd6321c1fca..c1f95e1a3b2 100644 --- a/internal/service/s3control/storage_lens_configuration.go +++ b/internal/service/s3control/storage_lens_configuration.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -394,6 +395,7 @@ func resourceStorageLensConfiguration() *schema.Resource { } func resourceStorageLensConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID @@ -416,20 +418,21 @@ func resourceStorageLensConfigurationCreate(ctx context.Context, d *schema.Resou _, err := conn.PutStorageLensConfiguration(ctx, input) if err != nil { - return diag.Errorf("creating S3 Storage Lens Configuration (%s): %s", id, err) + return sdkdiag.AppendErrorf(diags, "creating S3 Storage Lens Configuration (%s): %s", id, err) } d.SetId(id) - return resourceStorageLensConfigurationRead(ctx, d, meta) + return append(diags, resourceStorageLensConfigurationRead(ctx, d, meta)...) } func resourceStorageLensConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } output, err := findStorageLensConfigurationByAccountIDAndConfigID(ctx, conn, accountID, configID) @@ -437,37 +440,38 @@ func resourceStorageLensConfigurationRead(ctx context.Context, d *schema.Resourc if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Storage Lens Configuration (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading S3 Storage Lens Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading S3 Storage Lens Configuration (%s): %s", d.Id(), err) } d.Set(names.AttrAccountID, accountID) d.Set(names.AttrARN, output.StorageLensArn) d.Set("config_id", configID) if err := d.Set("storage_lens_configuration", []interface{}{flattenStorageLensConfiguration(output)}); err != nil { - return diag.Errorf("setting storage_lens_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting storage_lens_configuration: %s", err) } tags, err := storageLensConfigurationListTags(ctx, conn, accountID, configID) if err != nil { - return diag.Errorf("listing tags for S3 Storage Lens Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing tags for S3 Storage Lens Configuration (%s): %s", d.Id(), err) } setTagsOutS3(ctx, tagsS3(tags)) - return nil + return diags } func resourceStorageLensConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -484,7 +488,7 @@ func resourceStorageLensConfigurationUpdate(ctx context.Context, d *schema.Resou _, err := conn.PutStorageLensConfiguration(ctx, input) if err != nil { - return diag.Errorf("updating S3 Storage Lens Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Storage Lens Configuration (%s): %s", d.Id(), err) } } @@ -492,19 +496,20 @@ func resourceStorageLensConfigurationUpdate(ctx context.Context, d *schema.Resou o, n := d.GetChange(names.AttrTagsAll) if err := storageLensConfigurationUpdateTags(ctx, conn, accountID, configID, o, n); err != nil { - return diag.Errorf("updating S3 Storage Lens Configuration (%s) tags: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating S3 Storage Lens Configuration (%s) tags: %s", d.Id(), err) } } - return resourceStorageLensConfigurationRead(ctx, d, meta) + return append(diags, resourceStorageLensConfigurationRead(ctx, d, meta)...) } func resourceStorageLensConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } log.Printf("[DEBUG] Deleting S3 Storage Lens Configuration: %s", d.Id()) @@ -514,14 +519,14 @@ func resourceStorageLensConfigurationDelete(ctx context.Context, d *schema.Resou }) if tfawserr.ErrHTTPStatusCodeEquals(err, http.StatusNotFound) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting S3 Storage Lens Configuration (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting S3 Storage Lens Configuration (%s): %s", d.Id(), err) } - return nil + return diags } const storageLensConfigurationResourceIDSeparator = ":" diff --git a/internal/service/scheduler/schedule.go b/internal/service/scheduler/schedule.go index 2ffcfb5adc5..0a6a19dba43 100644 --- a/internal/service/scheduler/schedule.go +++ b/internal/service/scheduler/schedule.go @@ -432,6 +432,7 @@ const ( ) func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) @@ -484,11 +485,11 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, err) } if out == nil || out.ScheduleArn == nil { - return create.DiagError(names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, errors.New("empty output")) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, errors.New("empty output")) } // When the schedule is created without specifying a group, it is assigned @@ -501,21 +502,22 @@ func resourceScheduleCreate(ctx context.Context, d *schema.ResourceData, meta in id, err := ResourceScheduleIDFromARN(aws.ToString(out.ScheduleArn)) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, fmt.Errorf("invalid resource id: %w", err)) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionCreating, ResNameSchedule, name, fmt.Errorf("invalid resource id: %w", err)) } d.SetId(id) - return resourceScheduleRead(ctx, d, meta) + return append(diags, resourceScheduleRead(ctx, d, meta)...) } func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { // nosemgrep:ci.scheduler-in-func-name + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) groupName, scheduleName, err := ResourceScheduleParseID(d.Id()) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionReading, ResNameSchedule, d.Id(), fmt.Errorf("invalid resource id: %w", err)) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionReading, ResNameSchedule, d.Id(), fmt.Errorf("invalid resource id: %w", err)) } out, err := findScheduleByTwoPartKey(ctx, conn, groupName, scheduleName) @@ -523,11 +525,11 @@ func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EventBridge Scheduler Schedule (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionReading, ResNameSchedule, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionReading, ResNameSchedule, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -540,7 +542,7 @@ func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, meta inte } if err := d.Set("flexible_time_window", []interface{}{flattenFlexibleTimeWindow(out.FlexibleTimeWindow)}); err != nil { - return create.DiagError(names.Scheduler, create.ErrActionSetting, ResNameSchedule, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionSetting, ResNameSchedule, d.Id(), err) } d.Set(names.AttrGroupName, out.GroupName) @@ -559,13 +561,14 @@ func resourceScheduleRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set(names.AttrState, string(out.State)) if err := d.Set(names.AttrTarget, []interface{}{flattenTarget(ctx, out.Target)}); err != nil { - return create.DiagError(names.Scheduler, create.ErrActionSetting, ResNameSchedule, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionSetting, ResNameSchedule, d.Id(), err) } - return nil + return diags } func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) in := &scheduler.UpdateScheduleInput{ @@ -609,19 +612,20 @@ func resourceScheduleUpdate(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionUpdating, ResNameSchedule, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionUpdating, ResNameSchedule, d.Id(), err) } - return resourceScheduleRead(ctx, d, meta) + return append(diags, resourceScheduleRead(ctx, d, meta)...) } func resourceScheduleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) groupName, scheduleName, err := ResourceScheduleParseID(d.Id()) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionDeleting, ResNameSchedule, d.Id(), fmt.Errorf("invalid resource id: %w", err)) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionDeleting, ResNameSchedule, d.Id(), fmt.Errorf("invalid resource id: %w", err)) } log.Printf("[INFO] Deleting EventBridge Scheduler Schedule %s", d.Id()) @@ -634,13 +638,13 @@ func resourceScheduleDelete(ctx context.Context, d *schema.ResourceData, meta in if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.Scheduler, create.ErrActionDeleting, ResNameSchedule, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionDeleting, ResNameSchedule, d.Id(), err) } - return nil + return diags } func findScheduleByTwoPartKey(ctx context.Context, conn *scheduler.Client, groupName, scheduleName string) (*scheduler.GetScheduleOutput, error) { diff --git a/internal/service/scheduler/schedule_group.go b/internal/service/scheduler/schedule_group.go index 53509d022f0..7619733b405 100644 --- a/internal/service/scheduler/schedule_group.go +++ b/internal/service/scheduler/schedule_group.go @@ -95,6 +95,7 @@ const ( ) func resourceScheduleGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) @@ -106,23 +107,24 @@ func resourceScheduleGroupCreate(ctx context.Context, d *schema.ResourceData, me out, err := conn.CreateScheduleGroup(ctx, in) if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionCreating, ResNameScheduleGroup, name, err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionCreating, ResNameScheduleGroup, name, err) } if out == nil || out.ScheduleGroupArn == nil { - return create.DiagError(names.Scheduler, create.ErrActionCreating, ResNameScheduleGroup, name, errors.New("empty output")) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionCreating, ResNameScheduleGroup, name, errors.New("empty output")) } d.SetId(name) if _, err := waitScheduleGroupActive(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.Scheduler, create.ErrActionWaitingForCreation, ResNameScheduleGroup, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionWaitingForCreation, ResNameScheduleGroup, d.Id(), err) } - return resourceScheduleGroupRead(ctx, d, meta) + return append(diags, resourceScheduleGroupRead(ctx, d, meta)...) } func resourceScheduleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) out, err := findScheduleGroupByName(ctx, conn, d.Id()) @@ -130,11 +132,11 @@ func resourceScheduleGroupRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EventBridge Scheduler Schedule Group (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.Scheduler, create.ErrActionReading, ResNameScheduleGroup, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionReading, ResNameScheduleGroup, d.Id(), err) } d.Set(names.AttrARN, out.Arn) @@ -144,7 +146,7 @@ func resourceScheduleGroupRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(out.Name))) d.Set(names.AttrState, out.State) - return nil + return diags } func resourceScheduleGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -153,6 +155,7 @@ func resourceScheduleGroupUpdate(ctx context.Context, d *schema.ResourceData, me } func resourceScheduleGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchedulerClient(ctx) log.Printf("[INFO] Deleting EventBridge Scheduler ScheduleGroup %s", d.Id()) @@ -164,15 +167,15 @@ func resourceScheduleGroupDelete(ctx context.Context, d *schema.ResourceData, me if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.Scheduler, create.ErrActionDeleting, ResNameScheduleGroup, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionDeleting, ResNameScheduleGroup, d.Id(), err) } if _, err := waitScheduleGroupDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return create.DiagError(names.Scheduler, create.ErrActionWaitingForDeletion, ResNameScheduleGroup, d.Id(), err) + return create.AppendDiagError(diags, names.Scheduler, create.ErrActionWaitingForDeletion, ResNameScheduleGroup, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/schemas/registry_policy.go b/internal/service/schemas/registry_policy.go index b173cf2fdf8..b1f3603fbf6 100644 --- a/internal/service/schemas/registry_policy.go +++ b/internal/service/schemas/registry_policy.go @@ -59,12 +59,13 @@ const ( ) func resourceRegistryPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchemasConn(ctx) registryName := d.Get("registry_name").(string) policy, err := structure.ExpandJsonFromString(d.Get(names.AttrPolicy).(string)) if err != nil { - return create.DiagError(names.Schemas, create.ErrActionCreating, ResNameRegistryPolicy, registryName, err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionCreating, ResNameRegistryPolicy, registryName, err) } input := &schemas.PutResourcePolicyInput{ @@ -76,15 +77,16 @@ func resourceRegistryPolicyCreate(ctx context.Context, d *schema.ResourceData, m _, err = conn.PutResourcePolicyWithContext(ctx, input) if err != nil { - return create.DiagError(names.Schemas, create.ErrActionCreating, ResNameRegistryPolicy, registryName, err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionCreating, ResNameRegistryPolicy, registryName, err) } d.SetId(registryName) - return resourceRegistryPolicyRead(ctx, d, meta) + return append(diags, resourceRegistryPolicyRead(ctx, d, meta)...) } func resourceRegistryPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchemasConn(ctx) output, err := FindRegistryPolicyByName(ctx, conn, d.Id()) @@ -92,30 +94,31 @@ func resourceRegistryPolicyRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EventBridge Schemas Registry Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.Schemas, create.ErrActionReading, ResNameRegistryPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionReading, ResNameRegistryPolicy, d.Id(), err) } policy, err := structure.FlattenJsonToString(output.Policy) if err != nil { - return create.DiagError(names.Schemas, create.ErrActionReading, ResNameRegistryPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionReading, ResNameRegistryPolicy, d.Id(), err) } d.Set(names.AttrPolicy, policy) d.Set("registry_name", d.Id()) - return nil + return diags } func resourceRegistryPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchemasConn(ctx) policy, err := structure.ExpandJsonFromString(d.Get(names.AttrPolicy).(string)) if err != nil { - return create.DiagError(names.Schemas, create.ErrActionUpdating, ResNameRegistryPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionUpdating, ResNameRegistryPolicy, d.Id(), err) } if d.HasChanges(names.AttrPolicy) { @@ -128,14 +131,15 @@ func resourceRegistryPolicyUpdate(ctx context.Context, d *schema.ResourceData, m _, err := conn.PutResourcePolicyWithContext(ctx, input) if err != nil { - return create.DiagError(names.Schemas, create.ErrActionUpdating, ResNameRegistryPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionUpdating, ResNameRegistryPolicy, d.Id(), err) } } - return resourceRegistryPolicyRead(ctx, d, meta) + return append(diags, resourceRegistryPolicyRead(ctx, d, meta)...) } func resourceRegistryPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SchemasConn(ctx) log.Printf("[INFO] Deleting EventBridge Schemas Registry Policy (%s)", d.Id()) @@ -144,12 +148,12 @@ func resourceRegistryPolicyDelete(ctx context.Context, d *schema.ResourceData, m }) if tfawserr.ErrCodeEquals(err, schemas.ErrCodeNotFoundException) { - return nil + return diags } if err != nil { - return create.DiagError(names.Schemas, create.ErrActionDeleting, ResNameRegistryPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.Schemas, create.ErrActionDeleting, ResNameRegistryPolicy, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/securityhub/insight.go b/internal/service/securityhub/insight.go index 3bf7c49b5e4..0754d3d1c1d 100644 --- a/internal/service/securityhub/insight.go +++ b/internal/service/securityhub/insight.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -34,121 +35,124 @@ func resourceInsight() *schema.Resource { StateContext: schema.ImportStatePassthroughContext, }, - Schema: map[string]*schema.Schema{ - names.AttrARN: { - Type: schema.TypeString, - Computed: true, - }, - "filters": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - names.AttrAWSAccountID: stringFilterSchema(), - "company_name": stringFilterSchema(), - "compliance_status": stringFilterSchema(), - "confidence": numberFilterSchema(), - names.AttrCreatedAt: dateFilterSchema(), - "criticality": numberFilterSchema(), - names.AttrDescription: stringFilterSchema(), - "finding_provider_fields_confidence": numberFilterSchema(), - "finding_provider_fields_criticality": numberFilterSchema(), - "finding_provider_fields_related_findings_id": stringFilterSchema(), - "finding_provider_fields_related_findings_product_arn": stringFilterSchema(), - "finding_provider_fields_severity_label": stringFilterSchema(), - "finding_provider_fields_severity_original": stringFilterSchema(), - "finding_provider_fields_types": stringFilterSchema(), - "first_observed_at": dateFilterSchema(), - "generator_id": stringFilterSchema(), - names.AttrID: stringFilterSchema(), - "keyword": keywordFilterSchema(), - "last_observed_at": dateFilterSchema(), - "malware_name": stringFilterSchema(), - "malware_path": stringFilterSchema(), - "malware_state": stringFilterSchema(), - "malware_type": stringFilterSchema(), - "network_destination_domain": stringFilterSchema(), - "network_destination_ipv4": ipFilterSchema(), - "network_destination_ipv6": ipFilterSchema(), - "network_destination_port": numberFilterSchema(), - "network_direction": stringFilterSchema(), - "network_protocol": stringFilterSchema(), - "network_source_domain": stringFilterSchema(), - "network_source_ipv4": ipFilterSchema(), - "network_source_ipv6": ipFilterSchema(), - "network_source_mac": stringFilterSchema(), - "network_source_port": numberFilterSchema(), - "note_text": stringFilterSchema(), - "note_updated_at": dateFilterSchema(), - "note_updated_by": stringFilterSchema(), - "process_launched_at": dateFilterSchema(), - "process_name": stringFilterSchema(), - "process_parent_pid": numberFilterSchema(), - "process_path": stringFilterSchema(), - "process_pid": numberFilterSchema(), - "process_terminated_at": dateFilterSchema(), - "product_arn": stringFilterSchema(), - "product_fields": mapFilterSchema(), - "product_name": stringFilterSchema(), - "recommendation_text": stringFilterSchema(), - "record_state": stringFilterSchema(), - "related_findings_id": stringFilterSchema(), - "related_findings_product_arn": stringFilterSchema(), - "resource_aws_ec2_instance_iam_instance_profile_arn": stringFilterSchema(), - "resource_aws_ec2_instance_image_id": stringFilterSchema(), - "resource_aws_ec2_instance_ipv4_addresses": ipFilterSchema(), - "resource_aws_ec2_instance_ipv6_addresses": ipFilterSchema(), - "resource_aws_ec2_instance_key_name": stringFilterSchema(), - "resource_aws_ec2_instance_launched_at": dateFilterSchema(), - "resource_aws_ec2_instance_subnet_id": stringFilterSchema(), - "resource_aws_ec2_instance_type": stringFilterSchema(), - "resource_aws_ec2_instance_vpc_id": stringFilterSchema(), - "resource_aws_iam_access_key_created_at": dateFilterSchema(), - "resource_aws_iam_access_key_status": stringFilterSchema(), - "resource_aws_iam_access_key_user_name": stringFilterSchema(), - "resource_aws_s3_bucket_owner_id": stringFilterSchema(), - "resource_aws_s3_bucket_owner_name": stringFilterSchema(), - "resource_container_image_id": stringFilterSchema(), - "resource_container_image_name": stringFilterSchema(), - "resource_container_launched_at": dateFilterSchema(), - "resource_container_name": stringFilterSchema(), - "resource_details_other": mapFilterSchema(), - names.AttrResourceID: stringFilterSchema(), - "resource_partition": stringFilterSchema(), - "resource_region": stringFilterSchema(), - names.AttrResourceTags: mapFilterSchema(), - names.AttrResourceType: stringFilterSchema(), - "severity_label": stringFilterSchema(), - "source_url": stringFilterSchema(), - "threat_intel_indicator_category": stringFilterSchema(), - "threat_intel_indicator_last_observed_at": dateFilterSchema(), - "threat_intel_indicator_source": stringFilterSchema(), - "threat_intel_indicator_source_url": stringFilterSchema(), - "threat_intel_indicator_type": stringFilterSchema(), - "threat_intel_indicator_value": stringFilterSchema(), - "title": stringFilterSchema(), - names.AttrType: stringFilterSchema(), - "updated_at": dateFilterSchema(), - "user_defined_values": mapFilterSchema(), - "verification_state": stringFilterSchema(), - "workflow_status": workflowStatusSchema(), + SchemaFunc: func() map[string]*schema.Schema { + return map[string]*schema.Schema{ + names.AttrARN: { + Type: schema.TypeString, + Computed: true, + }, + "filters": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + names.AttrAWSAccountID: stringFilterSchema(), + "company_name": stringFilterSchema(), + "compliance_status": stringFilterSchema(), + "confidence": numberFilterSchema(), + names.AttrCreatedAt: dateFilterSchema(), + "criticality": numberFilterSchema(), + names.AttrDescription: stringFilterSchema(), + "finding_provider_fields_confidence": numberFilterSchema(), + "finding_provider_fields_criticality": numberFilterSchema(), + "finding_provider_fields_related_findings_id": stringFilterSchema(), + "finding_provider_fields_related_findings_product_arn": stringFilterSchema(), + "finding_provider_fields_severity_label": stringFilterSchema(), + "finding_provider_fields_severity_original": stringFilterSchema(), + "finding_provider_fields_types": stringFilterSchema(), + "first_observed_at": dateFilterSchema(), + "generator_id": stringFilterSchema(), + names.AttrID: stringFilterSchema(), + "keyword": keywordFilterSchema(), + "last_observed_at": dateFilterSchema(), + "malware_name": stringFilterSchema(), + "malware_path": stringFilterSchema(), + "malware_state": stringFilterSchema(), + "malware_type": stringFilterSchema(), + "network_destination_domain": stringFilterSchema(), + "network_destination_ipv4": ipFilterSchema(), + "network_destination_ipv6": ipFilterSchema(), + "network_destination_port": numberFilterSchema(), + "network_direction": stringFilterSchema(), + "network_protocol": stringFilterSchema(), + "network_source_domain": stringFilterSchema(), + "network_source_ipv4": ipFilterSchema(), + "network_source_ipv6": ipFilterSchema(), + "network_source_mac": stringFilterSchema(), + "network_source_port": numberFilterSchema(), + "note_text": stringFilterSchema(), + "note_updated_at": dateFilterSchema(), + "note_updated_by": stringFilterSchema(), + "process_launched_at": dateFilterSchema(), + "process_name": stringFilterSchema(), + "process_parent_pid": numberFilterSchema(), + "process_path": stringFilterSchema(), + "process_pid": numberFilterSchema(), + "process_terminated_at": dateFilterSchema(), + "product_arn": stringFilterSchema(), + "product_fields": mapFilterSchema(), + "product_name": stringFilterSchema(), + "recommendation_text": stringFilterSchema(), + "record_state": stringFilterSchema(), + "related_findings_id": stringFilterSchema(), + "related_findings_product_arn": stringFilterSchema(), + "resource_aws_ec2_instance_iam_instance_profile_arn": stringFilterSchema(), + "resource_aws_ec2_instance_image_id": stringFilterSchema(), + "resource_aws_ec2_instance_ipv4_addresses": ipFilterSchema(), + "resource_aws_ec2_instance_ipv6_addresses": ipFilterSchema(), + "resource_aws_ec2_instance_key_name": stringFilterSchema(), + "resource_aws_ec2_instance_launched_at": dateFilterSchema(), + "resource_aws_ec2_instance_subnet_id": stringFilterSchema(), + "resource_aws_ec2_instance_type": stringFilterSchema(), + "resource_aws_ec2_instance_vpc_id": stringFilterSchema(), + "resource_aws_iam_access_key_created_at": dateFilterSchema(), + "resource_aws_iam_access_key_status": stringFilterSchema(), + "resource_aws_iam_access_key_user_name": stringFilterSchema(), + "resource_aws_s3_bucket_owner_id": stringFilterSchema(), + "resource_aws_s3_bucket_owner_name": stringFilterSchema(), + "resource_container_image_id": stringFilterSchema(), + "resource_container_image_name": stringFilterSchema(), + "resource_container_launched_at": dateFilterSchema(), + "resource_container_name": stringFilterSchema(), + "resource_details_other": mapFilterSchema(), + names.AttrResourceID: stringFilterSchema(), + "resource_partition": stringFilterSchema(), + "resource_region": stringFilterSchema(), + names.AttrResourceTags: mapFilterSchema(), + names.AttrResourceType: stringFilterSchema(), + "severity_label": stringFilterSchema(), + "source_url": stringFilterSchema(), + "threat_intel_indicator_category": stringFilterSchema(), + "threat_intel_indicator_last_observed_at": dateFilterSchema(), + "threat_intel_indicator_source": stringFilterSchema(), + "threat_intel_indicator_source_url": stringFilterSchema(), + "threat_intel_indicator_type": stringFilterSchema(), + "threat_intel_indicator_value": stringFilterSchema(), + "title": stringFilterSchema(), + names.AttrType: stringFilterSchema(), + "updated_at": dateFilterSchema(), + "user_defined_values": mapFilterSchema(), + "verification_state": stringFilterSchema(), + "workflow_status": workflowStatusSchema(), + }, }, }, - }, - "group_by_attribute": { - Type: schema.TypeString, - Required: true, - }, - names.AttrName: { - Type: schema.TypeString, - Required: true, - }, + "group_by_attribute": { + Type: schema.TypeString, + Required: true, + }, + names.AttrName: { + Type: schema.TypeString, + Required: true, + }, + } }, } } func resourceInsightCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) name := d.Get(names.AttrName).(string) @@ -164,15 +168,16 @@ func resourceInsightCreate(ctx context.Context, d *schema.ResourceData, meta int output, err := conn.CreateInsight(ctx, input) if err != nil { - return diag.Errorf("creating Security Hub Insight (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Security Hub Insight (%s): %s", name, err) } d.SetId(aws.ToString(output.InsightArn)) - return resourceInsightRead(ctx, d, meta) + return append(diags, resourceInsightRead(ctx, d, meta)...) } func resourceInsightRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) insight, err := findInsightByARN(ctx, conn, d.Id()) @@ -180,24 +185,25 @@ func resourceInsightRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Security Hub Insight (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Security Hub Insight (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Security Hub Insight (%s): %s", d.Id(), err) } d.Set(names.AttrARN, insight.InsightArn) if err := d.Set("filters", flattenSecurityFindingFilters(insight.Filters)); err != nil { - return diag.Errorf("setting filters: %s", err) + return sdkdiag.AppendErrorf(diags, "setting filters: %s", err) } d.Set("group_by_attribute", insight.GroupByAttribute) d.Set(names.AttrName, insight.Name) - return nil + return diags } func resourceInsightUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) input := &securityhub.UpdateInsightInput{ @@ -219,13 +225,14 @@ func resourceInsightUpdate(ctx context.Context, d *schema.ResourceData, meta int _, err := conn.UpdateInsight(ctx, input) if err != nil { - return diag.Errorf("updating Security Hub Insight (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Security Hub Insight (%s): %s", d.Id(), err) } - return resourceInsightRead(ctx, d, meta) + return append(diags, resourceInsightRead(ctx, d, meta)...) } func resourceInsightDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) log.Printf("[DEBUG] Deleting Security Hub Insight: %s", d.Id()) @@ -234,14 +241,14 @@ func resourceInsightDelete(ctx context.Context, d *schema.ResourceData, meta int }) if tfawserr.ErrCodeEquals(err, errCodeResourceNotFoundException) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Security Hub Insight (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Security Hub Insight (%s): %s", d.Id(), err) } - return nil + return diags } func findInsightByARN(ctx context.Context, conn *securityhub.Client, arn string) (*types.Insight, error) { diff --git a/internal/service/securityhub/invite_accepter.go b/internal/service/securityhub/invite_accepter.go index 2a6b7ebd40e..5afe4ef68b0 100644 --- a/internal/service/securityhub/invite_accepter.go +++ b/internal/service/securityhub/invite_accepter.go @@ -84,11 +84,11 @@ func resourceInviteAccepterRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Security Hub Master Account (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Security Hub Master Account (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Security Hub Master Account (%s): %s", d.Id(), err) } d.Set("invitation_id", master.InvitationId) diff --git a/internal/service/securityhub/organization_admin_account.go b/internal/service/securityhub/organization_admin_account.go index 61c603e2aa8..02bb6fc34cb 100644 --- a/internal/service/securityhub/organization_admin_account.go +++ b/internal/service/securityhub/organization_admin_account.go @@ -83,7 +83,7 @@ func resourceOrganizationAdminAccountRead(ctx context.Context, d *schema.Resourc if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Security Hub Organization Admin Account (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/securityhub/product_subscription.go b/internal/service/securityhub/product_subscription.go index 2d022f4ef86..d8006ab8334 100644 --- a/internal/service/securityhub/product_subscription.go +++ b/internal/service/securityhub/product_subscription.go @@ -89,7 +89,7 @@ func resourceProductSubscriptionRead(ctx context.Context, d *schema.ResourceData if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Security Hub Product Subscription (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/securityhub/standards_control.go b/internal/service/securityhub/standards_control.go index 1dd81b37a5e..dc7d2ea3e0d 100644 --- a/internal/service/securityhub/standards_control.go +++ b/internal/service/securityhub/standards_control.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -85,6 +86,7 @@ func resourceStandardsControl() *schema.Resource { } func resourceStandardsControlPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) standardsControlARN := d.Get("standards_control_arn").(string) @@ -97,22 +99,23 @@ func resourceStandardsControlPut(ctx context.Context, d *schema.ResourceData, me _, err := conn.UpdateStandardsControl(ctx, input) if err != nil { - return diag.Errorf("updating Security Hub Standards Control (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Security Hub Standards Control (%s): %s", d.Id(), err) } if d.IsNewResource() { d.SetId(standardsControlARN) } - return resourceStandardsControlRead(ctx, d, meta) + return append(diags, resourceStandardsControlRead(ctx, d, meta)...) } func resourceStandardsControlRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SecurityHubClient(ctx) standardsSubscriptionARN, err := standardsControlARNToStandardsSubscriptionARN(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } control, err := findStandardsControlByTwoPartKey(ctx, conn, standardsSubscriptionARN, d.Id()) @@ -120,11 +123,11 @@ func resourceStandardsControlRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Security Hub Standards Control (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Security Hub Standards Control (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Security Hub Standards Control (%s): %s", d.Id(), err) } d.Set("control_id", control.ControlId) @@ -138,7 +141,7 @@ func resourceStandardsControlRead(ctx context.Context, d *schema.ResourceData, m d.Set("standards_control_arn", control.StandardsControlArn) d.Set("title", control.Title) - return nil + return diags } // standardsControlARNToStandardsSubscriptionARN converts a security standard control ARN to a subscription ARN. diff --git a/internal/service/servicecatalog/provisioning_artifacts_data_source.go b/internal/service/servicecatalog/provisioning_artifacts_data_source.go index dbe4840d26f..0aa6eeba33a 100644 --- a/internal/service/servicecatalog/provisioning_artifacts_data_source.go +++ b/internal/service/servicecatalog/provisioning_artifacts_data_source.go @@ -97,7 +97,7 @@ func dataSourceProvisioningArtifactsRead(ctx context.Context, d *schema.Resource return sdkdiag.AppendErrorf(diags, "setting provisioning_artifact_details: %s", err) } - return nil + return diags } func flattenProvisioningArtifactDetails(apiObjects []*servicecatalog.ProvisioningArtifactDetail) []interface{} { diff --git a/internal/service/servicediscovery/dns_namespace_data_source.go b/internal/service/servicediscovery/dns_namespace_data_source.go index e38f597aef3..aa30cb16137 100644 --- a/internal/service/servicediscovery/dns_namespace_data_source.go +++ b/internal/service/servicediscovery/dns_namespace_data_source.go @@ -12,6 +12,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -53,6 +54,7 @@ func DataSourceDNSNamespace() *schema.Resource { } func dataSourceDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -61,7 +63,7 @@ func dataSourceDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, met nsSummary, err := findNamespaceByNameAndType(ctx, conn, name, nsType) if err != nil { - return diag.Errorf("reading Service Discovery %s Namespace (%s): %s", name, nsType, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery %s Namespace (%s): %s", name, nsType, err) } namespaceID := aws.StringValue(nsSummary.Id) @@ -69,7 +71,7 @@ func dataSourceDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, met ns, err := FindNamespaceByID(ctx, conn, namespaceID) if err != nil { - return diag.Errorf("reading Service Discovery %s Namespace (%s): %s", nsType, namespaceID, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery %s Namespace (%s): %s", nsType, namespaceID, err) } d.SetId(namespaceID) @@ -86,12 +88,12 @@ func dataSourceDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, met tags, err := listTags(ctx, conn, arn) if err != nil { - return diag.Errorf("listing tags for Service Discovery %s Namespace (%s): %s", nsType, arn, err) + return sdkdiag.AppendErrorf(diags, "listing tags for Service Discovery %s Namespace (%s): %s", nsType, arn, err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } - return nil + return diags } diff --git a/internal/service/servicediscovery/http_namespace.go b/internal/service/servicediscovery/http_namespace.go index 982f42b5999..752c4deec78 100644 --- a/internal/service/servicediscovery/http_namespace.go +++ b/internal/service/servicediscovery/http_namespace.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -63,6 +64,7 @@ func ResourceHTTPNamespace() *schema.Resource { } func resourceHTTPNamespaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) name := d.Get(names.AttrName).(string) @@ -80,27 +82,28 @@ func resourceHTTPNamespaceCreate(ctx context.Context, d *schema.ResourceData, me output, err := conn.CreateHttpNamespaceWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Service Discovery HTTP Namespace (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery HTTP Namespace (%s): %s", name, err) } operation, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)) if err != nil { - return diag.Errorf("waiting for Service Discovery HTTP Namespace (%s) create: %s", name, err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery HTTP Namespace (%s) create: %s", name, err) } namespaceID, ok := operation.Targets[servicediscovery.OperationTargetTypeNamespace] if !ok { - return diag.Errorf("creating Service Discovery HTTP Namespace (%s): operation response missing Namespace ID", name) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery HTTP Namespace (%s): operation response missing Namespace ID", name) } d.SetId(aws.StringValue(namespaceID)) - return resourceHTTPNamespaceRead(ctx, d, meta) + return append(diags, resourceHTTPNamespaceRead(ctx, d, meta)...) } func resourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ns, err := FindNamespaceByID(ctx, conn, d.Id()) @@ -108,11 +111,11 @@ func resourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Service Discovery HTTP Namespace %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Service Discovery HTTP Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery HTTP Namespace (%s): %s", d.Id(), err) } arn := aws.StringValue(ns.Arn) @@ -125,7 +128,7 @@ func resourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, meta } d.Set(names.AttrName, ns.Name) - return nil + return diags } func resourceHTTPNamespaceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -134,6 +137,7 @@ func resourceHTTPNamespaceUpdate(ctx context.Context, d *schema.ResourceData, me } func resourceHTTPNamespaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) log.Printf("[INFO] Deleting Service Discovery HTTP Namespace: %s", d.Id()) @@ -144,18 +148,18 @@ func resourceHTTPNamespaceDelete(ctx context.Context, d *schema.ResourceData, me }, servicediscovery.ErrCodeResourceInUse) if tfawserr.ErrCodeEquals(err, servicediscovery.ErrCodeNamespaceNotFound) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Service Discovery HTTP Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Service Discovery HTTP Namespace (%s): %s", d.Id(), err) } if output := outputRaw.(*servicediscovery.DeleteNamespaceOutput); output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery HTTP Namespace (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery HTTP Namespace (%s) delete: %s", d.Id(), err) } } - return nil + return diags } diff --git a/internal/service/servicediscovery/http_namespace_data_source.go b/internal/service/servicediscovery/http_namespace_data_source.go index e2ca93a23e9..35568ff5122 100644 --- a/internal/service/servicediscovery/http_namespace_data_source.go +++ b/internal/service/servicediscovery/http_namespace_data_source.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -44,6 +45,7 @@ func DataSourceHTTPNamespace() *schema.Resource { } func dataSourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -51,7 +53,7 @@ func dataSourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, me nsSummary, err := findNamespaceByNameAndType(ctx, conn, name, servicediscovery.NamespaceTypeHttp) if err != nil { - return diag.Errorf("reading Service Discovery HTTP Namespace (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery HTTP Namespace (%s): %s", name, err) } namespaceID := aws.StringValue(nsSummary.Id) @@ -59,7 +61,7 @@ func dataSourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, me ns, err := FindNamespaceByID(ctx, conn, namespaceID) if err != nil { - return diag.Errorf("reading Service Discovery HTTP Namespace (%s): %s", namespaceID, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery HTTP Namespace (%s): %s", namespaceID, err) } d.SetId(namespaceID) @@ -76,12 +78,12 @@ func dataSourceHTTPNamespaceRead(ctx context.Context, d *schema.ResourceData, me tags, err := listTags(ctx, conn, arn) if err != nil { - return diag.Errorf("listing tags for Service Discovery HTTP Namespace (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "listing tags for Service Discovery HTTP Namespace (%s): %s", arn, err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } - return nil + return diags } diff --git a/internal/service/servicediscovery/instance.go b/internal/service/servicediscovery/instance.go index 4e9f4bcb479..9510f9df219 100644 --- a/internal/service/servicediscovery/instance.go +++ b/internal/service/servicediscovery/instance.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -66,6 +67,7 @@ func ResourceInstance() *schema.Resource { } func resourceInstancePut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) instanceID := d.Get(names.AttrInstanceID).(string) @@ -80,21 +82,22 @@ func resourceInstancePut(ctx context.Context, d *schema.ResourceData, meta inter output, err := conn.RegisterInstanceWithContext(ctx, input) if err != nil { - return diag.Errorf("registering Service Discovery Instance (%s): %s", instanceID, err) + return sdkdiag.AppendErrorf(diags, "registering Service Discovery Instance (%s): %s", instanceID, err) } d.SetId(instanceID) if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Instance (%s) create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Instance (%s) create: %s", d.Id(), err) } } - return resourceInstanceRead(ctx, d, meta) + return append(diags, resourceInstanceRead(ctx, d, meta)...) } func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) instance, err := FindInstanceByServiceIDAndInstanceID(ctx, conn, d.Get("service_id").(string), d.Get(names.AttrInstanceID).(string)) @@ -102,11 +105,11 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Service Discovery Instance (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Service Discovery Instance (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Instance (%s): %s", d.Id(), err) } attributes := instance.Attributes @@ -119,19 +122,20 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set(names.AttrAttributes, aws.StringValueMap(attributes)) d.Set(names.AttrInstanceID, instance.Id) - return nil + return diags } func resourceInstanceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) err := deregisterInstance(ctx, conn, d.Get("service_id").(string), d.Get(names.AttrInstanceID).(string)) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } - return nil + return diags } func resourceInstanceImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { diff --git a/internal/service/servicediscovery/private_dns_namespace.go b/internal/service/servicediscovery/private_dns_namespace.go index 64261a66bff..489ea07ceeb 100644 --- a/internal/service/servicediscovery/private_dns_namespace.go +++ b/internal/service/servicediscovery/private_dns_namespace.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -75,6 +76,7 @@ func ResourcePrivateDNSNamespace() *schema.Resource { } func resourcePrivateDNSNamespaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) name := d.Get(names.AttrName).(string) @@ -92,27 +94,28 @@ func resourcePrivateDNSNamespaceCreate(ctx context.Context, d *schema.ResourceDa output, err := conn.CreatePrivateDnsNamespaceWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Service Discovery Private DNS Namespace (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery Private DNS Namespace (%s): %s", name, err) } operation, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)) if err != nil { - return diag.Errorf("waiting for Service Discovery Private DNS Namespace (%s) create: %s", name, err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Private DNS Namespace (%s) create: %s", name, err) } namespaceID, ok := operation.Targets[servicediscovery.OperationTargetTypeNamespace] if !ok { - return diag.Errorf("creating Service Discovery Private DNS Namespace (%s): operation response missing Namespace ID", name) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery Private DNS Namespace (%s): operation response missing Namespace ID", name) } d.SetId(aws.StringValue(namespaceID)) - return resourcePrivateDNSNamespaceRead(ctx, d, meta) + return append(diags, resourcePrivateDNSNamespaceRead(ctx, d, meta)...) } func resourcePrivateDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ns, err := FindNamespaceByID(ctx, conn, d.Id()) @@ -120,11 +123,11 @@ func resourcePrivateDNSNamespaceRead(ctx context.Context, d *schema.ResourceData if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Service Discovery Private DNS Namespace %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) } arn := aws.StringValue(ns.Arn) @@ -137,10 +140,11 @@ func resourcePrivateDNSNamespaceRead(ctx context.Context, d *schema.ResourceData } d.Set(names.AttrName, ns.Name) - return nil + return diags } func resourcePrivateDNSNamespaceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) if d.HasChange(names.AttrDescription) { @@ -155,20 +159,21 @@ func resourcePrivateDNSNamespaceUpdate(ctx context.Context, d *schema.ResourceDa output, err := conn.UpdatePrivateDnsNamespaceWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) } if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Private DNS Namespace (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Private DNS Namespace (%s) update: %s", d.Id(), err) } } } - return resourcePrivateDNSNamespaceRead(ctx, d, meta) + return append(diags, resourcePrivateDNSNamespaceRead(ctx, d, meta)...) } func resourcePrivateDNSNamespaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) log.Printf("[INFO] Deleting Service Discovery Private DNS Namespace: %s", d.Id()) @@ -177,14 +182,14 @@ func resourcePrivateDNSNamespaceDelete(ctx context.Context, d *schema.ResourceDa }) if err != nil { - return diag.Errorf("deleting Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Service Discovery Private DNS Namespace (%s): %s", d.Id(), err) } if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Private DNS Namespace (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Private DNS Namespace (%s) delete: %s", d.Id(), err) } } - return nil + return diags } diff --git a/internal/service/servicediscovery/public_dns_namespace.go b/internal/service/servicediscovery/public_dns_namespace.go index 269df06793a..95f0d322e83 100644 --- a/internal/service/servicediscovery/public_dns_namespace.go +++ b/internal/service/servicediscovery/public_dns_namespace.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -60,6 +61,7 @@ func ResourcePublicDNSNamespace() *schema.Resource { } func resourcePublicDNSNamespaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) name := d.Get(names.AttrName).(string) @@ -76,27 +78,28 @@ func resourcePublicDNSNamespaceCreate(ctx context.Context, d *schema.ResourceDat output, err := conn.CreatePublicDnsNamespaceWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Service Discovery Public DNS Namespace (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery Public DNS Namespace (%s): %s", name, err) } operation, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)) if err != nil { - return diag.Errorf("waiting for Service Discovery Public DNS Namespace (%s) create: %s", name, err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Public DNS Namespace (%s) create: %s", name, err) } namespaceID, ok := operation.Targets[servicediscovery.OperationTargetTypeNamespace] if !ok { - return diag.Errorf("creating Service Discovery Public DNS Namespace (%s): operation response missing Namespace ID", name) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery Public DNS Namespace (%s): operation response missing Namespace ID", name) } d.SetId(aws.StringValue(namespaceID)) - return resourcePublicDNSNamespaceRead(ctx, d, meta) + return append(diags, resourcePublicDNSNamespaceRead(ctx, d, meta)...) } func resourcePublicDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ns, err := FindNamespaceByID(ctx, conn, d.Id()) @@ -104,11 +107,11 @@ func resourcePublicDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Service Discovery Public DNS Namespace %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) } arn := aws.StringValue(ns.Arn) @@ -121,10 +124,11 @@ func resourcePublicDNSNamespaceRead(ctx context.Context, d *schema.ResourceData, } d.Set(names.AttrName, ns.Name) - return nil + return diags } func resourcePublicDNSNamespaceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) if d.HasChange(names.AttrDescription) { @@ -139,20 +143,21 @@ func resourcePublicDNSNamespaceUpdate(ctx context.Context, d *schema.ResourceDat output, err := conn.UpdatePublicDnsNamespaceWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) } if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Public DNS Namespace (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Public DNS Namespace (%s) update: %s", d.Id(), err) } } } - return resourcePublicDNSNamespaceRead(ctx, d, meta) + return append(diags, resourcePublicDNSNamespaceRead(ctx, d, meta)...) } func resourcePublicDNSNamespaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) log.Printf("[INFO] Deleting Service Discovery Public DNS Namespace: %s", d.Id()) @@ -161,14 +166,14 @@ func resourcePublicDNSNamespaceDelete(ctx context.Context, d *schema.ResourceDat }) if err != nil { - return diag.Errorf("deleting Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Service Discovery Public DNS Namespace (%s): %s", d.Id(), err) } if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Public DNS Namespace (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Public DNS Namespace (%s) delete: %s", d.Id(), err) } } - return nil + return diags } diff --git a/internal/service/servicediscovery/service.go b/internal/service/servicediscovery/service.go index 61c4c632da4..fe8953ce4c9 100644 --- a/internal/service/servicediscovery/service.go +++ b/internal/service/servicediscovery/service.go @@ -17,6 +17,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -154,6 +155,7 @@ func ResourceService() *schema.Resource { } func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) name := d.Get(names.AttrName).(string) @@ -190,15 +192,16 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int output, err := conn.CreateServiceWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Service Discovery Service (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Service Discovery Service (%s): %s", name, err) } d.SetId(aws.StringValue(output.Service.Id)) - return resourceServiceRead(ctx, d, meta) + return append(diags, resourceServiceRead(ctx, d, meta)...) } func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) service, err := FindServiceByID(ctx, conn, d.Id()) @@ -206,11 +209,11 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Service Discovery Service (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Service Discovery Service (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Service (%s): %s", d.Id(), err) } arn := aws.StringValue(service.Arn) @@ -218,21 +221,21 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrDescription, service.Description) if tfMap := flattenDNSConfig(service.DnsConfig); len(tfMap) > 0 { if err := d.Set("dns_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting dns_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting dns_config: %s", err) } } else { d.Set("dns_config", nil) } if tfMap := flattenHealthCheckConfig(service.HealthCheckConfig); len(tfMap) > 0 { if err := d.Set("health_check_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting health_check_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting health_check_config: %s", err) } } else { d.Set("health_check_config", nil) } if tfMap := flattenHealthCheckCustomConfig(service.HealthCheckCustomConfig); len(tfMap) > 0 { if err := d.Set("health_check_custom_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting health_check_custom_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting health_check_custom_config: %s", err) } } else { d.Set("health_check_custom_config", nil) @@ -241,10 +244,11 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("namespace_id", service.NamespaceId) d.Set(names.AttrType, service.Type) - return nil + return diags } func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -266,20 +270,21 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int output, err := conn.UpdateServiceWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Service Discovery Service (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Service Discovery Service (%s): %s", d.Id(), err) } if output != nil && output.OperationId != nil { if _, err := WaitOperationSuccess(ctx, conn, aws.StringValue(output.OperationId)); err != nil { - return diag.Errorf("waiting for Service Discovery Service (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Service Discovery Service (%s) update: %s", d.Id(), err) } } } - return resourceServiceRead(ctx, d, meta) + return append(diags, resourceServiceRead(ctx, d, meta)...) } func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) if d.Get(names.AttrForceDestroy).(bool) { @@ -313,7 +318,7 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int err = errors.Join(errs...) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } } @@ -323,14 +328,14 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int }) if tfawserr.ErrCodeEquals(err, servicediscovery.ErrCodeServiceNotFound) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting Service Discovery Service (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Service Discovery Service (%s): %s", d.Id(), err) } - return nil + return diags } func expandDNSConfig(tfMap map[string]interface{}) *servicediscovery.DnsConfig { diff --git a/internal/service/servicediscovery/service_data_source.go b/internal/service/servicediscovery/service_data_source.go index 55f34f4581c..3026741b421 100644 --- a/internal/service/servicediscovery/service_data_source.go +++ b/internal/service/servicediscovery/service_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -113,6 +114,7 @@ func DataSourceService() *schema.Resource { } func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).ServiceDiscoveryConn(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -120,7 +122,7 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int serviceSummary, err := findServiceByNameAndNamespaceID(ctx, conn, name, d.Get("namespace_id").(string)) if err != nil { - return diag.Errorf("reading Service Discovery Service (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Service (%s): %s", name, err) } serviceID := aws.StringValue(serviceSummary.Id) @@ -128,7 +130,7 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int service, err := FindServiceByID(ctx, conn, serviceID) if err != nil { - return diag.Errorf("reading Service Discovery Service (%s): %s", serviceID, err) + return sdkdiag.AppendErrorf(diags, "reading Service Discovery Service (%s): %s", serviceID, err) } d.SetId(serviceID) @@ -137,21 +139,21 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int d.Set(names.AttrDescription, service.Description) if tfMap := flattenDNSConfig(service.DnsConfig); len(tfMap) > 0 { if err := d.Set("dns_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting dns_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting dns_config: %s", err) } } else { d.Set("dns_config", nil) } if tfMap := flattenHealthCheckConfig(service.HealthCheckConfig); len(tfMap) > 0 { if err := d.Set("health_check_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting health_check_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting health_check_config: %s", err) } } else { d.Set("health_check_config", nil) } if tfMap := flattenHealthCheckCustomConfig(service.HealthCheckCustomConfig); len(tfMap) > 0 { if err := d.Set("health_check_custom_config", []interface{}{tfMap}); err != nil { - return diag.Errorf("setting health_check_custom_config: %s", err) + return sdkdiag.AppendErrorf(diags, "setting health_check_custom_config: %s", err) } } else { d.Set("health_check_custom_config", nil) @@ -162,12 +164,12 @@ func dataSourceServiceRead(ctx context.Context, d *schema.ResourceData, meta int tags, err := listTags(ctx, conn, arn) if err != nil { - return diag.Errorf("listing tags for Service Discovery Service (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "listing tags for Service Discovery Service (%s): %s", arn, err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } - return nil + return diags } diff --git a/internal/service/sesv2/account_vdm_attributes.go b/internal/service/sesv2/account_vdm_attributes.go index f994cbf8fd2..5d75f2196da 100644 --- a/internal/service/sesv2/account_vdm_attributes.go +++ b/internal/service/sesv2/account_vdm_attributes.go @@ -77,6 +77,7 @@ const ( ) func resourceAccountVDMAttributesUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.PutAccountVdmAttributesInput{ @@ -95,21 +96,22 @@ func resourceAccountVDMAttributesUpdate(ctx context.Context, d *schema.ResourceD out, err := conn.PutAccountVdmAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameAccountVDMAttributes, "", err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameAccountVDMAttributes, "", err) } if out == nil { - return create.DiagError(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() { d.SetId("ses-account-vdm-attributes") } - return resourceAccountVDMAttributesRead(ctx, d, meta) + return append(diags, resourceAccountVDMAttributesRead(ctx, d, meta)...) } func resourceAccountVDMAttributesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindAccountVDMAttributes(ctx, conn) @@ -117,31 +119,32 @@ func resourceAccountVDMAttributesRead(ctx context.Context, d *schema.ResourceDat if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 AccountVDMAttributes (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(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.DiagError(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.DiagError(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 nil + return diags } func resourceAccountVDMAttributesDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 AccountVDMAttributes %s", d.Id()) @@ -155,13 +158,13 @@ func resourceAccountVDMAttributesDelete(ctx context.Context, d *schema.ResourceD if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameAccountVDMAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameAccountVDMAttributes, d.Id(), err) } - return nil + return diags } func FindAccountVDMAttributes(ctx context.Context, conn *sesv2.Client) (*types.VdmAttributes, error) { diff --git a/internal/service/sesv2/configuration_set.go b/internal/service/sesv2/configuration_set.go index 93d164d087a..d5b248a6ac1 100644 --- a/internal/service/sesv2/configuration_set.go +++ b/internal/service/sesv2/configuration_set.go @@ -184,6 +184,7 @@ const ( ) func resourceConfigurationSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.CreateConfigurationSetInput{ @@ -217,19 +218,20 @@ func resourceConfigurationSetCreate(ctx context.Context, d *schema.ResourceData, out, err := conn.CreateConfigurationSet(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameConfigurationSet, d.Get("configuration_set_name").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameConfigurationSet, d.Get("configuration_set_name").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameConfigurationSet, d.Get("configuration_set_name").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameConfigurationSet, d.Get("configuration_set_name").(string), errors.New("empty output")) } d.SetId(d.Get("configuration_set_name").(string)) - return resourceConfigurationSetRead(ctx, d, meta) + return append(diags, resourceConfigurationSetRead(ctx, d, meta)...) } func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindConfigurationSetByID(ctx, conn, d.Id()) @@ -237,11 +239,11 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 ConfigurationSet (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameConfigurationSet, d.Id(), err) } d.Set(names.AttrARN, configurationSetNameToARN(meta, aws.ToString(out.ConfigurationSetName))) @@ -249,7 +251,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if out.DeliveryOptions != nil { if err := d.Set("delivery_options", []interface{}{flattenDeliveryOptions(out.DeliveryOptions)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("delivery_options", nil) @@ -257,7 +259,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if out.ReputationOptions != nil { if err := d.Set("reputation_options", []interface{}{flattenReputationOptions(out.ReputationOptions)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("reputation_options", nil) @@ -265,7 +267,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if out.SendingOptions != nil { if err := d.Set("sending_options", []interface{}{flattenSendingOptions(out.SendingOptions)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("sending_options", nil) @@ -273,7 +275,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if out.SuppressionOptions != nil { if err := d.Set("suppression_options", []interface{}{flattenSuppressionOptions(out.SuppressionOptions)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("suppression_options", nil) @@ -281,7 +283,7 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m if out.TrackingOptions != nil { if err := d.Set("tracking_options", []interface{}{flattenTrackingOptions(out.TrackingOptions)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("tracking_options", nil) @@ -289,16 +291,17 @@ func resourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, m 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSet, d.Id(), err) } } else { d.Set("vdm_options", nil) } - return nil + return diags } func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) if d.HasChanges("delivery_options") { @@ -321,7 +324,7 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] Updating SESV2 ConfigurationSet DeliveryOptions (%s): %#v", d.Id(), in) _, err := conn.PutConfigurationSetDeliveryOptions(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } @@ -341,7 +344,7 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] Updating SESV2 ConfigurationSet ReputationOptions (%s): %#v", d.Id(), in) _, err := conn.PutConfigurationSetReputationOptions(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } @@ -360,7 +363,7 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] Updating SESV2 ConfigurationSet SendingOptions (%s): %#v", d.Id(), in) _, err := conn.PutConfigurationSetSendingOptions(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } } @@ -381,7 +384,7 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] Updating SESV2 ConfigurationSet SuppressionOptions (%s): %#v", d.Id(), in) _, err := conn.PutConfigurationSetSuppressionOptions(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } @@ -401,7 +404,7 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[DEBUG] Updating SESV2 ConfigurationSet TrackingOptions (%s): %#v", d.Id(), in) _, err := conn.PutConfigurationSetTrackingOptions(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } @@ -417,14 +420,15 @@ func resourceConfigurationSetUpdate(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSet, d.Id(), err) } } - return resourceConfigurationSetRead(ctx, d, meta) + return append(diags, resourceConfigurationSetRead(ctx, d, meta)...) } func resourceConfigurationSetDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 ConfigurationSet %s", d.Id()) @@ -436,13 +440,13 @@ func resourceConfigurationSetDelete(ctx context.Context, d *schema.ResourceData, if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameConfigurationSet, d.Id(), err) } - return nil + return diags } func FindConfigurationSetByID(ctx context.Context, conn *sesv2.Client, id string) (*sesv2.GetConfigurationSetOutput, error) { diff --git a/internal/service/sesv2/configuration_set_data_source.go b/internal/service/sesv2/configuration_set_data_source.go index 3ba30af24e8..13dd3537bd6 100644 --- a/internal/service/sesv2/configuration_set_data_source.go +++ b/internal/service/sesv2/configuration_set_data_source.go @@ -144,13 +144,14 @@ const ( ) func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameConfigurationSet, name, err) } d.SetId(aws.ToString(out.ConfigurationSetName)) @@ -160,7 +161,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("delivery_options", nil) @@ -168,7 +169,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("reputation_options", nil) @@ -176,7 +177,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("sending_options", nil) @@ -184,7 +185,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("suppression_options", nil) @@ -192,7 +193,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("tracking_options", nil) @@ -200,7 +201,7 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, 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) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } } else { d.Set("vdm_options", nil) @@ -208,14 +209,14 @@ func dataSourceConfigurationSetRead(ctx context.Context, d *schema.ResourceData, tags, err := listTags(ctx, conn, d.Get(names.AttrARN).(string)) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, DSNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameConfigurationSet, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameConfigurationSet, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/sesv2/configuration_set_event_destination.go b/internal/service/sesv2/configuration_set_event_destination.go index 3dd3473108e..49238e3140d 100644 --- a/internal/service/sesv2/configuration_set_event_destination.go +++ b/internal/service/sesv2/configuration_set_event_destination.go @@ -182,6 +182,7 @@ const ( ) func resourceConfigurationSetEventDestinationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.CreateConfigurationSetEventDestinationInput{ @@ -194,24 +195,25 @@ func resourceConfigurationSetEventDestinationCreate(ctx context.Context, d *sche out, err := conn.CreateConfigurationSetEventDestination(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameConfigurationSetEventDestination, configurationSetEventDestinationID, err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameConfigurationSetEventDestination, configurationSetEventDestinationID, err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameConfigurationSetEventDestination, configurationSetEventDestinationID, errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameConfigurationSetEventDestination, configurationSetEventDestinationID, errors.New("empty output")) } d.SetId(configurationSetEventDestinationID) - return resourceConfigurationSetEventDestinationRead(ctx, d, meta) + return append(diags, resourceConfigurationSetEventDestinationRead(ctx, d, meta)...) } func resourceConfigurationSetEventDestinationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) configurationSetName, _, err := ParseConfigurationSetEventDestinationID(d.Id()) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) } out, err := FindConfigurationSetEventDestinationByID(ctx, conn, d.Id()) @@ -219,29 +221,30 @@ func resourceConfigurationSetEventDestinationRead(ctx context.Context, d *schema if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 ConfigurationSetEventDestination (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) } d.Set("configuration_set_name", configurationSetName) d.Set("event_destination_name", out.Name) if err := d.Set("event_destination", []interface{}{flattenEventDestination(out)}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameConfigurationSetEventDestination, d.Id(), err) } - return nil + return diags } func resourceConfigurationSetEventDestinationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) configurationSetName, eventDestinationName, err := ParseConfigurationSetEventDestinationID(d.Id()) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSetEventDestination, d.Id(), err) } if d.HasChanges("event_destination") { @@ -254,21 +257,22 @@ func resourceConfigurationSetEventDestinationUpdate(ctx context.Context, d *sche log.Printf("[DEBUG] Updating SESV2 ConfigurationSetEventDestination (%s): %#v", d.Id(), in) _, err := conn.UpdateConfigurationSetEventDestination(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameConfigurationSetEventDestination, d.Id(), err) } } - return resourceConfigurationSetEventDestinationRead(ctx, d, meta) + return append(diags, resourceConfigurationSetEventDestinationRead(ctx, d, meta)...) } func resourceConfigurationSetEventDestinationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 ConfigurationSetEventDestination %s", d.Id()) configurationSetName, eventDestinationName, err := ParseConfigurationSetEventDestinationID(d.Id()) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameConfigurationSetEventDestination, d.Id(), err) } _, err = conn.DeleteConfigurationSetEventDestination(ctx, &sesv2.DeleteConfigurationSetEventDestinationInput{ @@ -279,13 +283,13 @@ func resourceConfigurationSetEventDestinationDelete(ctx context.Context, d *sche if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameConfigurationSetEventDestination, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameConfigurationSetEventDestination, d.Id(), err) } - return nil + return diags } func FindConfigurationSetEventDestinationByID(ctx context.Context, conn *sesv2.Client, id string) (types.EventDestination, error) { diff --git a/internal/service/sesv2/contact_list.go b/internal/service/sesv2/contact_list.go index 6ab5fc13b26..736792bd4d4 100644 --- a/internal/service/sesv2/contact_list.go +++ b/internal/service/sesv2/contact_list.go @@ -99,6 +99,7 @@ const ( ) func resourceContactListCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.CreateContactListInput{ @@ -116,19 +117,20 @@ func resourceContactListCreate(ctx context.Context, d *schema.ResourceData, meta out, err := conn.CreateContactList(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameContactList, d.Get("contact_list_name").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameContactList, d.Get("contact_list_name").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameContactList, d.Get("contact_list_name").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameContactList, d.Get("contact_list_name").(string), errors.New("empty output")) } d.SetId(d.Get("contact_list_name").(string)) - return resourceContactListRead(ctx, d, meta) + return append(diags, resourceContactListRead(ctx, d, meta)...) } func resourceContactListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindContactListByID(ctx, conn, d.Id()) @@ -136,11 +138,11 @@ func resourceContactListRead(ctx context.Context, d *schema.ResourceData, meta i if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 ContactList (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameContactList, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameContactList, d.Id(), err) } arn := arn.ARN{ @@ -158,13 +160,14 @@ func resourceContactListRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("last_updated_timestamp", aws.ToTime(out.LastUpdatedTimestamp).Format(time.RFC3339)) if err := d.Set("topic", flattenTopics(out.Topics)); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameContactList, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameContactList, d.Id(), err) } - return nil + return diags } func resourceContactListUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.UpdateContactListInput{ @@ -177,14 +180,15 @@ func resourceContactListUpdate(ctx context.Context, d *schema.ResourceData, meta log.Printf("[DEBUG] Updating SESV2 ContactList (%s): %#v", d.Id(), in) if _, err := conn.UpdateContactList(ctx, in); err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameContactList, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameContactList, d.Id(), err) } } - return resourceContactListRead(ctx, d, meta) + return append(diags, resourceContactListRead(ctx, d, meta)...) } func resourceContactListDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 ContactList %s", d.Id()) @@ -196,13 +200,13 @@ func resourceContactListDelete(ctx context.Context, d *schema.ResourceData, meta if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameContactList, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameContactList, d.Id(), err) } - return nil + return diags } func FindContactListByID(ctx context.Context, conn *sesv2.Client, id string) (*sesv2.GetContactListOutput, error) { diff --git a/internal/service/sesv2/dedicated_ip_assignment.go b/internal/service/sesv2/dedicated_ip_assignment.go index c55792c88e0..f34882d337f 100644 --- a/internal/service/sesv2/dedicated_ip_assignment.go +++ b/internal/service/sesv2/dedicated_ip_assignment.go @@ -61,6 +61,7 @@ const ( ) func resourceDedicatedIPAssignmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.PutDedicatedIpInPoolInput{ @@ -70,35 +71,37 @@ func resourceDedicatedIPAssignmentCreate(ctx context.Context, d *schema.Resource _, err := conn.PutDedicatedIpInPool(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameDedicatedIPAssignment, d.Get("ip").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameDedicatedIPAssignment, d.Get("ip").(string), err) } id := toID(d.Get("ip").(string), d.Get("destination_pool_name").(string)) d.SetId(id) - return resourceDedicatedIPAssignmentRead(ctx, d, meta) + return append(diags, resourceDedicatedIPAssignmentRead(ctx, d, meta)...) } func resourceDedicatedIPAssignmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindDedicatedIPAssignmentByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 DedicatedIPAssignment (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameDedicatedIPAssignment, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameDedicatedIPAssignment, d.Id(), err) } d.Set("ip", out.Ip) d.Set("destination_pool_name", out.PoolName) - return nil + return diags } func resourceDedicatedIPAssignmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) ip, _ := splitID(d.Id()) @@ -111,13 +114,13 @@ func resourceDedicatedIPAssignmentDelete(ctx context.Context, d *schema.Resource if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameDedicatedIPAssignment, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameDedicatedIPAssignment, d.Id(), err) } - return nil + return diags } const ( diff --git a/internal/service/sesv2/dedicated_ip_pool.go b/internal/service/sesv2/dedicated_ip_pool.go index 009c72f9b2e..f0e71b1d9cc 100644 --- a/internal/service/sesv2/dedicated_ip_pool.go +++ b/internal/service/sesv2/dedicated_ip_pool.go @@ -75,6 +75,7 @@ const ( ) func resourceDedicatedIPPoolCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.CreateDedicatedIpPoolInput{ @@ -87,34 +88,35 @@ func resourceDedicatedIPPoolCreate(ctx context.Context, d *schema.ResourceData, out, err := conn.CreateDedicatedIpPool(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameDedicatedIPPool, d.Get("pool_name").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameDedicatedIPPool, d.Get("pool_name").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameDedicatedIPPool, d.Get("pool_name").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameDedicatedIPPool, d.Get("pool_name").(string), errors.New("empty output")) } d.SetId(d.Get("pool_name").(string)) - return resourceDedicatedIPPoolRead(ctx, d, meta) + return append(diags, resourceDedicatedIPPoolRead(ctx, d, meta)...) } func resourceDedicatedIPPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindDedicatedIPPoolByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 DedicatedIPPool (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameDedicatedIPPool, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameDedicatedIPPool, d.Id(), err) } poolName := aws.ToString(out.DedicatedIpPool.PoolName) d.Set("pool_name", poolName) d.Set("scaling_mode", string(out.DedicatedIpPool.ScalingMode)) d.Set(names.AttrARN, poolNameToARN(meta, poolName)) - return nil + return diags } func resourceDedicatedIPPoolUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -123,6 +125,7 @@ func resourceDedicatedIPPoolUpdate(ctx context.Context, d *schema.ResourceData, } func resourceDedicatedIPPoolDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 DedicatedIPPool %s", d.Id()) @@ -133,12 +136,12 @@ func resourceDedicatedIPPoolDelete(ctx context.Context, d *schema.ResourceData, if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameDedicatedIPPool, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameDedicatedIPPool, d.Id(), err) } - return nil + return diags } func FindDedicatedIPPoolByID(ctx context.Context, conn *sesv2.Client, id string) (*sesv2.GetDedicatedIpPoolOutput, error) { diff --git a/internal/service/sesv2/dedicated_ip_pool_data_source.go b/internal/service/sesv2/dedicated_ip_pool_data_source.go index ae4c773eafd..3a2ecdbc3c7 100644 --- a/internal/service/sesv2/dedicated_ip_pool_data_source.go +++ b/internal/service/sesv2/dedicated_ip_pool_data_source.go @@ -68,11 +68,12 @@ const ( ) func dataSourceDedicatedIPPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindDedicatedIPPoolByID(ctx, conn, d.Get("pool_name").(string)) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, d.Get("pool_name").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, d.Get("pool_name").(string), err) } poolName := aws.ToString(out.DedicatedIpPool.PoolName) d.SetId(poolName) @@ -81,13 +82,13 @@ func dataSourceDedicatedIPPoolRead(ctx context.Context, d *schema.ResourceData, outIP, err := findDedicatedIPPoolIPs(ctx, conn, poolName) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, poolName, err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, poolName, err) } d.Set("dedicated_ips", flattenDedicatedIPs(outIP.DedicatedIps)) tags, err := listTags(ctx, conn, d.Get(names.AttrARN).(string)) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameDedicatedIPPool, d.Id(), err) } defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig @@ -95,10 +96,10 @@ func dataSourceDedicatedIPPoolRead(ctx context.Context, d *schema.ResourceData, tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) if err := d.Set(names.AttrTags, tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, DSNameDedicatedIPPool, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, DSNameDedicatedIPPool, d.Id(), err) } - return nil + return diags } func flattenDedicatedIPs(apiObjects []types.DedicatedIp) []interface{} { diff --git a/internal/service/sesv2/email_identity.go b/internal/service/sesv2/email_identity.go index d0788c18da4..3f0d620062a 100644 --- a/internal/service/sesv2/email_identity.go +++ b/internal/service/sesv2/email_identity.go @@ -130,6 +130,7 @@ const ( ) func resourceEmailIdentityCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.CreateEmailIdentityInput{ @@ -147,16 +148,16 @@ func resourceEmailIdentityCreate(ctx context.Context, d *schema.ResourceData, me out, err := conn.CreateEmailIdentity(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentity, d.Get("email_identity").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentity, d.Get("email_identity").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentity, d.Get("email_identity").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentity, d.Get("email_identity").(string), errors.New("empty output")) } d.SetId(d.Get("email_identity").(string)) - return resourceEmailIdentityRead(ctx, d, meta) + return append(diags, resourceEmailIdentityRead(ctx, d, meta)...) } func emailIdentityNameToARN(meta interface{}, emailIdentityName string) string { @@ -170,6 +171,7 @@ func emailIdentityNameToARN(meta interface{}, emailIdentityName string) string { } func resourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindEmailIdentityByID(ctx, conn, d.Id()) @@ -177,11 +179,11 @@ func resourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 EmailIdentity (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentity, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentity, d.Id(), err) } arn := emailIdentityNameToARN(meta, d.Id()) @@ -196,7 +198,7 @@ func resourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, meta tfMap["domain_signing_selector"] = d.Get("dkim_signing_attributes.0.domain_signing_selector").(string) if err := d.Set("dkim_signing_attributes", []interface{}{tfMap}); err != nil { - return create.DiagError(names.SESV2, create.ErrActionSetting, ResNameEmailIdentity, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameEmailIdentity, d.Id(), err) } } else { d.Set("dkim_signing_attributes", nil) @@ -205,10 +207,11 @@ func resourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, meta d.Set("identity_type", string(out.IdentityType)) d.Set("verified_for_sending_status", out.VerifiedForSendingStatus) - return nil + return diags } func resourceEmailIdentityUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) if d.HasChanges("configuration_set_name") { @@ -223,7 +226,7 @@ func resourceEmailIdentityUpdate(ctx context.Context, d *schema.ResourceData, me log.Printf("[DEBUG] Updating SESV2 EmailIdentity ConfigurationSetAttributes (%s): %#v", d.Id(), in) _, err := conn.PutEmailIdentityConfigurationSetAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameEmailIdentity, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameEmailIdentity, d.Id(), err) } } @@ -241,14 +244,15 @@ func resourceEmailIdentityUpdate(ctx context.Context, d *schema.ResourceData, me log.Printf("[DEBUG] Updating SESV2 EmailIdentity DkimSigningAttributes (%s): %#v", d.Id(), in) _, err := conn.PutEmailIdentityDkimSigningAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameEmailIdentity, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameEmailIdentity, d.Id(), err) } } - return resourceEmailIdentityRead(ctx, d, meta) + return append(diags, resourceEmailIdentityRead(ctx, d, meta)...) } func resourceEmailIdentityDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 EmailIdentity %s", d.Id()) @@ -260,13 +264,13 @@ func resourceEmailIdentityDelete(ctx context.Context, d *schema.ResourceData, me if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameEmailIdentity, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameEmailIdentity, d.Id(), err) } - return nil + return diags } func FindEmailIdentityByID(ctx context.Context, conn *sesv2.Client, id string) (*sesv2.GetEmailIdentityOutput, error) { diff --git a/internal/service/sesv2/email_identity_data_source.go b/internal/service/sesv2/email_identity_data_source.go index 2c012beb589..988b34e3ef5 100644 --- a/internal/service/sesv2/email_identity_data_source.go +++ b/internal/service/sesv2/email_identity_data_source.go @@ -100,7 +100,7 @@ func dataSourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, me out, err := FindEmailIdentityByID(ctx, conn, name) if err != nil { - return append(diags, create.DiagError(names.SESV2, create.ErrActionReading, DSNameEmailIdentity, name, err)...) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, DSNameEmailIdentity, name, err) } arn := emailIdentityNameToARN(meta, name) @@ -116,7 +116,7 @@ func dataSourceEmailIdentityRead(ctx context.Context, d *schema.ResourceData, me tfMap["domain_signing_selector"] = d.Get("dkim_signing_attributes.0.domain_signing_selector").(string) if err := d.Set("dkim_signing_attributes", []interface{}{tfMap}); err != nil { - return append(diags, create.DiagError(names.SESV2, create.ErrActionSetting, ResNameEmailIdentity, name, err)...) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionSetting, ResNameEmailIdentity, name, err) } } else { d.Set("dkim_signing_attributes", nil) diff --git a/internal/service/sesv2/email_identity_feedback_attributes.go b/internal/service/sesv2/email_identity_feedback_attributes.go index 314ebab34aa..d4b6695952e 100644 --- a/internal/service/sesv2/email_identity_feedback_attributes.go +++ b/internal/service/sesv2/email_identity_feedback_attributes.go @@ -51,6 +51,7 @@ const ( ) func resourceEmailIdentityFeedbackAttributesCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.PutEmailIdentityFeedbackAttributesInput{ @@ -60,19 +61,20 @@ func resourceEmailIdentityFeedbackAttributesCreate(ctx context.Context, d *schem out, err := conn.PutEmailIdentityFeedbackAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentityFeedbackAttributes, d.Get("email_identity").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentityFeedbackAttributes, d.Get("email_identity").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentityFeedbackAttributes, d.Get("email_identity").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentityFeedbackAttributes, d.Get("email_identity").(string), errors.New("empty output")) } d.SetId(d.Get("email_identity").(string)) - return resourceEmailIdentityFeedbackAttributesRead(ctx, d, meta) + return append(diags, resourceEmailIdentityFeedbackAttributesRead(ctx, d, meta)...) } func resourceEmailIdentityFeedbackAttributesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindEmailIdentityByID(ctx, conn, d.Id()) @@ -80,20 +82,21 @@ func resourceEmailIdentityFeedbackAttributesRead(ctx context.Context, d *schema. if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 EmailIdentityFeedbackAttributes (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) } d.Set("email_identity", d.Id()) d.Set("email_forwarding_enabled", out.FeedbackForwardingStatus) - return nil + return diags } func resourceEmailIdentityFeedbackAttributesUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) update := false @@ -108,19 +111,20 @@ func resourceEmailIdentityFeedbackAttributesUpdate(ctx context.Context, d *schem } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating SESV2 EmailIdentityFeedbackAttributes (%s): %#v", d.Id(), in) _, err := conn.PutEmailIdentityFeedbackAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) } - return resourceEmailIdentityFeedbackAttributesRead(ctx, d, meta) + return append(diags, resourceEmailIdentityFeedbackAttributesRead(ctx, d, meta)...) } func resourceEmailIdentityFeedbackAttributesDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 EmailIdentityFeedbackAttributes %s", d.Id()) @@ -132,11 +136,11 @@ func resourceEmailIdentityFeedbackAttributesDelete(ctx context.Context, d *schem if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityFeedbackAttributes, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/sesv2/email_identity_mail_from_attributes.go b/internal/service/sesv2/email_identity_mail_from_attributes.go index 673afef7f8c..1824537ff9e 100644 --- a/internal/service/sesv2/email_identity_mail_from_attributes.go +++ b/internal/service/sesv2/email_identity_mail_from_attributes.go @@ -59,6 +59,7 @@ const ( ) func resourceEmailIdentityMailFromAttributesCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) in := &sesv2.PutEmailIdentityMailFromAttributesInput{ @@ -74,24 +75,25 @@ func resourceEmailIdentityMailFromAttributesCreate(ctx context.Context, d *schem } if in.BehaviorOnMxFailure == types.BehaviorOnMxFailureRejectMessage && (in.MailFromDomain == nil || aws.ToString(in.MailFromDomain) == "") { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), ErrMailFromRequired) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), ErrMailFromRequired) } out, err := conn.PutEmailIdentityMailFromAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), err) } if out == nil { - return create.DiagError(names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionCreating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), errors.New("empty output")) } d.SetId(d.Get("email_identity").(string)) - return resourceEmailIdentityMailFromAttributesRead(ctx, d, meta) + return append(diags, resourceEmailIdentityMailFromAttributesRead(ctx, d, meta)...) } func resourceEmailIdentityMailFromAttributesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) out, err := FindEmailIdentityByID(ctx, conn, d.Id()) @@ -99,11 +101,11 @@ func resourceEmailIdentityMailFromAttributesRead(ctx context.Context, d *schema. if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SESV2 EmailIdentityMailFromAttributes (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityMailFromAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentityMailFromAttributes, d.Id(), err) } d.Set("email_identity", d.Id()) @@ -116,10 +118,11 @@ func resourceEmailIdentityMailFromAttributesRead(ctx context.Context, d *schema. d.Set("mail_from_domain", nil) } - return nil + return diags } func resourceEmailIdentityMailFromAttributesUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) update := false @@ -133,26 +136,27 @@ func resourceEmailIdentityMailFromAttributesUpdate(ctx context.Context, d *schem in.MailFromDomain = aws.String(d.Get("mail_from_domain").(string)) if in.BehaviorOnMxFailure == types.BehaviorOnMxFailureRejectMessage && (in.MailFromDomain == nil || aws.ToString(in.MailFromDomain) == "") { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), ErrMailFromRequired) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityMailFromAttributes, d.Get("email_identity").(string), ErrMailFromRequired) } update = true } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating SESV2 EmailIdentityMailFromAttributes (%s): %#v", d.Id(), in) _, err := conn.PutEmailIdentityMailFromAttributes(ctx, in) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityMailFromAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionUpdating, ResNameEmailIdentityMailFromAttributes, d.Id(), err) } - return resourceEmailIdentityMailFromAttributesRead(ctx, d, meta) + return append(diags, resourceEmailIdentityMailFromAttributesRead(ctx, d, meta)...) } func resourceEmailIdentityMailFromAttributesDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 EmailIdentityMailFromAttributes %s", d.Id()) @@ -164,11 +168,11 @@ func resourceEmailIdentityMailFromAttributesDelete(ctx context.Context, d *schem if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityMailFromAttributes, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityMailFromAttributes, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/sesv2/email_identity_mail_from_attributes_data_source.go b/internal/service/sesv2/email_identity_mail_from_attributes_data_source.go index 896d10c7e4f..8f093ad8d77 100644 --- a/internal/service/sesv2/email_identity_mail_from_attributes_data_source.go +++ b/internal/service/sesv2/email_identity_mail_from_attributes_data_source.go @@ -48,7 +48,7 @@ func dataSourceEmailIdentityMailFromAttributesRead(ctx context.Context, d *schem out, err := FindEmailIdentityByID(ctx, conn, name) if err != nil { - return append(diags, create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityMailFromAttributes, name, err)...) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentityMailFromAttributes, name, err) } d.SetId(name) diff --git a/internal/service/sesv2/email_identity_policy.go b/internal/service/sesv2/email_identity_policy.go index 69c405949fe..db1866705b4 100644 --- a/internal/service/sesv2/email_identity_policy.go +++ b/internal/service/sesv2/email_identity_policy.go @@ -108,7 +108,7 @@ func resourceEmailIdentityPolicyRead(ctx context.Context, d *schema.ResourceData emailIdentity, policyName, err := ParseEmailIdentityPolicyID(d.Id()) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentityPolicy, d.Id(), err) } policy, err := FindEmailIdentityPolicyByID(ctx, conn, d.Id()) @@ -165,13 +165,14 @@ func resourceEmailIdentityPolicyUpdate(ctx context.Context, d *schema.ResourceDa } func resourceEmailIdentityPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SESV2Client(ctx) log.Printf("[INFO] Deleting SESV2 EmailIdentityPolicy %s", d.Id()) emailIdentity, policyName, err := ParseEmailIdentityPolicyID(d.Id()) if err != nil { - return create.DiagError(names.SESV2, create.ErrActionReading, ResNameEmailIdentityPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionReading, ResNameEmailIdentityPolicy, d.Id(), err) } _, err = conn.DeleteEmailIdentityPolicy(ctx, &sesv2.DeleteEmailIdentityPolicyInput{ @@ -182,13 +183,13 @@ func resourceEmailIdentityPolicyDelete(ctx context.Context, d *schema.ResourceDa if err != nil { var nfe *types.NotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityPolicy, d.Id(), err) + return create.AppendDiagError(diags, names.SESV2, create.ErrActionDeleting, ResNameEmailIdentityPolicy, d.Id(), err) } - return nil + return diags } func FindEmailIdentityPolicyByID(ctx context.Context, conn *sesv2.Client, id string) (string, error) { diff --git a/internal/service/sfn/activity.go b/internal/service/sfn/activity.go index 9c19749d45b..c41fc029f54 100644 --- a/internal/service/sfn/activity.go +++ b/internal/service/sfn/activity.go @@ -16,6 +16,7 @@ import ( "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/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -55,6 +56,7 @@ func ResourceActivity() *schema.Resource { } func resourceActivityCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) name := d.Get(names.AttrName).(string) @@ -66,15 +68,16 @@ func resourceActivityCreate(ctx context.Context, d *schema.ResourceData, meta in output, err := conn.CreateActivityWithContext(ctx, input) if err != nil { - return diag.Errorf("creating Step Functions Activity (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Step Functions Activity (%s): %s", name, err) } d.SetId(aws.StringValue(output.ActivityArn)) - return resourceActivityRead(ctx, d, meta) + return append(diags, resourceActivityRead(ctx, d, meta)...) } func resourceActivityRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) output, err := FindActivityByARN(ctx, conn, d.Id()) @@ -82,17 +85,17 @@ func resourceActivityRead(ctx context.Context, d *schema.ResourceData, meta inte if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Step Functions Activity (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Step Functions Activity (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Step Functions Activity (%s): %s", d.Id(), err) } d.Set(names.AttrCreationDate, output.CreationDate.Format(time.RFC3339)) d.Set(names.AttrName, output.Name) - return nil + return diags } func resourceActivityUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -101,6 +104,7 @@ func resourceActivityUpdate(ctx context.Context, d *schema.ResourceData, meta in } func resourceActivityDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) log.Printf("[DEBUG] Deleting Step Functions Activity: %s", d.Id()) @@ -109,10 +113,10 @@ func resourceActivityDelete(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return diag.Errorf("deleting Step Functions Activity (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Step Functions Activity (%s): %s", d.Id(), err) } - return nil + return diags } func FindActivityByARN(ctx context.Context, conn *sfn.SFN, arn string) (*sfn.DescribeActivityOutput, error) { diff --git a/internal/service/sfn/activity_data_source.go b/internal/service/sfn/activity_data_source.go index d8b44815c6b..16bf21e0aa7 100644 --- a/internal/service/sfn/activity_data_source.go +++ b/internal/service/sfn/activity_data_source.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -48,6 +49,7 @@ func DataSourceActivity() *schema.Resource { } func dataSourceActivityRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) if v, ok := d.GetOk(names.AttrName); ok { @@ -69,13 +71,13 @@ func dataSourceActivityRead(ctx context.Context, d *schema.ResourceData, meta in }) if err != nil { - return diag.Errorf("listing Step Functions Activities: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Step Functions Activities: %s", err) } if n := len(activities); n == 0 { - return diag.Errorf("no Step Functions Activities matched") + return sdkdiag.AppendErrorf(diags, "no Step Functions Activities matched") } else if n > 1 { - return diag.Errorf("%d Step Functions Activities matched; use additional constraints to reduce matches to a single Activity", n) + return sdkdiag.AppendErrorf(diags, "%d Step Functions Activities matched; use additional constraints to reduce matches to a single Activity", n) } activity := activities[0] @@ -90,7 +92,7 @@ func dataSourceActivityRead(ctx context.Context, d *schema.ResourceData, meta in activity, err := FindActivityByARN(ctx, conn, arn) if err != nil { - return diag.Errorf("reading Step Functions Activity (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "reading Step Functions Activity (%s): %s", arn, err) } arn = aws.StringValue(activity.ActivityArn) @@ -100,5 +102,5 @@ func dataSourceActivityRead(ctx context.Context, d *schema.ResourceData, meta in d.Set(names.AttrName, activity.Name) } - return nil + return diags } diff --git a/internal/service/sfn/alias.go b/internal/service/sfn/alias.go index 606ffc77fce..b0230646a02 100644 --- a/internal/service/sfn/alias.go +++ b/internal/service/sfn/alias.go @@ -82,6 +82,7 @@ const ( ) func resourceAliasCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) in := &sfn.CreateStateMachineAliasInput{ @@ -95,19 +96,20 @@ func resourceAliasCreate(ctx context.Context, d *schema.ResourceData, meta inter out, err := conn.CreateStateMachineAliasWithContext(ctx, in) if err != nil { - return create.DiagError(names.SFN, create.ErrActionCreating, ResNameAlias, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionCreating, ResNameAlias, d.Get(names.AttrName).(string), err) } if out == nil || out.StateMachineAliasArn == nil { - return create.DiagError(names.SFN, create.ErrActionCreating, ResNameAlias, d.Get(names.AttrName).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SFN, create.ErrActionCreating, ResNameAlias, d.Get(names.AttrName).(string), errors.New("empty output")) } d.SetId(aws.StringValue(out.StateMachineAliasArn)) - return resourceAliasRead(ctx, d, meta) + return append(diags, resourceAliasRead(ctx, d, meta)...) } func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) out, err := FindAliasByARN(ctx, conn, d.Id()) @@ -115,11 +117,11 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interfa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SFN Alias (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SFN, create.ErrActionReading, ResNameAlias, d.Id(), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionReading, ResNameAlias, d.Id(), err) } d.Set(names.AttrARN, out.StateMachineAliasArn) @@ -129,12 +131,13 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interfa d.SetId(aws.StringValue(out.StateMachineAliasArn)) if err := d.Set("routing_configuration", flattenAliasRoutingConfiguration(out.RoutingConfiguration)); err != nil { - return create.DiagError(names.SFN, create.ErrActionSetting, ResNameAlias, d.Id(), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionSetting, ResNameAlias, d.Id(), err) } - return nil + return diags } func resourceAliasUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) update := false @@ -154,31 +157,32 @@ func resourceAliasUpdate(ctx context.Context, d *schema.ResourceData, meta inter } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating SFN Alias (%s): %#v", d.Id(), in) _, err := conn.UpdateStateMachineAliasWithContext(ctx, in) if err != nil { - return create.DiagError(names.SFN, create.ErrActionUpdating, ResNameAlias, d.Id(), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionUpdating, ResNameAlias, d.Id(), err) } - return resourceAliasRead(ctx, d, meta) + return append(diags, resourceAliasRead(ctx, d, meta)...) } func resourceAliasDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) - log.Printf("[INFO] Deleting SFN Alias %s", d.Id()) + log.Printf("[INFO] Deleting SFN Alias %s", d.Id()) _, err := conn.DeleteStateMachineAliasWithContext(ctx, &sfn.DeleteStateMachineAliasInput{ StateMachineAliasArn: aws.String(d.Id()), }) if err != nil { - return create.DiagError(names.SFN, create.ErrActionDeleting, ResNameAlias, d.Id(), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionDeleting, ResNameAlias, d.Id(), err) } - return nil + return diags } func FindAliasByARN(ctx context.Context, conn *sfn.SFN, arn string) (*sfn.DescribeStateMachineAliasOutput, error) { diff --git a/internal/service/sfn/alias_data_source.go b/internal/service/sfn/alias_data_source.go index 81784c445fb..476ecfa0107 100644 --- a/internal/service/sfn/alias_data_source.go +++ b/internal/service/sfn/alias_data_source.go @@ -14,6 +14,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -68,9 +69,10 @@ const ( ) func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) - aliasArn := "" + aliasArn := "" in := &sfn.ListStateMachineAliasesInput{ StateMachineArn: aws.String(d.Get("statemachine_arn").(string)), } @@ -78,11 +80,11 @@ func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta inter out, err := conn.ListStateMachineAliasesWithContext(ctx, in) if err != nil { - return diag.Errorf("listing Step Functions State Machines: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Step Functions State Machines: %s", err) } if n := len(out.StateMachineAliases); n == 0 { - return diag.Errorf("no Step Functions State Machine Aliases matched") + return sdkdiag.AppendErrorf(diags, "no Step Functions State Machine Aliases matched") } for _, in := range out.StateMachineAliases { @@ -92,13 +94,13 @@ func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta inter } if aliasArn == "" { - return diag.Errorf("no Step Functions State Machine Aliases matched") + return sdkdiag.AppendErrorf(diags, "no Step Functions State Machine Aliases matched") } output, err := FindAliasByARN(ctx, conn, aliasArn) if err != nil { - return diag.Errorf("reading Step Functions State Machine Alias (%s): %s", aliasArn, err) + return sdkdiag.AppendErrorf(diags, "reading Step Functions State Machine Alias (%s): %s", aliasArn, err) } d.SetId(aliasArn) @@ -108,8 +110,8 @@ func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrCreationDate, aws.TimeValue(output.CreationDate).Format(time.RFC3339)) if err := d.Set("routing_configuration", flattenAliasRoutingConfiguration(output.RoutingConfiguration)); err != nil { - return create.DiagError(names.SFN, create.ErrActionSetting, ResNameAlias, d.Id(), err) + return create.AppendDiagError(diags, names.SFN, create.ErrActionSetting, ResNameAlias, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/sfn/state_machine.go b/internal/service/sfn/state_machine.go index 9dcd2c9cd64..f7c5e874f03 100644 --- a/internal/service/sfn/state_machine.go +++ b/internal/service/sfn/state_machine.go @@ -20,6 +20,7 @@ import ( "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" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -166,6 +167,7 @@ func ResourceStateMachine() *schema.Resource { } func resourceStateMachineCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) @@ -195,16 +197,17 @@ func resourceStateMachineCreate(ctx context.Context, d *schema.ResourceData, met }, sfn.ErrCodeStateMachineDeleting, "AccessDeniedException") if err != nil { - return diag.Errorf("creating Step Functions State Machine (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating Step Functions State Machine (%s): %s", name, err) } arn := aws.StringValue(outputRaw.(*sfn.CreateStateMachineOutput).StateMachineArn) d.SetId(arn) - return resourceStateMachineRead(ctx, d, meta) + return append(diags, resourceStateMachineRead(ctx, d, meta)...) } func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) output, err := FindStateMachineByARN(ctx, conn, d.Id()) @@ -212,11 +215,11 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Step Functions State Machine (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading Step Functions State Machine (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading Step Functions State Machine (%s): %s", d.Id(), err) } d.Set(names.AttrARN, output.StateMachineArn) @@ -229,7 +232,7 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrDescription, output.Description) if output.LoggingConfiguration != nil { if err := d.Set(names.AttrLoggingConfiguration, []interface{}{flattenLoggingConfiguration(output.LoggingConfiguration)}); err != nil { - return diag.Errorf("setting logging_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting logging_configuration: %s", err) } } else { d.Set(names.AttrLoggingConfiguration, nil) @@ -242,7 +245,7 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrStatus, output.Status) if output.TracingConfiguration != nil { if err := d.Set("tracing_configuration", []interface{}{flattenTracingConfiguration(output.TracingConfiguration)}); err != nil { - return diag.Errorf("setting tracing_configuration: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tracing_configuration: %s", err) } } else { d.Set("tracing_configuration", nil) @@ -255,7 +258,7 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta listVersionsOutput, err := conn.ListStateMachineVersionsWithContext(ctx, input) if err != nil { - return diag.Errorf("listing Step Functions State Machine (%s) Versions: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing Step Functions State Machine (%s) Versions: %s", d.Id(), err) } // The results are sorted in descending order of the version creation time. @@ -266,10 +269,11 @@ func resourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta d.Set("state_machine_version_arn", nil) } - return nil + return diags } func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -300,7 +304,7 @@ func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, met _, err := conn.UpdateStateMachineWithContext(ctx, input) if err != nil { - return diag.Errorf("updating Step Functions State Machine (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating Step Functions State Machine (%s): %s", d.Id(), err) } // Handle eventual consistency after update. @@ -324,14 +328,15 @@ func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, met }) if err != nil { - return diag.Errorf("waiting for Step Functions State Machine (%s) update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Step Functions State Machine (%s) update: %s", d.Id(), err) } } - return resourceStateMachineRead(ctx, d, meta) + return append(diags, resourceStateMachineRead(ctx, d, meta)...) } func resourceStateMachineDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) log.Printf("[DEBUG] Deleting Step Functions State Machine: %s", d.Id()) @@ -340,14 +345,14 @@ func resourceStateMachineDelete(ctx context.Context, d *schema.ResourceData, met }) if err != nil { - return diag.Errorf("deleting Step Functions State Machine (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting Step Functions State Machine (%s): %s", d.Id(), err) } if _, err := waitStateMachineDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { - return diag.Errorf("waiting for Step Functions State Machine (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for Step Functions State Machine (%s) delete: %s", d.Id(), err) } - return nil + return diags } func FindStateMachineByARN(ctx context.Context, conn *sfn.SFN, arn string) (*sfn.DescribeStateMachineOutput, error) { diff --git a/internal/service/sfn/state_machine_data_source.go b/internal/service/sfn/state_machine_data_source.go index 148a2bf21ac..62fa4ef3498 100644 --- a/internal/service/sfn/state_machine_data_source.go +++ b/internal/service/sfn/state_machine_data_source.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -58,6 +59,7 @@ func DataSourceStateMachine() *schema.Resource { } func dataSourceStateMachineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SFNConn(ctx) name := d.Get(names.AttrName).(string) @@ -78,20 +80,20 @@ func dataSourceStateMachineRead(ctx context.Context, d *schema.ResourceData, met }) if err != nil { - return diag.Errorf("listing Step Functions State Machines: %s", err) + return sdkdiag.AppendErrorf(diags, "listing Step Functions State Machines: %s", err) } if n := len(arns); n == 0 { - return diag.Errorf("no Step Functions State Machines matched") + return sdkdiag.AppendErrorf(diags, "no Step Functions State Machines matched") } else if n > 1 { - return diag.Errorf("%d Step Functions State Machines matched; use additional constraints to reduce matches to a single State Machine", n) + return sdkdiag.AppendErrorf(diags, "%d Step Functions State Machines matched; use additional constraints to reduce matches to a single State Machine", n) } arn := arns[0] output, err := FindStateMachineByARN(ctx, conn, arn) if err != nil { - return diag.Errorf("reading Step Functions State Machine (%s): %s", arn, err) + return sdkdiag.AppendErrorf(diags, "reading Step Functions State Machine (%s): %s", arn, err) } d.SetId(arn) @@ -104,5 +106,5 @@ func dataSourceStateMachineRead(ctx context.Context, d *schema.ResourceData, met d.Set("revision_id", output.RevisionId) d.Set(names.AttrStatus, output.Status) - return nil + return diags } diff --git a/internal/service/sns/platform_application.go b/internal/service/sns/platform_application.go index 93898c19595..66496e8f4da 100644 --- a/internal/service/sns/platform_application.go +++ b/internal/service/sns/platform_application.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/attrmap" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -120,11 +121,12 @@ func resourcePlatformApplication() *schema.Resource { } func resourcePlatformApplicationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := platformApplicationAttributeMap.ResourceDataToAPIAttributesCreate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } name := d.Get(names.AttrName).(string) @@ -139,15 +141,16 @@ func resourcePlatformApplicationCreate(ctx context.Context, d *schema.ResourceDa }, "is not a valid role to allow SNS to write to Cloudwatch Logs") if err != nil { - return diag.Errorf("creating SNS Platform Application (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating SNS Platform Application (%s): %s", name, err) } d.SetId(aws.ToString(outputRaw.(*sns.CreatePlatformApplicationOutput).PlatformApplicationArn)) - return resourcePlatformApplicationRead(ctx, d, meta) + return append(diags, resourcePlatformApplicationRead(ctx, d, meta)...) } func resourcePlatformApplicationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) // There is no SNS Describe/GetPlatformApplication to fetch attributes like name and platform @@ -156,7 +159,7 @@ func resourcePlatformApplicationRead(ctx context.Context, d *schema.ResourceData // * Parse out the name and platform arn, name, platform, err := parsePlatformApplicationResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } attributes, err := findPlatformApplicationAttributesByARN(ctx, conn, d.Id()) @@ -164,11 +167,11 @@ func resourcePlatformApplicationRead(ctx context.Context, d *schema.ResourceData if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SNS Platform Application (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading SNS Platform Application (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading SNS Platform Application (%s): %s", d.Id(), err) } d.Set(names.AttrARN, arn) @@ -177,18 +180,19 @@ func resourcePlatformApplicationRead(ctx context.Context, d *schema.ResourceData err = platformApplicationAttributeMap.APIAttributesToResourceData(attributes, d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } - return nil + return diags } func resourcePlatformApplicationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := platformApplicationAttributeMap.ResourceDataToAPIAttributesUpdate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.HasChanges("apple_platform_bundle_id", "apple_platform_team_id", "platform_credential", "platform_principal") { @@ -206,7 +210,7 @@ func resourcePlatformApplicationUpdate(ctx context.Context, d *schema.ResourceDa oPPRaw, nPPRaw := d.GetChange("platform_principal") if len(attributes) == 0 && isChangeSha256Removal(oPCRaw, nPCRaw) && isChangeSha256Removal(oPPRaw, nPPRaw) { - return nil + return diags } attributes[platformApplicationAttributeNamePlatformCredential] = d.Get("platform_credential").(string) @@ -229,13 +233,14 @@ func resourcePlatformApplicationUpdate(ctx context.Context, d *schema.ResourceDa }, "is not a valid role to allow SNS to write to Cloudwatch Logs") if err != nil { - return diag.Errorf("updating SNS Platform Application (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating SNS Platform Application (%s): %s", d.Id(), err) } - return resourcePlatformApplicationRead(ctx, d, meta) + return append(diags, resourcePlatformApplicationRead(ctx, d, meta)...) } func resourcePlatformApplicationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) log.Printf("[DEBUG] Deleting SNS Platform Application: %s", d.Id()) @@ -244,14 +249,14 @@ func resourcePlatformApplicationDelete(ctx context.Context, d *schema.ResourceDa }) if errs.IsA[*types.NotFoundException](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting SNS Platform Application (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting SNS Platform Application (%s): %s", d.Id(), err) } - return nil + return diags } func findPlatformApplicationAttributesByARN(ctx context.Context, conn *sns.Client, arn string) (map[string]string, error) { diff --git a/internal/service/sns/sms_preferences.go b/internal/service/sns/sms_preferences.go index 35167a9ba20..e39f381f73f 100644 --- a/internal/service/sns/sms_preferences.go +++ b/internal/service/sns/sms_preferences.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/attrmap" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) func validateMonthlySpend(v interface{}, k string) (ws []string, errors []error) { @@ -135,11 +136,12 @@ func resourceSMSPreferences() *schema.Resource { } func resourceSMSPreferencesSet(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := SMSPreferencesAttributeMap.ResourceDataToAPIAttributesCreate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &sns.SetSMSAttributesInput{ @@ -149,27 +151,29 @@ func resourceSMSPreferencesSet(ctx context.Context, d *schema.ResourceData, meta _, err = conn.SetSMSAttributes(ctx, input) if err != nil { - return diag.Errorf("setting SNS SMS Preferences: %s", err) + return sdkdiag.AppendErrorf(diags, "setting SNS SMS Preferences: %s", err) } d.SetId("aws_sns_sms_id") - return nil + return diags } func resourceSMSPreferencesGet(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) output, err := conn.GetSMSAttributes(ctx, &sns.GetSMSAttributesInput{}) if err != nil { - return diag.Errorf("reading SNS SMS Preferences: %s", err) + return sdkdiag.AppendErrorf(diags, "reading SNS SMS Preferences: %s", err) } - return diag.FromErr(SMSPreferencesAttributeMap.APIAttributesToResourceData(output.Attributes, d)) + return sdkdiag.AppendFromErr(diags, SMSPreferencesAttributeMap.APIAttributesToResourceData(output.Attributes, d)) } func resourceSMSPreferencesDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) // Reset the attributes to their default value. @@ -185,8 +189,8 @@ func resourceSMSPreferencesDelete(ctx context.Context, d *schema.ResourceData, m _, err := conn.SetSMSAttributes(ctx, input) if err != nil { - return diag.Errorf("resetting SNS SMS Preferences: %s", err) + return sdkdiag.AppendErrorf(diags, "resetting SNS SMS Preferences: %s", err) } - return nil + return diags } diff --git a/internal/service/sns/topic.go b/internal/service/sns/topic.go index 71cc3dcab34..ce64108d084 100644 --- a/internal/service/sns/topic.go +++ b/internal/service/sns/topic.go @@ -273,7 +273,7 @@ func resourceTopicCreate(ctx context.Context, d *schema.ResourceData, meta inter attributes, err := topicAttributeMap.ResourceDataToAPIAttributesCreate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } // The FifoTopic attribute must be passed in the call to CreateTopic. @@ -337,7 +337,7 @@ func resourceTopicRead(ctx context.Context, d *schema.ResourceData, meta any) di if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SNS Topic (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { return sdkdiag.AppendErrorf(diags, "reading SNS Topic (%s): %s", d.Id(), err) @@ -345,12 +345,12 @@ func resourceTopicRead(ctx context.Context, d *schema.ResourceData, meta any) di err = topicAttributeMap.APIAttributesToResourceData(attributes, d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } arn, err := arn.Parse(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } name := arn.Resource @@ -361,28 +361,30 @@ func resourceTopicRead(ctx context.Context, d *schema.ResourceData, meta any) di d.Set(names.AttrNamePrefix, create.NamePrefixFromName(name)) } - return nil + return diags } func resourceTopicUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { attributes, err := topicAttributeMap.ResourceDataToAPIAttributesUpdate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } err = putTopicAttributes(ctx, conn, d.Id(), attributes) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } } - return resourceTopicRead(ctx, d, meta) + return append(diags, resourceTopicRead(ctx, d, meta)...) } func resourceTopicDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) log.Printf("[DEBUG] Deleting SNS Topic: %s", d.Id()) @@ -391,14 +393,14 @@ func resourceTopicDelete(ctx context.Context, d *schema.ResourceData, meta inter }) if errs.IsA[*types.NotFoundException](err) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting SNS Topic (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting SNS Topic (%s): %s", d.Id(), err) } - return nil + return diags } func resourceTopicCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { diff --git a/internal/service/sns/topic_data_source.go b/internal/service/sns/topic_data_source.go index 89796d85608..766e27098b8 100644 --- a/internal/service/sns/topic_data_source.go +++ b/internal/service/sns/topic_data_source.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -37,20 +38,21 @@ func dataSourceTopic() *schema.Resource { } func dataSourceTopicRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) name := d.Get(names.AttrName).(string) topic, err := findTopicByName(ctx, conn, name) if err != nil { - return diag.Errorf("reading SNS Topic (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading SNS Topic (%s): %s", name, err) } topicARN := aws.ToString(topic.TopicArn) d.SetId(topicARN) d.Set(names.AttrARN, topicARN) - return nil + return diags } func findTopicByName(ctx context.Context, conn *sns.Client, name string) (*types.Topic, error) { diff --git a/internal/service/sns/topic_policy.go b/internal/service/sns/topic_policy.go index 61421aa8646..46b0ee75fbc 100644 --- a/internal/service/sns/topic_policy.go +++ b/internal/service/sns/topic_policy.go @@ -61,28 +61,30 @@ func resourceTopicPolicy() *schema.Resource { } func resourceTopicPolicyUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) policy, err := structure.NormalizeJsonString(d.Get(names.AttrPolicy).(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get(names.AttrPolicy).(string), err) + return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", d.Get(names.AttrPolicy).(string), err) } arn := d.Get(names.AttrARN).(string) err = putTopicPolicy(ctx, conn, arn, policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if d.IsNewResource() { d.SetId(arn) } - return resourceTopicPolicyRead(ctx, d, meta) + return append(diags, resourceTopicPolicyRead(ctx, d, meta)...) } func resourceTopicPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := findTopicAttributesWithValidAWSPrincipalsByARN(ctx, conn, d.Id()) @@ -100,11 +102,11 @@ func resourceTopicPolicyRead(ctx context.Context, d *schema.ResourceData, meta i if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SNS Topic Policy (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading SNS Topic Policy (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading SNS Topic Policy (%s): %s", d.Id(), err) } d.Set(names.AttrARN, attributes[topicAttributeNameTopicARN]) @@ -112,12 +114,12 @@ func resourceTopicPolicyRead(ctx context.Context, d *schema.ResourceData, meta i policyToSet, err := verify.PolicyToSet(d.Get(names.AttrPolicy).(string), policy) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrPolicy, policyToSet) - return nil + return diags } func resourceTopicPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/internal/service/sns/topic_subscription.go b/internal/service/sns/topic_subscription.go index 048654b937f..dcef58b2333 100644 --- a/internal/service/sns/topic_subscription.go +++ b/internal/service/sns/topic_subscription.go @@ -25,6 +25,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/attrmap" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" "github.com/hashicorp/terraform-provider-aws/names" @@ -174,11 +175,12 @@ func resourceTopicSubscription() *schema.Resource { } func resourceTopicSubscriptionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := subscriptionAttributeMap.ResourceDataToAPIAttributesCreate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } // Endpoint, Protocol and TopicArn are not passed in Attributes. @@ -198,7 +200,7 @@ func resourceTopicSubscriptionCreate(ctx context.Context, d *schema.ResourceData output, err := conn.Subscribe(ctx, input) if err != nil { - return diag.Errorf("creating SNS Topic Subscription: %s", err) + return sdkdiag.AppendErrorf(diags, "creating SNS Topic Subscription: %s", err) } d.SetId(aws.ToString(output.SubscriptionArn)) @@ -220,14 +222,15 @@ func resourceTopicSubscriptionCreate(ctx context.Context, d *schema.ResourceData } if _, err := waitSubscriptionConfirmed(ctx, conn, d.Id(), timeout); err != nil { - return diag.Errorf("waiting for SNS Topic Subscription (%s) confirmation: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for SNS Topic Subscription (%s) confirmation: %s", d.Id(), err) } } - return resourceTopicSubscriptionRead(ctx, d, meta) + return append(diags, resourceTopicSubscriptionRead(ctx, d, meta)...) } func resourceTopicSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, subscriptionCreateTimeout, func() (interface{}, error) { @@ -237,36 +240,38 @@ func resourceTopicSubscriptionRead(ctx context.Context, d *schema.ResourceData, if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SNS Topic Subscription %s not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading SNS Topic Subscription (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading SNS Topic Subscription (%s): %s", d.Id(), err) } attributes := outputRaw.(map[string]string) - return diag.FromErr(subscriptionAttributeMap.APIAttributesToResourceData(attributes, d)) + return sdkdiag.AppendFromErr(diags, subscriptionAttributeMap.APIAttributesToResourceData(attributes, d)) } func resourceTopicSubscriptionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) attributes, err := subscriptionAttributeMap.ResourceDataToAPIAttributesUpdate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } err = putSubscriptionAttributes(ctx, conn, d.Id(), attributes) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } - return resourceTopicSubscriptionRead(ctx, d, meta) + return append(diags, resourceTopicSubscriptionRead(ctx, d, meta)...) } func resourceTopicSubscriptionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SNSClient(ctx) log.Printf("[DEBUG] Deleting SNS Topic Subscription: %s", d.Id()) @@ -275,18 +280,18 @@ func resourceTopicSubscriptionDelete(ctx context.Context, d *schema.ResourceData }) if errs.IsAErrorMessageContains[*types.InvalidParameterException](err, "Cannot unsubscribe a subscription that is pending confirmation") { - return nil + return diags } if err != nil { - return diag.Errorf("deleting SNS Topic Subscription (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting SNS Topic Subscription (%s): %s", d.Id(), err) } if _, err := waitSubscriptionDeleted(ctx, conn, d.Id(), subscriptionDeleteTimeout); err != nil { - return diag.Errorf("waiting for SNS Topic Subscription (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for SNS Topic Subscription (%s) delete: %s", d.Id(), err) } - return nil + return diags } func putSubscriptionAttributes(ctx context.Context, conn *sns.Client, arn string, attributes map[string]string) error { diff --git a/internal/service/sqs/attribute_funcs.go b/internal/service/sqs/attribute_funcs.go index 52a238b71af..c47c9286b07 100644 --- a/internal/service/sqs/attribute_funcs.go +++ b/internal/service/sqs/attribute_funcs.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -28,11 +29,12 @@ type queueAttributeHandler struct { } func (h *queueAttributeHandler) Upsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) attrValue, err := structure.NormalizeJsonString(d.Get(h.SchemaKey).(string)) if err != nil { - return diag.Errorf("%s (%s) is invalid JSON: %s", h.SchemaKey, d.Get(h.SchemaKey).(string), err) + return sdkdiag.AppendErrorf(diags, "%s (%s) is invalid JSON: %s", h.SchemaKey, d.Get(h.SchemaKey).(string), err) } attributes := map[types.QueueAttributeName]string{ @@ -49,19 +51,20 @@ func (h *queueAttributeHandler) Upsert(ctx context.Context, d *schema.ResourceDa }, errCodeInvalidAttributeValue, "Invalid value for the parameter Policy") if err != nil { - return diag.Errorf("setting SQS Queue (%s) attribute (%s): %s", url, h.AttributeName, err) + return sdkdiag.AppendErrorf(diags, "setting SQS Queue (%s) attribute (%s): %s", url, h.AttributeName, err) } d.SetId(url) if err := waitQueueAttributesPropagated(ctx, conn, d.Id(), attributes); err != nil { - return diag.Errorf("waiting for SQS Queue (%s) attribute (%s) create: %s", d.Id(), h.AttributeName, err) + return sdkdiag.AppendErrorf(diags, "waiting for SQS Queue (%s) attribute (%s) create: %s", d.Id(), h.AttributeName, err) } - return h.Read(ctx, d, meta) + return append(diags, h.Read(ctx, d, meta)...) } func (h *queueAttributeHandler) Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) outputRaw, err := tfresource.RetryWhenNotFound(ctx, queueAttributeReadTimeout, func() (interface{}, error) { @@ -71,32 +74,33 @@ func (h *queueAttributeHandler) Read(ctx context.Context, d *schema.ResourceData if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SQS Queue (%s) attribute (%s) not found, removing from state", d.Id(), h.AttributeName) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading SQS Queue (%s) attribute (%s): %s", d.Id(), h.AttributeName, err) + return sdkdiag.AppendErrorf(diags, "reading SQS Queue (%s) attribute (%s): %s", d.Id(), h.AttributeName, err) } newValue, err := h.ToSet(d.Get(h.SchemaKey).(string), aws.ToString(outputRaw.(*string))) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } if h.SchemaKey == names.AttrPolicy { newValue, err = verify.PolicyToSet(d.Get(names.AttrPolicy).(string), newValue) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } } d.Set(h.SchemaKey, newValue) d.Set("queue_url", d.Id()) - return nil + return diags } func (h *queueAttributeHandler) Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) log.Printf("[DEBUG] Deleting SQS Queue (%s) attribute: %s", d.Id(), h.AttributeName) @@ -109,16 +113,16 @@ func (h *queueAttributeHandler) Delete(ctx context.Context, d *schema.ResourceDa }) if tfawserr.ErrCodeEquals(err, errCodeQueueDoesNotExist) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting SQS Queue (%s) attribute (%s): %s", d.Id(), h.AttributeName, err) + return sdkdiag.AppendErrorf(diags, "deleting SQS Queue (%s) attribute (%s): %s", d.Id(), h.AttributeName, err) } if err := waitQueueAttributesPropagated(ctx, conn, d.Id(), attributes); err != nil { - return diag.Errorf("waiting for SQS Queue (%s) attribute (%s) delete: %s", d.Id(), h.AttributeName, err) + return sdkdiag.AppendErrorf(diags, "waiting for SQS Queue (%s) attribute (%s) delete: %s", d.Id(), h.AttributeName, err) } - return nil + return diags } diff --git a/internal/service/sqs/queue.go b/internal/service/sqs/queue.go index e7498eb7f04..a8e56163754 100644 --- a/internal/service/sqs/queue.go +++ b/internal/service/sqs/queue.go @@ -29,6 +29,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfmaps "github.com/hashicorp/terraform-provider-aws/internal/maps" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" @@ -211,6 +212,7 @@ func resourceQueue() *schema.Resource { } func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) name := queueName(d) @@ -221,7 +223,7 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter attributes, err := queueAttributeMap.ResourceDataToAPIAttributesCreate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input.Attributes = flex.ExpandStringyValueMap(attributes) @@ -240,13 +242,13 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter } if err != nil { - return diag.Errorf("creating SQS Queue (%s): %s", name, err) + return sdkdiag.AppendErrorf(diags, "creating SQS Queue (%s): %s", name, err) } d.SetId(aws.ToString(outputRaw.(*sqs.CreateQueueOutput).QueueUrl)) if err := waitQueueAttributesPropagated(ctx, conn, d.Id(), attributes); err != nil { - return diag.Errorf("waiting for SQS Queue (%s) attributes create: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for SQS Queue (%s) attributes create: %s", d.Id(), err) } // For partitions not supporting tag-on-create, attempt tag after create. @@ -255,18 +257,19 @@ func resourceQueueCreate(ctx context.Context, d *schema.ResourceData, meta inter // If default tags only, continue. Otherwise, error. if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { - return resourceQueueRead(ctx, d, meta) + return append(diags, resourceQueueRead(ctx, d, meta)...) } if err != nil { - return diag.Errorf("setting SQS Queue (%s) tags: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "setting SQS Queue (%s) tags: %s", d.Id(), err) } } - return resourceQueueRead(ctx, d, meta) + return append(diags, resourceQueueRead(ctx, d, meta)...) } func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) outputRaw, err := tfresource.RetryWhenNotFound(ctx, queueReadTimeout, func() (interface{}, error) { @@ -276,21 +279,21 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SQS Queue (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return diag.Errorf("reading SQS Queue (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "reading SQS Queue (%s): %s", d.Id(), err) } name, err := queueNameFromURL(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } err = queueAttributeMap.APIAttributesToResourceData(outputRaw.(map[types.QueueAttributeName]string), d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } // Backwards compatibility: https://github.com/hashicorp/terraform-provider-aws/issues/19786. @@ -306,16 +309,17 @@ func resourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interfa } d.Set(names.AttrURL, d.Id()) - return nil + return diags } func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { attributes, err := queueAttributeMap.ResourceDataToAPIAttributesUpdate(d) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } input := &sqs.SetQueueAttributesInput{ @@ -326,18 +330,19 @@ func resourceQueueUpdate(ctx context.Context, d *schema.ResourceData, meta inter _, err = conn.SetQueueAttributes(ctx, input) if err != nil { - return diag.Errorf("updating SQS Queue (%s) attributes: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating SQS Queue (%s) attributes: %s", d.Id(), err) } if err := waitQueueAttributesPropagated(ctx, conn, d.Id(), attributes); err != nil { - return diag.Errorf("waiting for SQS Queue (%s) attributes update: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for SQS Queue (%s) attributes update: %s", d.Id(), err) } } - return resourceQueueRead(ctx, d, meta) + return append(diags, resourceQueueRead(ctx, d, meta)...) } func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) log.Printf("[DEBUG] Deleting SQS Queue: %s", d.Id()) @@ -346,18 +351,18 @@ func resourceQueueDelete(ctx context.Context, d *schema.ResourceData, meta inter }) if tfawserr.ErrCodeEquals(err, errCodeQueueDoesNotExist) { - return nil + return diags } if err != nil { - return diag.Errorf("deleting SQS Queue (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "deleting SQS Queue (%s): %s", d.Id(), err) } if err := waitQueueDeleted(ctx, conn, d.Id()); err != nil { - return diag.Errorf("waiting for SQS Queue (%s) delete: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for SQS Queue (%s) delete: %s", d.Id(), err) } - return nil + return diags } func resourceQueueCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { diff --git a/internal/service/sqs/queue_data_source.go b/internal/service/sqs/queue_data_source.go index 12f242e22d0..1bd5ffc8d62 100644 --- a/internal/service/sqs/queue_data_source.go +++ b/internal/service/sqs/queue_data_source.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -45,6 +46,7 @@ func dataSourceQueue() *schema.Resource { } func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig @@ -52,14 +54,14 @@ func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta inter urlOutput, err := findQueueURLByName(ctx, conn, name) if err != nil { - return diag.Errorf("reading SQS Queue (%s) URL: %s", name, err) + return sdkdiag.AppendErrorf(diags, "reading SQS Queue (%s) URL: %s", name, err) } queueURL := aws.ToString(urlOutput) attributesOutput, err := findQueueAttributeByTwoPartKey(ctx, conn, queueURL, types.QueueAttributeNameQueueArn) if err != nil { - return diag.Errorf("reading SQS Queue (%s) ARN attribute: %s", queueURL, err) + return sdkdiag.AppendErrorf(diags, "reading SQS Queue (%s) ARN attribute: %s", queueURL, err) } d.SetId(queueURL) @@ -71,18 +73,18 @@ func dataSourceQueueRead(ctx context.Context, d *schema.ResourceData, meta inter if errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { // Some partitions may not support tagging, giving error log.Printf("[WARN] failed listing tags for SQS Queue (%s): %s", d.Id(), err) - return nil + return diags } if err != nil { - return diag.Errorf("listing tags for SQS Queue (%s): %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "listing tags for SQS Queue (%s): %s", d.Id(), err) } if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } - return nil + return diags } func findQueueURLByName(ctx context.Context, conn *sqs.Client, name string) (*string, error) { diff --git a/internal/service/sqs/queues_data_source.go b/internal/service/sqs/queues_data_source.go index 088f5b248a0..e90b9d617a3 100644 --- a/internal/service/sqs/queues_data_source.go +++ b/internal/service/sqs/queues_data_source.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) // @SDKDataSource("aws_sqs_queues") @@ -33,6 +34,7 @@ func dataSourceQueues() *schema.Resource { } func dataSourceQueuesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SQSClient(ctx) input := &sqs.ListQueuesInput{} @@ -47,7 +49,7 @@ func dataSourceQueuesRead(ctx context.Context, d *schema.ResourceData, meta inte page, err := pages.NextPage(ctx) if err != nil { - return diag.Errorf("listing SQS Queues: %s", err) + return sdkdiag.AppendErrorf(diags, "listing SQS Queues: %s", err) } queueURLs = append(queueURLs, page.QueueUrls...) @@ -56,5 +58,5 @@ func dataSourceQueuesRead(ctx context.Context, d *schema.ResourceData, meta inte d.SetId(meta.(*conns.AWSClient).Region) d.Set("queue_urls", queueURLs) - return nil + return diags } diff --git a/internal/service/ssm/default_patch_baseline.go b/internal/service/ssm/default_patch_baseline.go index 0067977ca74..339b9e60771 100644 --- a/internal/service/ssm/default_patch_baseline.go +++ b/internal/service/ssm/default_patch_baseline.go @@ -118,7 +118,7 @@ func resourceDefaultPatchBaselineRead(ctx context.Context, d *schema.ResourceDat if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSM Default Patch Baseline (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/ssmcontacts/contact.go b/internal/service/ssmcontacts/contact.go index 458e23caf45..e2694c0f8f5 100644 --- a/internal/service/ssmcontacts/contact.go +++ b/internal/service/ssmcontacts/contact.go @@ -66,6 +66,7 @@ const ( ) func resourceContactCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMContactsClient(ctx) input := &ssmcontacts.CreateContactInput{ @@ -78,19 +79,20 @@ func resourceContactCreate(ctx context.Context, d *schema.ResourceData, meta int output, err := client.CreateContact(ctx, input) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionCreating, ResNameContact, d.Get(names.AttrAlias).(string), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionCreating, ResNameContact, d.Get(names.AttrAlias).(string), err) } if output == nil { - return create.DiagError(names.SSMContacts, create.ErrActionCreating, ResNameContact, d.Get(names.AttrAlias).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionCreating, ResNameContact, d.Get(names.AttrAlias).(string), errors.New("empty output")) } d.SetId(aws.ToString(output.ContactArn)) - return resourceContactRead(ctx, d, meta) + return append(diags, resourceContactRead(ctx, d, meta)...) } func resourceContactRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) out, err := findContactByID(ctx, conn, d.Id()) @@ -98,21 +100,22 @@ func resourceContactRead(ctx context.Context, d *schema.ResourceData, meta inter if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSMContacts Contact (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, ResNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, ResNameContact, d.Id(), err) } if err := setContactResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionSetting, ResNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionSetting, ResNameContact, d.Id(), err) } - return nil + return diags } func resourceContactUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) if d.HasChanges(names.AttrDisplayName) { @@ -123,14 +126,15 @@ func resourceContactUpdate(ctx context.Context, d *schema.ResourceData, meta int _, err := conn.UpdateContact(ctx, in) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionUpdating, ResNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionUpdating, ResNameContact, d.Id(), err) } } - return resourceContactRead(ctx, d, meta) + return append(diags, resourceContactRead(ctx, d, meta)...) } func resourceContactDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) log.Printf("[INFO] Deleting SSMContacts Contact %s", d.Id()) @@ -142,10 +146,10 @@ func resourceContactDelete(ctx context.Context, d *schema.ResourceData, meta int if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SSMContacts, create.ErrActionDeleting, ResNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionDeleting, ResNameContact, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmcontacts/contact_channel.go b/internal/service/ssmcontacts/contact_channel.go index cf014437940..4dffcab43ec 100644 --- a/internal/service/ssmcontacts/contact_channel.go +++ b/internal/service/ssmcontacts/contact_channel.go @@ -76,6 +76,7 @@ const ( ) func resourceContactChannelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) delivery_address := expandContactChannelAddress(d.Get("delivery_address").([]interface{})) @@ -89,19 +90,20 @@ func resourceContactChannelCreate(ctx context.Context, d *schema.ResourceData, m out, err := conn.CreateContactChannel(ctx, in) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionCreating, ResNameContactChannel, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionCreating, ResNameContactChannel, d.Get(names.AttrName).(string), err) } if out == nil { - return create.DiagError(names.SSMContacts, create.ErrActionCreating, ResNameContactChannel, d.Get(names.AttrName).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionCreating, ResNameContactChannel, d.Get(names.AttrName).(string), errors.New("empty output")) } d.SetId(aws.ToString(out.ContactChannelArn)) - return resourceContactChannelRead(ctx, d, meta) + return append(diags, resourceContactChannelRead(ctx, d, meta)...) } func resourceContactChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) out, err := findContactChannelByID(ctx, conn, d.Id()) @@ -109,21 +111,22 @@ func resourceContactChannelRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSMContacts ContactChannel (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, ResNameContactChannel, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, ResNameContactChannel, d.Id(), err) } if err := setContactChannelResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionSetting, ResNameContactChannel, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionSetting, ResNameContactChannel, d.Id(), err) } - return nil + return diags } func resourceContactChannelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) update := false @@ -143,19 +146,20 @@ func resourceContactChannelUpdate(ctx context.Context, d *schema.ResourceData, m } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating SSMContacts ContactChannel (%s): %#v", d.Id(), in) _, err := conn.UpdateContactChannel(ctx, in) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionUpdating, ResNameContactChannel, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionUpdating, ResNameContactChannel, d.Id(), err) } - return resourceContactChannelRead(ctx, d, meta) + return append(diags, resourceContactChannelRead(ctx, d, meta)...) } func resourceContactChannelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) log.Printf("[INFO] Deleting SSMContacts ContactChannel %s", d.Id()) @@ -167,11 +171,11 @@ func resourceContactChannelDelete(ctx context.Context, d *schema.ResourceData, m if err != nil { var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - return nil + return diags } - return create.DiagError(names.SSMContacts, create.ErrActionDeleting, ResNameContactChannel, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionDeleting, ResNameContactChannel, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmcontacts/contact_channel_data_source.go b/internal/service/ssmcontacts/contact_channel_data_source.go index f8e95bafc73..60033875a8c 100644 --- a/internal/service/ssmcontacts/contact_channel_data_source.go +++ b/internal/service/ssmcontacts/contact_channel_data_source.go @@ -61,20 +61,21 @@ const ( ) func dataSourceContactChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) arn := d.Get(names.AttrARN).(string) out, err := findContactChannelByID(ctx, conn, arn) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, DSNameContactChannel, arn, err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, DSNameContactChannel, arn, err) } d.SetId(aws.ToString(out.ContactChannelArn)) if err := setContactChannelResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionSetting, ResNameContactChannel, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionSetting, ResNameContactChannel, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmcontacts/contact_data_source.go b/internal/service/ssmcontacts/contact_data_source.go index b3aeb12104b..55077641521 100644 --- a/internal/service/ssmcontacts/contact_data_source.go +++ b/internal/service/ssmcontacts/contact_data_source.go @@ -47,32 +47,33 @@ const ( ) func dataSourceContactRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) arn := d.Get(names.AttrARN).(string) out, err := findContactByID(ctx, conn, arn) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, DSNameContact, arn, err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, DSNameContact, arn, err) } d.SetId(aws.ToString(out.ContactArn)) if err := setContactResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionSetting, DSNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionSetting, DSNameContact, d.Id(), err) } tags, err := listTags(ctx, conn, d.Id()) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, DSNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, DSNameContact, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig //lintignore:AWSR002 if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionSetting, DSNameContact, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionSetting, DSNameContact, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmcontacts/plan.go b/internal/service/ssmcontacts/plan.go index 7bbb490030e..f554b279482 100644 --- a/internal/service/ssmcontacts/plan.go +++ b/internal/service/ssmcontacts/plan.go @@ -99,6 +99,7 @@ const ( ) func resourcePlanCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) contactId := d.Get("contact_id").(string) @@ -114,21 +115,20 @@ func resourcePlanCreate(ctx context.Context, d *schema.ResourceData, meta interf _, err := conn.UpdateContact(ctx, in) if err != nil { - return create.DiagError( - names.SSMContacts, + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionCreating, ResNamePlan, contactId, - err, - ) + err) } d.SetId(contactId) - return resourcePlanRead(ctx, d, meta) + return append(diags, resourcePlanRead(ctx, d, meta)...) } func resourcePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) out, err := findContactByID(ctx, conn, d.Id()) @@ -136,21 +136,22 @@ func resourcePlanRead(ctx context.Context, d *schema.ResourceData, meta interfac if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSMContacts Plan (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, ResNamePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, ResNamePlan, d.Id(), err) } if err := setPlanResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, ResNamePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, ResNamePlan, d.Id(), err) } - return nil + return diags } func resourcePlanUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) update := false @@ -168,19 +169,20 @@ func resourcePlanUpdate(ctx context.Context, d *schema.ResourceData, meta interf } if !update { - return nil + return diags } log.Printf("[DEBUG] Updating SSMContacts Plan (%s): %#v", d.Id(), in) _, err := conn.UpdateContact(ctx, in) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionUpdating, ResNamePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionUpdating, ResNamePlan, d.Id(), err) } - return resourcePlanRead(ctx, d, meta) + return append(diags, resourcePlanRead(ctx, d, meta)...) } func resourcePlanDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) log.Printf("[INFO] Deleting SSMContacts Plan %s", d.Id()) @@ -193,8 +195,8 @@ func resourcePlanDelete(ctx context.Context, d *schema.ResourceData, meta interf }) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionDeleting, ResNamePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionDeleting, ResNamePlan, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmcontacts/plan_data_source.go b/internal/service/ssmcontacts/plan_data_source.go index ac72b91c6da..ab9feff504a 100644 --- a/internal/service/ssmcontacts/plan_data_source.go +++ b/internal/service/ssmcontacts/plan_data_source.go @@ -85,20 +85,21 @@ const ( ) func dataSourcePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics conn := meta.(*conns.AWSClient).SSMContactsClient(ctx) contactId := d.Get("contact_id").(string) out, err := findContactByID(ctx, conn, contactId) if err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, DSNamePlan, contactId, err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, DSNamePlan, contactId, err) } d.SetId(aws.ToString(out.ContactArn)) if err := setPlanResourceData(d, out); err != nil { - return create.DiagError(names.SSMContacts, create.ErrActionReading, DSNamePlan, contactId, err) + return create.AppendDiagError(diags, names.SSMContacts, create.ErrActionReading, DSNamePlan, contactId, err) } - return nil + return diags } diff --git a/internal/service/ssmincidents/replication_set.go b/internal/service/ssmincidents/replication_set.go index da474cf6d79..66691803c6e 100644 --- a/internal/service/ssmincidents/replication_set.go +++ b/internal/service/ssmincidents/replication_set.go @@ -106,6 +106,7 @@ func ResourceReplicationSet() *schema.Resource { } func resourceReplicationSetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) input := &ssmincidents.CreateReplicationSetInput{ @@ -115,11 +116,11 @@ func resourceReplicationSetCreate(ctx context.Context, d *schema.ResourceData, m createReplicationSetOutput, err := client.CreateReplicationSet(ctx, input) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionCreating, ResNameReplicationSet, "", err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionCreating, ResNameReplicationSet, "", err) } if createReplicationSetOutput == nil { - return create.DiagError(names.SSMIncidents, create.ErrActionCreating, ResNameReplicationSet, "", errors.New("empty output")) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionCreating, ResNameReplicationSet, "", errors.New("empty output")) } d.SetId(aws.ToString(createReplicationSetOutput.Arn)) @@ -129,13 +130,14 @@ func resourceReplicationSetCreate(ctx context.Context, d *schema.ResourceData, m } if err := ssmincidents.NewWaitForReplicationSetActiveWaiter(client).Wait(ctx, getReplicationSetInput, d.Timeout(schema.TimeoutCreate)); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionWaitingForCreation, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionWaitingForCreation, ResNameReplicationSet, d.Id(), err) } - return resourceReplicationSetRead(ctx, d, meta) + return append(diags, resourceReplicationSetRead(ctx, d, meta)...) } func resourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) replicationSet, err := FindReplicationSetByID(ctx, client, d.Id()) @@ -143,11 +145,11 @@ func resourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, met if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSMIncidents ReplicationSet (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) } d.Set(names.AttrARN, replicationSet.Arn) @@ -155,14 +157,15 @@ func resourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, met d.Set("deletion_protected", replicationSet.DeletionProtected) d.Set("last_modified_by", replicationSet.LastModifiedBy) if err := d.Set(names.AttrRegion, flattenRegions(replicationSet.RegionMap)); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionSetting, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionSetting, ResNameReplicationSet, d.Id(), err) } d.Set(names.AttrStatus, replicationSet.Status) - return nil + return diags } func resourceReplicationSetUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) if d.HasChanges(names.AttrRegion) { @@ -171,13 +174,13 @@ func resourceReplicationSetUpdate(ctx context.Context, d *schema.ResourceData, m } if err := updateRegionsInput(d, input); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionUpdating, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionUpdating, ResNameReplicationSet, d.Id(), err) } log.Printf("[DEBUG] Updating SSMIncidents ReplicationSet (%s): %#v", d.Id(), input) _, err := client.UpdateReplicationSet(ctx, input) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionUpdating, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionUpdating, ResNameReplicationSet, d.Id(), err) } getReplicationSetInput := &ssmincidents.GetReplicationSetInput{ @@ -185,14 +188,15 @@ func resourceReplicationSetUpdate(ctx context.Context, d *schema.ResourceData, m } if err := ssmincidents.NewWaitForReplicationSetActiveWaiter(client).Wait(ctx, getReplicationSetInput, d.Timeout(schema.TimeoutUpdate)); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionWaitingForUpdate, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionWaitingForUpdate, ResNameReplicationSet, d.Id(), err) } } - return resourceReplicationSetRead(ctx, d, meta) + return append(diags, resourceReplicationSetRead(ctx, d, meta)...) } func resourceReplicationSetDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) log.Printf("[INFO] Deleting SSMIncidents ReplicationSet: %s", d.Id()) @@ -203,10 +207,10 @@ func resourceReplicationSetDelete(ctx context.Context, d *schema.ResourceData, m if err != nil { var notFoundError *types.ResourceNotFoundException if errors.As(err, ¬FoundError) { - return nil + return diags } - return create.DiagError(names.SSMIncidents, create.ErrActionDeleting, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionDeleting, ResNameReplicationSet, d.Id(), err) } getReplicationSetInput := &ssmincidents.GetReplicationSetInput{ @@ -214,10 +218,10 @@ func resourceReplicationSetDelete(ctx context.Context, d *schema.ResourceData, m } if err := ssmincidents.NewWaitForReplicationSetDeletedWaiter(client).Wait(ctx, getReplicationSetInput, d.Timeout(schema.TimeoutDelete)); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionWaitingForDeletion, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionWaitingForDeletion, ResNameReplicationSet, d.Id(), err) } - return nil + return diags } // converts a list of regions to a map which maps region name to kms key arn diff --git a/internal/service/ssmincidents/replication_set_data_source.go b/internal/service/ssmincidents/replication_set_data_source.go index 34043c12fd5..7a9ad0e67fe 100644 --- a/internal/service/ssmincidents/replication_set_data_source.go +++ b/internal/service/ssmincidents/replication_set_data_source.go @@ -75,12 +75,13 @@ const ( ) func dataSourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) arn, err := getReplicationSetARN(ctx, client) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) } d.SetId(arn) @@ -88,7 +89,7 @@ func dataSourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, m replicationSet, err := FindReplicationSetByID(ctx, client, d.Id()) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, ResNameReplicationSet, d.Id(), err) } d.Set(names.AttrARN, replicationSet.Arn) @@ -98,21 +99,21 @@ func dataSourceReplicationSetRead(ctx context.Context, d *schema.ResourceData, m d.Set(names.AttrStatus, replicationSet.Status) if err := d.Set(names.AttrRegion, flattenRegions(replicationSet.RegionMap)); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionSetting, ResNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionSetting, ResNameReplicationSet, d.Id(), err) } tags, err := listTags(ctx, client, d.Id()) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, DSNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, DSNameReplicationSet, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig //lintignore:AWSR002 if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionSetting, DSNameReplicationSet, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionSetting, DSNameReplicationSet, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/ssmincidents/response_plan.go b/internal/service/ssmincidents/response_plan.go index 606aa770af8..442315e7563 100644 --- a/internal/service/ssmincidents/response_plan.go +++ b/internal/service/ssmincidents/response_plan.go @@ -194,6 +194,7 @@ func ResourceResponsePlan() *schema.Resource { } func resourceResponsePlanCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) input := &ssmincidents.CreateResponsePlanInput{ @@ -210,19 +211,20 @@ func resourceResponsePlanCreate(ctx context.Context, d *schema.ResourceData, met output, err := client.CreateResponsePlan(ctx, input) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionCreating, ResNameResponsePlan, d.Get(names.AttrName).(string), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionCreating, ResNameResponsePlan, d.Get(names.AttrName).(string), err) } if output == nil { - return create.DiagError(names.SSMIncidents, create.ErrActionCreating, ResNameResponsePlan, d.Get(names.AttrName).(string), errors.New("empty output")) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionCreating, ResNameResponsePlan, d.Get(names.AttrName).(string), errors.New("empty output")) } d.SetId(aws.ToString(output.Arn)) - return resourceResponsePlanRead(ctx, d, meta) + return append(diags, resourceResponsePlanRead(ctx, d, meta)...) } func resourceResponsePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) responsePlan, err := FindResponsePlanByID(ctx, client, d.Id()) @@ -230,21 +232,22 @@ func resourceResponsePlanRead(ctx context.Context, d *schema.ResourceData, meta if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SSMIncidents ResponsePlan (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, ResNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, ResNameResponsePlan, d.Id(), err) } if d, err := setResponsePlanResourceData(d, responsePlan); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionSetting, ResNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionSetting, ResNameResponsePlan, d.Id(), err) } - return nil + return diags } func resourceResponsePlanUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { @@ -281,14 +284,15 @@ func resourceResponsePlanUpdate(ctx context.Context, d *schema.ResourceData, met _, err := client.UpdateResponsePlan(ctx, input) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionUpdating, ResNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionUpdating, ResNameResponsePlan, d.Id(), err) } } - return resourceResponsePlanRead(ctx, d, meta) + return append(diags, resourceResponsePlanRead(ctx, d, meta)...) } func resourceResponsePlanDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) log.Printf("[INFO] Deleting SSMIncidents ResponsePlan %s", d.Id()) @@ -303,13 +307,13 @@ func resourceResponsePlanDelete(ctx context.Context, d *schema.ResourceData, met var notFoundError *types.ResourceNotFoundException if errors.As(err, ¬FoundError) { - return nil + return diags } - return create.DiagError(names.SSMIncidents, create.ErrActionDeleting, ResNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionDeleting, ResNameResponsePlan, d.Id(), err) } - return nil + return diags } // input validation already done in flattenIncidentTemplate function diff --git a/internal/service/ssmincidents/response_plan_data_source.go b/internal/service/ssmincidents/response_plan_data_source.go index caf3db15aba..27643b1b2e0 100644 --- a/internal/service/ssmincidents/response_plan_data_source.go +++ b/internal/service/ssmincidents/response_plan_data_source.go @@ -173,6 +173,7 @@ const ( ) func dataSourceResponsePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics client := meta.(*conns.AWSClient).SSMIncidentsClient(ctx) d.SetId(d.Get(names.AttrARN).(string)) @@ -180,24 +181,24 @@ func dataSourceResponsePlanRead(ctx context.Context, d *schema.ResourceData, met responsePlan, err := FindResponsePlanByID(ctx, client, d.Id()) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) } if d, err := setResponsePlanResourceData(d, responsePlan); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) } tags, err := listTags(ctx, client, d.Id()) if err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionReading, DSNameResponsePlan, d.Id(), err) } ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig //lintignore:AWSR002 if err := d.Set(names.AttrTags, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return create.DiagError(names.SSMIncidents, create.ErrActionSetting, DSNameResponsePlan, d.Id(), err) + return create.AppendDiagError(diags, names.SSMIncidents, create.ErrActionSetting, DSNameResponsePlan, d.Id(), err) } - return nil + return diags } diff --git a/internal/service/swf/domain.go b/internal/service/swf/domain.go index 1ad788e7bdd..d98f4852848 100644 --- a/internal/service/swf/domain.go +++ b/internal/service/swf/domain.go @@ -106,7 +106,7 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte d.SetId(name) - return resourceDomainRead(ctx, d, meta) + return append(diags, resourceDomainRead(ctx, d, meta)...) } func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -118,7 +118,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] SWF Domain (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/synthetics/group.go b/internal/service/synthetics/group.go index 1f3467c6413..31e8cfb1d29 100644 --- a/internal/service/synthetics/group.go +++ b/internal/service/synthetics/group.go @@ -90,7 +90,7 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Synthetics Group (%s) not found, removing from state", d.Id()) d.SetId("") - return nil + return diags } if err != nil { diff --git a/internal/service/synthetics/group_association.go b/internal/service/synthetics/group_association.go index fc6c96c7b48..f282d9b31e1 100644 --- a/internal/service/synthetics/group_association.go +++ b/internal/service/synthetics/group_association.go @@ -89,7 +89,7 @@ func resourceGroupAssociationRead(ctx context.Context, d *schema.ResourceData, m canaryArn, groupName, err := GroupAssociationParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } group, err := FindAssociatedGroup(ctx, conn, canaryArn, groupName) @@ -97,7 +97,7 @@ func resourceGroupAssociationRead(ctx context.Context, d *schema.ResourceData, m if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Synthetics Group Association between canary (%s) and group (%s) not found, removing from state", canaryArn, groupName) d.SetId("") - return nil + return diags } if err != nil { @@ -121,7 +121,7 @@ func resourceGroupAssociationDelete(ctx context.Context, d *schema.ResourceData, canaryArn, groupName, err := GroupAssociationParseResourceID(d.Id()) if err != nil { - return diag.FromErr(err) + return sdkdiag.AppendFromErr(diags, err) } in := &synthetics.DisassociateResourceInput{