From 1c3a8cd2d6b51e8e2fc635c006a227af528f114b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 19 Sep 2024 13:28:48 -0400 Subject: [PATCH 01/45] ci(semgrep): add avoid-errs-Must check This check will match on any use of `errs.Must(...)` within `internal/service/**/`. Errors should be handled explicitly in service packages to avoid the possibility of crashing the provider during execution. This function was originally intended for use while initializing service clients during the `ConfigureProvider` operation, where a panic is the appropriate course of action. --- .ci/.semgrep.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.ci/.semgrep.yml b/.ci/.semgrep.yml index f8dd7303494..0a02114b994 100644 --- a/.ci/.semgrep.yml +++ b/.ci/.semgrep.yml @@ -659,3 +659,14 @@ rules: $DIAGS = sdkdiag.AppendErrorf($DIAGS, ...) } severity: ERROR + + - id: avoid-errs-Must + languages: [go] + message: Avoid use of `errs.Must()` in service packages, handle errors explicitly instead. + paths: + include: + - internal/service + patterns: + - pattern-either: + - pattern: errs.Must(...) + severity: WARNING From a39a4413e91b76acb0a2916f82ddfe83c35f9bf5 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 14:36:53 -0400 Subject: [PATCH 02/45] account: remove use of `errs.Must` --- internal/service/account/region.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/service/account/region.go b/internal/service/account/region.go index 75db7dd10c4..7003d8afd70 100644 --- a/internal/service/account/region.go +++ b/internal/service/account/region.go @@ -16,7 +16,6 @@ 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" "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" @@ -78,7 +77,10 @@ func resourceRegionUpdate(ctx context.Context, d *schema.ResourceData, meta inte accountID := "" if v, ok := d.GetOk(names.AttrAccountID); ok { accountID = v.(string) - id = errs.Must(flex.FlattenResourceId([]string{accountID, region}, regionResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{accountID, region}, regionResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "enabling Account Region (%s): %s", id, err) + } } else { id = region } From 46f5b0faafb5a305fbd6c71333aec785124318b7 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 14:37:11 -0400 Subject: [PATCH 03/45] acmpca: remove use of `errs.Must` --- internal/service/acmpca/permission.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/service/acmpca/permission.go b/internal/service/acmpca/permission.go index 89f26941aa0..2b9e99fc585 100644 --- a/internal/service/acmpca/permission.go +++ b/internal/service/acmpca/permission.go @@ -81,7 +81,11 @@ func resourcePermissionCreate(ctx context.Context, d *schema.ResourceData, meta caARN := d.Get("certificate_authority_arn").(string) principal := d.Get(names.AttrPrincipal).(string) sourceAccount := d.Get("source_account").(string) - id := errs.Must(flex.FlattenResourceId([]string{caARN, principal, sourceAccount}, permissionResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{caARN, principal, sourceAccount}, permissionResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating ACM PCA Permission (%s): %s", id, err) + } + input := &acmpca.CreatePermissionInput{ Actions: expandPermissionActions(d.Get(names.AttrActions).(*schema.Set)), CertificateAuthorityArn: aws.String(caARN), @@ -92,9 +96,7 @@ func resourcePermissionCreate(ctx context.Context, d *schema.ResourceData, meta input.SourceAccount = aws.String(sourceAccount) } - _, err := conn.CreatePermission(ctx, input) - - if err != nil { + if _, err := conn.CreatePermission(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "creating ACM PCA Permission (%s): %s", id, err) } From de6e050a105579be80d754b94d146d3aefb7815e Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 19 Sep 2024 16:48:15 -0400 Subject: [PATCH 04/45] appfabric: remove use of `errs.Must` --- .../service/appfabric/app_authorization.go | 24 +++++++++++++++---- .../appfabric/app_authorization_connection.go | 21 +++++++++++----- internal/service/appfabric/app_bundle.go | 7 +++++- internal/service/appfabric/ingestion.go | 23 ++++++++++++++---- .../appfabric/ingestion_destination.go | 24 +++++++++++++++---- 5 files changed, 80 insertions(+), 19 deletions(-) diff --git a/internal/service/appfabric/app_authorization.go b/internal/service/appfabric/app_authorization.go index 6e6ba292670..0252d586831 100644 --- a/internal/service/appfabric/app_authorization.go +++ b/internal/service/appfabric/app_authorization.go @@ -217,8 +217,13 @@ func (r *appAuthorizationResource) Create(ctx context.Context, request resource. return } + uuid, err := uuid.GenerateUUID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating AppFabric App (%s) Authorization", data.App.ValueString()), err.Error()) + } + input.AppBundleIdentifier = data.AppBundleARN.ValueStringPointer() - input.ClientToken = aws.String(errs.Must(uuid.GenerateUUID())) + input.ClientToken = aws.String(uuid) input.Tags = getTagsIn(ctx) output, err := conn.CreateAppAuthorization(ctx, input) @@ -229,9 +234,15 @@ func (r *appAuthorizationResource) Create(ctx context.Context, request resource. return } + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("flattening resource ID AppFabric App (%s) Authorization", data.App.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) + // Set values for unknowns. data.AppAuthorizationARN = fwflex.StringToFramework(ctx, output.AppAuthorization.AppAuthorizationArn) - data.setID() appAuthorization, err := waitAppAuthorizationCreated(ctx, conn, data.AppAuthorizationARN.ValueString(), data.AppBundleARN.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) @@ -525,8 +536,13 @@ func (m *appAuthorizationResourceModel) InitFromID() error { return nil } -func (m *appAuthorizationResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AppAuthorizationARN.ValueString(), m.AppBundleARN.ValueString()}, appAuthorizationResourceIDPartCount, false))) +func (m *appAuthorizationResourceModel) setID() (string, error) { + parts := []string{ + m.AppAuthorizationARN.ValueString(), + m.AppBundleARN.ValueString(), + } + + return flex.FlattenResourceId(parts, appAuthorizationResourceIDPartCount, false) } var ( diff --git a/internal/service/appfabric/app_authorization_connection.go b/internal/service/appfabric/app_authorization_connection.go index 48290357c7a..735ec526fbc 100644 --- a/internal/service/appfabric/app_authorization_connection.go +++ b/internal/service/appfabric/app_authorization_connection.go @@ -135,8 +135,12 @@ func (r *appAuthorizationConnectionResource) Create(ctx context.Context, request return } - // Set values for unknowns. - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("flattening resource ID AppFabric App Authorization (%s) Connection", data.AppAuthorizationARN.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) appAuthorization, err := waitConnectAppAuthorizationCreated(ctx, conn, data.AppAuthorizationARN.ValueString(), data.AppBundleARN.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) @@ -167,7 +171,7 @@ func (r *appAuthorizationConnectionResource) Read(ctx context.Context, request r return } - if err := data.InitFromID(); err != nil { + if err := data.initFromID(); err != nil { response.Diagnostics.AddError("parsing resource ID", err.Error()) return @@ -272,7 +276,7 @@ const ( appAuthorizationConnectionResourceIDPartCount = 2 ) -func (m *appAuthorizationConnectionResourceModel) InitFromID() error { +func (m *appAuthorizationConnectionResourceModel) initFromID() error { parts, err := flex.ExpandResourceId(m.ID.ValueString(), appAuthorizationConnectionResourceIDPartCount, false) if err != nil { return err @@ -284,8 +288,13 @@ func (m *appAuthorizationConnectionResourceModel) InitFromID() error { return nil } -func (m *appAuthorizationConnectionResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AppAuthorizationARN.ValueString(), m.AppBundleARN.ValueString()}, appAuthorizationConnectionResourceIDPartCount, false))) +func (m *appAuthorizationConnectionResourceModel) setID() (string, error) { + parts := []string{ + m.AppAuthorizationARN.ValueString(), + m.AppBundleARN.ValueString(), + } + + return flex.FlattenResourceId(parts, appAuthorizationConnectionResourceIDPartCount, false) } type authRequestModel struct { diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 0c9af1db2d2..3bca6523df8 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -75,8 +75,13 @@ func (r *appBundleResource) Create(ctx context.Context, request resource.CreateR conn := r.Meta().AppFabricClient(ctx) + uuid, err := uuid.GenerateUUID() + if err != nil { + response.Diagnostics.AddError("creating AppFabric App Bundle", err.Error()) + } + input := &appfabric.CreateAppBundleInput{ - ClientToken: aws.String(errs.Must(uuid.GenerateUUID())), + ClientToken: aws.String(uuid), CustomerManagedKeyIdentifier: fwflex.StringFromFramework(ctx, data.CustomerManagedKeyARN), Tags: getTagsIn(ctx), } diff --git a/internal/service/appfabric/ingestion.go b/internal/service/appfabric/ingestion.go index 5cffa7aa34b..a8c231c98b5 100644 --- a/internal/service/appfabric/ingestion.go +++ b/internal/service/appfabric/ingestion.go @@ -110,9 +110,14 @@ func (r *ingestionResource) Create(ctx context.Context, request resource.CreateR return } + uuid, err := uuid.GenerateUUID() + if err != nil { + response.Diagnostics.AddError("creating AppFabric Ingestion", err.Error()) + } + // Additional fields. input.AppBundleIdentifier = fwflex.StringFromFramework(ctx, data.AppBundleARN) - input.ClientToken = aws.String(errs.Must(uuid.GenerateUUID())) + input.ClientToken = aws.String(uuid) input.Tags = getTagsIn(ctx) output, err := conn.CreateIngestion(ctx, input) @@ -130,7 +135,12 @@ func (r *ingestionResource) Create(ctx context.Context, request resource.CreateR // Set values for unknowns. data.ARN = fwflex.StringToFramework(ctx, output.Ingestion.Arn) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattening resource ID AppFabric Ingestion", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -255,6 +265,11 @@ func (m *ingestionResourceModel) InitFromID() error { return nil } -func (m *ingestionResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AppBundleARN.ValueString(), m.ARN.ValueString()}, ingestionResourceIDPartCount, false))) +func (m *ingestionResourceModel) setID() (string, error) { + parts := []string{ + m.AppBundleARN.ValueString(), + m.ARN.ValueString(), + } + + return flex.FlattenResourceId(parts, ingestionResourceIDPartCount, false) } diff --git a/internal/service/appfabric/ingestion_destination.go b/internal/service/appfabric/ingestion_destination.go index d2bed80052c..1092204be30 100644 --- a/internal/service/appfabric/ingestion_destination.go +++ b/internal/service/appfabric/ingestion_destination.go @@ -258,9 +258,14 @@ func (r *ingestionDestinationResource) Create(ctx context.Context, request resou input.ProcessingConfiguration = processingConfiguration } + uuid, err := uuid.GenerateUUID() + if err != nil { + response.Diagnostics.AddError("creating AppFabric Ingestion Destination", err.Error()) + } + // Additional fields. input.AppBundleIdentifier = data.AppBundleARN.ValueStringPointer() - input.ClientToken = aws.String(errs.Must(uuid.GenerateUUID())) + input.ClientToken = aws.String(uuid) input.IngestionIdentifier = data.IngestionARN.ValueStringPointer() input.Tags = getTagsIn(ctx) @@ -274,7 +279,12 @@ func (r *ingestionDestinationResource) Create(ctx context.Context, request resou // Set values for unknowns. data.ARN = fwflex.StringToFramework(ctx, output.IngestionDestination.Arn) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattening resource ID AppFabric Ingestion Destination", err.Error()) + return + } + data.ID = types.StringValue(id) if _, err := waitIngestionDestinationActive(ctx, conn, data.AppBundleARN.ValueString(), data.IngestionARN.ValueString(), data.ARN.ValueString(), r.CreateTimeout(ctx, data.Timeouts)); err != nil { response.State.SetAttribute(ctx, path.Root(names.AttrID), data.ID) // Set 'id' so as to taint the resource. @@ -561,8 +571,14 @@ func (m *ingestionDestinationResourceModel) InitFromID() error { return nil } -func (m *ingestionDestinationResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AppBundleARN.ValueString(), m.IngestionARN.ValueString(), m.ARN.ValueString()}, ingestionDestinationResourceIDPartCount, false))) +func (m *ingestionDestinationResourceModel) setID() (string, error) { + parts := []string{ + m.AppBundleARN.ValueString(), + m.IngestionARN.ValueString(), + m.ARN.ValueString(), + } + + return flex.FlattenResourceId(parts, ingestionDestinationResourceIDPartCount, false) } type destinationConfigurationModel struct { From 489d731a6a4e115d5db9db0152dad648e4b835e6 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 14:37:24 -0400 Subject: [PATCH 05/45] appsync: remove use of `errs.Must` --- .../service/appsync/source_api_association.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/service/appsync/source_api_association.go b/internal/service/appsync/source_api_association.go index b9594e94aa0..ec5e70e8512 100644 --- a/internal/service/appsync/source_api_association.go +++ b/internal/service/appsync/source_api_association.go @@ -192,7 +192,15 @@ func (r *sourceAPIAssociationResource) Create(ctx context.Context, request resou plan.AssociationId = flex.StringToFramework(ctx, out.SourceApiAssociation.AssociationId) plan.MergedAPIId = flex.StringToFramework(ctx, out.SourceApiAssociation.MergedApiId) - plan.setID() + id, err := plan.setID() + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.AppSync, create.ErrActionFlatteningResourceId, resNameSourceAPIAssociation, plan.MergedAPIId.String(), err), + err.Error(), + ) + return + } + plan.ID = types.StringValue(id) createTimeout := r.CreateTimeout(ctx, plan.Timeouts) _, err = waitSourceAPIAssociationCreated(ctx, conn, plan.AssociationId.ValueString(), aws.ToString(out.SourceApiAssociation.MergedApiArn), createTimeout) @@ -485,6 +493,11 @@ func (m *sourceAPIAssociationResourceModel) InitFromID() error { return nil } -func (m *sourceAPIAssociationResourceModel) setID() { - m.ID = types.StringValue(errs.Must(autoflex.FlattenResourceId([]string{m.MergedAPIId.ValueString(), m.AssociationId.ValueString()}, sourceAPIAssociationIDPartCount, false))) +func (m *sourceAPIAssociationResourceModel) setID() (string, error) { + parts := []string{ + m.MergedAPIId.ValueString(), + m.AssociationId.ValueString(), + } + + return autoflex.FlattenResourceId(parts, sourceAPIAssociationIDPartCount, false) } From 44fd0bf9dde02a845d3e1307de7976584345a0fe Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 14:10:21 -0400 Subject: [PATCH 06/45] bedrockagent: remove use of `errs.Must` --- .../service/bedrockagent/agent_action_group.go | 17 ++++++++++++++--- internal/service/bedrockagent/agent_alias.go | 16 +++++++++++++--- .../agent_knowledge_base_association.go | 17 ++++++++++++++--- internal/service/bedrockagent/data_source.go | 16 +++++++++++++--- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/internal/service/bedrockagent/agent_action_group.go b/internal/service/bedrockagent/agent_action_group.go index 99e9d9e6be8..d6a1b672573 100644 --- a/internal/service/bedrockagent/agent_action_group.go +++ b/internal/service/bedrockagent/agent_action_group.go @@ -252,7 +252,12 @@ func (r *agentActionGroupResource) Create(ctx context.Context, request resource. // Set values for unknowns. data.ActionGroupID = fwflex.StringToFramework(ctx, output.AgentActionGroup.ActionGroupId) data.ActionGroupState = fwtypes.StringEnumValue(output.AgentActionGroup.ActionGroupState) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattening resource ID Bedrock Agent Action Group", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -430,8 +435,14 @@ func (m *agentActionGroupResourceModel) InitFromID() error { return nil } -func (m *agentActionGroupResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.ActionGroupID.ValueString(), m.AgentID.ValueString(), m.AgentVersion.ValueString()}, agentActionGroupResourceIDPartCount, false))) +func (m *agentActionGroupResourceModel) setID() (string, error) { + parts := []string{ + m.ActionGroupID.ValueString(), + m.AgentID.ValueString(), + m.AgentVersion.ValueString(), + } + + return flex.FlattenResourceId(parts, agentActionGroupResourceIDPartCount, false) } type actionGroupExecutorModel struct { diff --git a/internal/service/bedrockagent/agent_alias.go b/internal/service/bedrockagent/agent_alias.go index 9c9bb20111f..36fa6e2117c 100644 --- a/internal/service/bedrockagent/agent_alias.go +++ b/internal/service/bedrockagent/agent_alias.go @@ -137,7 +137,12 @@ func (r *agentAliasResource) Create(ctx context.Context, request resource.Create // Set values for unknowns. data.AgentAliasID = fwflex.StringToFramework(ctx, output.AgentAlias.AgentAliasId) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattning resource ID Bedrock Agent Alias", err.Error()) + return + } + data.ID = types.StringValue(id) alias, err := waitAgentAliasCreated(ctx, conn, data.AgentAliasID.ValueString(), data.AgentID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) @@ -376,8 +381,13 @@ func (m *agentAliasResourceModel) InitFromID() error { return nil } -func (m *agentAliasResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AgentAliasID.ValueString(), m.AgentID.ValueString()}, agentAliasResourceIDPartCount, false))) +func (m *agentAliasResourceModel) setID() (string, error) { + parts := []string{ + m.AgentAliasID.ValueString(), + m.AgentID.ValueString(), + } + + return flex.FlattenResourceId(parts, agentAliasResourceIDPartCount, false) } type agentAliasRoutingConfigurationListItemModel struct { diff --git a/internal/service/bedrockagent/agent_knowledge_base_association.go b/internal/service/bedrockagent/agent_knowledge_base_association.go index 92c787fdb93..61e23081829 100644 --- a/internal/service/bedrockagent/agent_knowledge_base_association.go +++ b/internal/service/bedrockagent/agent_knowledge_base_association.go @@ -121,7 +121,12 @@ func (r *agentKnowledgeBaseAssociationResource) Create(ctx context.Context, requ } // Set values for unknowns. - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattening resource ID Bedrock Agent Knowledge Base Association", err.Error()) + return + } + data.ID = types.StringValue(id) _, err = prepareAgent(ctx, conn, data.AgentID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) if err != nil { @@ -288,6 +293,12 @@ func (m *agentKnowledgeBaseAssociationResourceModel) InitFromID() error { return nil } -func (m *agentKnowledgeBaseAssociationResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.AgentID.ValueString(), m.AgentVersion.ValueString(), m.KnowledgeBaseID.ValueString()}, agentKnowledgeBaseAssociationResourceIDPartCount, false))) +func (m *agentKnowledgeBaseAssociationResourceModel) setID() (string, error) { + parts := []string{ + m.AgentID.ValueString(), + m.AgentVersion.ValueString(), + m.KnowledgeBaseID.ValueString(), + } + + return flex.FlattenResourceId(parts, agentKnowledgeBaseAssociationResourceIDPartCount, false) } diff --git a/internal/service/bedrockagent/data_source.go b/internal/service/bedrockagent/data_source.go index 3c8b7bcdbc7..c98ce0a65ee 100644 --- a/internal/service/bedrockagent/data_source.go +++ b/internal/service/bedrockagent/data_source.go @@ -402,7 +402,12 @@ func (r *dataSourceResource) Create(ctx context.Context, request resource.Create } data.DataSourceID = fwflex.StringToFramework(ctx, outputRaw.(*bedrockagent.CreateDataSourceOutput).DataSource.DataSourceId) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("flattening resource ID Bedrock Agent Data Source", err.Error()) + return + } + data.ID = types.StringValue(id) ds, err := waitDataSourceCreated(ctx, conn, data.DataSourceID.ValueString(), data.KnowledgeBaseID.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) @@ -627,8 +632,13 @@ func (m *dataSourceResourceModel) InitFromID() error { return nil } -func (m *dataSourceResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.DataSourceID.ValueString(), m.KnowledgeBaseID.ValueString()}, dataSourceResourceIDPartCount, false))) +func (m *dataSourceResourceModel) setID() (string, error) { + parts := []string{ + m.DataSourceID.ValueString(), + m.KnowledgeBaseID.ValueString(), + } + + return flex.FlattenResourceId(parts, dataSourceResourceIDPartCount, false) } type dataSourceConfigurationModel struct { From bd3c194cb83a8ddbc542575f87217bfbdcbc0ce8 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:43:43 -0400 Subject: [PATCH 07/45] cloudformation: remove use of `errs.Must` --- internal/service/cloudformation/stack_instances_test.go | 2 +- internal/service/cloudformation/sweep.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/service/cloudformation/stack_instances_test.go b/internal/service/cloudformation/stack_instances_test.go index b4a123ce682..c2e1ef02ef8 100644 --- a/internal/service/cloudformation/stack_instances_test.go +++ b/internal/service/cloudformation/stack_instances_test.go @@ -573,7 +573,7 @@ func testAccCheckStackInstancesExists(ctx context.Context, resourceName string, } func attributeLength(attribute string) int { - return errs.Must(strconv.Atoi(attribute)) + return errs.Must(strconv.Atoi(attribute)) // nosemgrep: ci.avoid-errs-Must } // testAccCheckStackInstancesForOrganizationalUnitExists is a variant of the diff --git a/internal/service/cloudformation/sweep.go b/internal/service/cloudformation/sweep.go index 2efbbf1eacc..ab9e4b608b6 100644 --- a/internal/service/cloudformation/sweep.go +++ b/internal/service/cloudformation/sweep.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/flex" tforganizations "github.com/hashicorp/terraform-provider-aws/internal/service/organizations" "github.com/hashicorp/terraform-provider-aws/internal/sweep" @@ -107,7 +106,10 @@ func sweepStackSetInstances(region string) error { r := resourceStackSetInstance() d := r.Data(nil) - id := errs.Must(flex.FlattenResourceId([]string{stackSetID, accountOrOrgID, aws.ToString(v.Region)}, stackSetInstanceResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{stackSetID, accountOrOrgID, aws.ToString(v.Region)}, stackSetInstanceResourceIDPartCount, false) + if err != nil { + sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error flattening resource ID CloudFormation StackSet Instances (%s): %w", region, err)) + } d.SetId(id) d.Set("call_as", awstypes.CallAsSelf) if ouID != "" { From 8da6dc52fdc7c04edc363e1ebb43b73fad7c8ee8 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:44:04 -0400 Subject: [PATCH 08/45] cloudfrontkeyvaluestore: remove use of `errs.Must` --- internal/service/cloudfrontkeyvaluestore/key.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/service/cloudfrontkeyvaluestore/key.go b/internal/service/cloudfrontkeyvaluestore/key.go index aac86465565..6518d20a0b8 100644 --- a/internal/service/cloudfrontkeyvaluestore/key.go +++ b/internal/service/cloudfrontkeyvaluestore/key.go @@ -119,7 +119,12 @@ func (r *keyResource) Create(ctx context.Context, request resource.CreateRequest // Set values for unknowns. data.TotalSizeInBytes = fwflex.Int64ToFramework(ctx, output.TotalSizeInBytes) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating CloudFront KeyValueStore (%s) Key (%s)", kvsARN, data.Key.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -340,6 +345,11 @@ func (data *keyResourceModel) InitFromID() error { return nil } -func (data *keyResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.KvsARN.ValueString(), data.Key.ValueString()}, keyResourceIDPartCount, false))) +func (data *keyResourceModel) setID() (string, error) { + parts := []string{ + data.KvsARN.ValueString(), + data.Key.ValueString(), + } + + return flex.FlattenResourceId(parts, keyResourceIDPartCount, false) } From 9794f22d7bc4694f0e06d43a994b51d1e8c7758d Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:44:30 -0400 Subject: [PATCH 09/45] cognitoidp: remove use of `errs.Must` --- .../service/cognitoidp/user_pool_ui_customization.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/service/cognitoidp/user_pool_ui_customization.go b/internal/service/cognitoidp/user_pool_ui_customization.go index d44a5fd0d86..f51e93fad30 100644 --- a/internal/service/cognitoidp/user_pool_ui_customization.go +++ b/internal/service/cognitoidp/user_pool_ui_customization.go @@ -84,7 +84,11 @@ func resourceUserPoolUICustomizationPut(ctx context.Context, d *schema.ResourceD conn := meta.(*conns.AWSClient).CognitoIDPClient(ctx) userPoolID, clientID := d.Get(names.AttrUserPoolID).(string), d.Get(names.AttrClientID).(string) - id := errs.Must(flex.FlattenResourceId([]string{userPoolID, clientID}, userPoolUICustomizationResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{userPoolID, clientID}, userPoolUICustomizationResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating Cognito User Pool UI Customization (%s): %s", id, err) + } + input := &cognitoidentityprovider.SetUICustomizationInput{ ClientId: aws.String(clientID), UserPoolId: aws.String(userPoolID), @@ -102,9 +106,7 @@ func resourceUserPoolUICustomizationPut(ctx context.Context, d *schema.ResourceD input.ImageFile = v } - _, err := conn.SetUICustomization(ctx, input) - - if err != nil { + if _, err := conn.SetUICustomization(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "setting Cognito User Pool UI Customization (%s): %s", id, err) } From 641876171163b0ff6a3b4f1543a9204ecf52d664 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:44:49 -0400 Subject: [PATCH 10/45] computeoptimizer: remove use of `errs.Must` --- .../recommendation_preferences.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/service/computeoptimizer/recommendation_preferences.go b/internal/service/computeoptimizer/recommendation_preferences.go index 033a49c4149..dc1d71dfd45 100644 --- a/internal/service/computeoptimizer/recommendation_preferences.go +++ b/internal/service/computeoptimizer/recommendation_preferences.go @@ -220,7 +220,12 @@ func (r *recommendationPreferencesResource) Create(ctx context.Context, request } // Set values for unknowns. - data.setID(ctx) + id, err := data.setID(ctx) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("flattening resource ID Compute Optimizer Recommendation Preferences (%s)", data.ID.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) // Read the resource to get other Computed attribute values. scope := fwdiag.Must(data.Scope.ToPtr(ctx)) @@ -439,9 +444,15 @@ func (m *recommendationPreferencesResourceModel) InitFromID(ctx context.Context) return nil } -func (m *recommendationPreferencesResourceModel) setID(ctx context.Context) { +func (m *recommendationPreferencesResourceModel) setID(ctx context.Context) (string, error) { scope := fwdiag.Must(m.Scope.ToPtr(ctx)) - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.ResourceType.ValueString(), scope.Name.ValueString(), scope.Value.ValueString()}, recommendationPreferencesResourceIDPartCount, false))) + parts := []string{ + m.ResourceType.ValueString(), + scope.Name.ValueString(), + scope.Value.ValueString(), + } + + return flex.FlattenResourceId(parts, recommendationPreferencesResourceIDPartCount, false) } type externalMetricsPreferenceModel struct { From 7c12a3980ac2e45513db9aaf8165fe7811011113 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 14:47:57 -0400 Subject: [PATCH 11/45] connect: remove use of `errs.Must` --- .../service/connect/lambda_function_association.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/service/connect/lambda_function_association.go b/internal/service/connect/lambda_function_association.go index 24e6acbdfb3..26f13f89510 100644 --- a/internal/service/connect/lambda_function_association.go +++ b/internal/service/connect/lambda_function_association.go @@ -60,15 +60,17 @@ func resourceLambdaFunctionAssociationCreate(ctx context.Context, d *schema.Reso instanceID := d.Get(names.AttrInstanceID).(string) functionARN := d.Get(names.AttrFunctionARN).(string) - id := errs.Must(flex.FlattenResourceId([]string{instanceID, functionARN}, lambdaFunctionAssociationResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{instanceID, functionARN}, lambdaFunctionAssociationResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating Connect Lambda Function Association (%s): %s", id, err) + } + input := &connect.AssociateLambdaFunctionInput{ FunctionArn: aws.String(functionARN), InstanceId: aws.String(instanceID), } - _, err := conn.AssociateLambdaFunction(ctx, input) - - if err != nil { + if _, err := conn.AssociateLambdaFunction(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "creating Connect Lambda Function Association (%s): %s", id, err) } From fc94c65b662d2acf8525a2cb2b7d4d46ebe62d74 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:45:33 -0400 Subject: [PATCH 12/45] controltower: remove use of `errs.Must` --- internal/service/controltower/control.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index 0559852690c..64169e4058d 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -108,7 +108,11 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int controlIdentifier := d.Get("control_identifier").(string) targetIdentifier := d.Get("target_identifier").(string) - id := errs.Must(flex.FlattenResourceId([]string{targetIdentifier, controlIdentifier}, controlResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{targetIdentifier, controlIdentifier}, controlResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating ControlTower Control (%s): %s", id, err) + } + input := &controltower.EnableControlInput{ ControlIdentifier: aws.String(controlIdentifier), TargetIdentifier: aws.String(targetIdentifier), From cbc3e98ae1252c47069918f9a054e87ef35c444c Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:45:07 -0400 Subject: [PATCH 13/45] dynamodb: remove use of `errs.Must` --- .../service/dynamodb/kinesis_streaming_destination.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/service/dynamodb/kinesis_streaming_destination.go b/internal/service/dynamodb/kinesis_streaming_destination.go index c2577e6a438..897c37800b5 100644 --- a/internal/service/dynamodb/kinesis_streaming_destination.go +++ b/internal/service/dynamodb/kinesis_streaming_destination.go @@ -63,15 +63,17 @@ func resourceKinesisStreamingDestinationCreate(ctx context.Context, d *schema.Re streamARN := d.Get(names.AttrStreamARN).(string) tableName := d.Get(names.AttrTableName).(string) - id := errs.Must(flex.FlattenResourceId([]string{tableName, streamARN}, kinesisStreamingDestinationResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{tableName, streamARN}, kinesisStreamingDestinationResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "enabling DynamoDB Kinesis Streaming Destination (%s): %s", id, err) + } + input := &dynamodb.EnableKinesisStreamingDestinationInput{ StreamArn: aws.String(streamARN), TableName: aws.String(tableName), } - _, err := conn.EnableKinesisStreamingDestination(ctx, input) - - if err != nil { + if _, err := conn.EnableKinesisStreamingDestination(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "enabling DynamoDB Kinesis Streaming Destination (%s): %s", id, err) } From ab1022ccc094f0e209138a815ae5a9c8ae874955 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:45:54 -0400 Subject: [PATCH 14/45] ec2: remove use of `errs.Must` --- .../service/ec2/ebs_fast_snapshot_restore.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/service/ec2/ebs_fast_snapshot_restore.go b/internal/service/ec2/ebs_fast_snapshot_restore.go index fd9f32c9ddf..683f1a30c63 100644 --- a/internal/service/ec2/ebs_fast_snapshot_restore.go +++ b/internal/service/ec2/ebs_fast_snapshot_restore.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -103,7 +102,12 @@ func (r *ebsFastSnapshotRestoreResource) Create(ctx context.Context, request res } // Set values for unknowns. - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating EC2 EBS Fast Snapshot Restore", err.Error()) + return + } + data.ID = types.StringValue(id) v, err := waitFastSnapshotRestoreCreated(ctx, conn, availabilityZone, snapshotID, r.CreateTimeout(ctx, data.Timeouts)) @@ -208,6 +212,11 @@ func (data *ebsFastSnapshotRestoreResourceModel) InitFromID() error { return nil } -func (data *ebsFastSnapshotRestoreResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.AvailabilityZone.ValueString(), data.SnapshotID.ValueString()}, ebsFastSnapshotRestoreIDPartCount, false))) +func (data *ebsFastSnapshotRestoreResourceModel) setID() (string, error) { + parts := []string{ + data.AvailabilityZone.ValueString(), + data.SnapshotID.ValueString(), + } + + return flex.FlattenResourceId(parts, ebsFastSnapshotRestoreIDPartCount, false) } From 14770dd8a48c254dc5ba5080943900a27a076d85 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:46:08 -0400 Subject: [PATCH 15/45] elasticache: remove use of `errs.Must` --- .../service/elasticache/user_group_association.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/service/elasticache/user_group_association.go b/internal/service/elasticache/user_group_association.go index 2f1827ef5d2..5fd12eea6a9 100644 --- a/internal/service/elasticache/user_group_association.go +++ b/internal/service/elasticache/user_group_association.go @@ -62,17 +62,18 @@ func resourceUserGroupAssociationCreate(ctx context.Context, d *schema.ResourceD userGroupID := d.Get("user_group_id").(string) userID := d.Get("user_id").(string) - id := errs.Must(flex.FlattenResourceId([]string{userGroupID, userID}, userGroupAssociationResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{userGroupID, userID}, userGroupAssociationResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating ElastiCache User Group Association (%s): %s", id, err) + } input := &elasticache.ModifyUserGroupInput{ UserGroupId: aws.String(userGroupID), UserIdsToAdd: []string{userID}, } - _, err := tfresource.RetryWhenIsA[*awstypes.InvalidUserGroupStateFault](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { + if _, err := tfresource.RetryWhenIsA[*awstypes.InvalidUserGroupStateFault](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { return conn.ModifyUserGroup(ctx, input) - }) - - if err != nil { + }); err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache User Group Association (%s): %s", id, err) } From 6cbcd24e1acf36e62bc856c62a9a4953f824ebfc Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:46:22 -0400 Subject: [PATCH 16/45] elbv2: remove use of `errs.Must` --- internal/service/elbv2/trust_store_revocation.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/service/elbv2/trust_store_revocation.go b/internal/service/elbv2/trust_store_revocation.go index cdf71927697..550a442ca47 100644 --- a/internal/service/elbv2/trust_store_revocation.go +++ b/internal/service/elbv2/trust_store_revocation.go @@ -102,7 +102,10 @@ func resourceTrustStoreRevocationCreate(ctx context.Context, d *schema.ResourceD } revocationID := aws.ToInt64(output.TrustStoreRevocations[0].RevocationId) - id := errs.Must(flex.FlattenResourceId([]string{trustStoreARN, strconv.FormatInt(revocationID, 10)}, trustStoreRevocationResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{trustStoreARN, strconv.FormatInt(revocationID, 10)}, trustStoreRevocationResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating ELBv2 Trust Store (%s) Revocation (s3://%s/%s): %s", trustStoreARN, s3Bucket, s3Key, err) + } d.SetId(id) @@ -127,7 +130,11 @@ func resourceTrustStoreRevocationRead(ctx context.Context, d *schema.ResourceDat } trustStoreARN := parts[0] - revocationID := errs.Must(strconv.ParseInt(parts[1], 10, 64)) + revocationID, err := strconv.ParseInt(parts[1], 10, 64) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading ELBv2 Trust Store Revocation (%s): %s", d.Id(), err) + } + revocation, err := findTrustStoreRevocationByTwoPartKey(ctx, conn, trustStoreARN, revocationID) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -156,7 +163,10 @@ func resourceTrustStoreRevocationDelete(ctx context.Context, d *schema.ResourceD } trustStoreARN := parts[0] - revocationID := errs.Must(strconv.ParseInt(parts[1], 10, 64)) + revocationID, err := strconv.ParseInt(parts[1], 10, 64) + if err != nil { + return sdkdiag.AppendErrorf(diags, "deleting ELBv2 Trust Store Revocation (%s): %s", d.Id(), err) + } log.Printf("[DEBUG] Deleting ELBv2 Trust Store Revocation: %s", d.Id()) _, err = conn.RemoveTrustStoreRevocations(ctx, &elasticloadbalancingv2.RemoveTrustStoreRevocationsInput{ From 7a2896d5cb2a957303e0ae13848cbed182613884 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:46:31 -0400 Subject: [PATCH 17/45] fms: remove use of `errs.Must` --- internal/service/fms/sweep.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/fms/sweep.go b/internal/service/fms/sweep.go index ec9fda9b3af..73e84e07757 100644 --- a/internal/service/fms/sweep.go +++ b/internal/service/fms/sweep.go @@ -1,4 +1,4 @@ -// Copyright (c) HashiCorp, Inc. +// Copyright (c) HashiCorp, Inc.fms/sweep // SPDX-License-Identifier: MPL-2.0 package fms @@ -103,7 +103,7 @@ func (aas adminAccountSweeper) Delete(ctx context.Context, timeout time.Duration }) return nil } - if err != nil && errs.Must(regexp.MatchString(`InvalidOperationException: This operation is not supported in the '[-a-z0-9]+' region`, err.Error())) { + if err != nil && errs.Must(regexp.MatchString(`InvalidOperationException: This operation is not supported in the '[-a-z0-9]+' region`, err.Error())) { // nosemgrep: ci.avoid-errs-Must tflog.Warn(ctx, "Skipping resource", map[string]any{ "attr.account_id": aas.d.Get(names.AttrAccountID), "error": err.Error(), From 9b867535cf67ef1ce62713267441a92a6b9b8b42 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:46:56 -0400 Subject: [PATCH 18/45] grafana: remove use of `errs.Must` --- .../grafana/workspace_service_account.go | 23 ++++++++++++++---- .../workspace_service_account_token.go | 24 +++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/internal/service/grafana/workspace_service_account.go b/internal/service/grafana/workspace_service_account.go index 56941d5153e..81a75ed087a 100644 --- a/internal/service/grafana/workspace_service_account.go +++ b/internal/service/grafana/workspace_service_account.go @@ -102,7 +102,12 @@ func (r *workspaceServiceAccountResource) Create(ctx context.Context, request re // Set values for unknowns. data.ServiceAccountID = fwflex.StringToFramework(ctx, output.Id) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating Grafana Workspace Service Account (%s)", name), err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -145,7 +150,12 @@ func (r *workspaceServiceAccountResource) Read(ctx context.Context, request reso // Restore resource ID. // It has been overwritten by the 'Id' field from the API response. - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading Grafana Workspace Service Account (%s)", id), err.Error()) + return + } + data.ID = types.StringValue(id) // Role is returned from the API in lowercase. data.GrafanaRole = fwtypes.StringEnumValueToUpper(output.GrafanaRole) @@ -254,6 +264,11 @@ func (data *workspaceServiceAccountResourceModel) InitFromID() error { return nil } -func (data *workspaceServiceAccountResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.WorkspaceID.ValueString(), data.ServiceAccountID.ValueString()}, workspaceServiceAccountResourceIDPartCount, false))) +func (data *workspaceServiceAccountResourceModel) setID() (string, error) { + parts := []string{ + data.WorkspaceID.ValueString(), + data.ServiceAccountID.ValueString(), + } + + return flex.FlattenResourceId(parts, workspaceServiceAccountResourceIDPartCount, false) } diff --git a/internal/service/grafana/workspace_service_account_token.go b/internal/service/grafana/workspace_service_account_token.go index 0673cf313e1..32880a2597f 100644 --- a/internal/service/grafana/workspace_service_account_token.go +++ b/internal/service/grafana/workspace_service_account_token.go @@ -133,7 +133,12 @@ func (r *workspaceServiceAccountTokenResource) Create(ctx context.Context, reque // Set values for unknowns. data.Key = fwflex.StringToFramework(ctx, output.ServiceAccountToken.Key) data.TokenID = fwflex.StringToFramework(ctx, output.ServiceAccountToken.Id) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("setting resource ID", err.Error()) + return + } + data.ID = types.StringValue(id) serviceAccountToken, err := findWorkspaceServiceAccountTokenByThreePartKey(ctx, conn, data.WorkspaceID.ValueString(), data.ServiceAccountID.ValueString(), data.TokenID.ValueString()) @@ -187,7 +192,12 @@ func (r *workspaceServiceAccountTokenResource) Read(ctx context.Context, request // Restore resource ID. // It has been overwritten by the 'Id' field from the API response. - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("setting resource ID", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -300,6 +310,12 @@ func (data *workspaceServiceAccountTokenResourceModel) InitFromID() error { return nil } -func (data *workspaceServiceAccountTokenResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.WorkspaceID.ValueString(), data.ServiceAccountID.ValueString(), data.TokenID.ValueString()}, workspaceServiceAccountTokenResourceIDPartCount, false))) +func (data *workspaceServiceAccountTokenResourceModel) setID() (string, error) { + parts := []string{ + data.WorkspaceID.ValueString(), + data.ServiceAccountID.ValueString(), + data.TokenID.ValueString(), + } + + return flex.FlattenResourceId(parts, workspaceServiceAccountTokenResourceIDPartCount, false) } From d4a7d977f33a28cba8092deb98d31b4dc6547360 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:47:18 -0400 Subject: [PATCH 19/45] lambda: remove use of `errs.Must` --- internal/service/lambda/layer_version_permission.go | 9 +++++---- .../service/lambda/provisioned_concurrency_config.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/service/lambda/layer_version_permission.go b/internal/service/lambda/layer_version_permission.go index 4741fb9ca95..1486d436a4c 100644 --- a/internal/service/lambda/layer_version_permission.go +++ b/internal/service/lambda/layer_version_permission.go @@ -102,7 +102,10 @@ func resourceLayerVersionPermissionCreate(ctx context.Context, d *schema.Resourc layerName := d.Get("layer_name").(string) versionNumber := d.Get("version_number").(int) - id := errs.Must(flex.FlattenResourceId([]string{layerName, strconv.FormatInt(int64(versionNumber), 10)}, layerVersionPermissionResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{layerName, strconv.FormatInt(int64(versionNumber), 10)}, layerVersionPermissionResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "adding Lambda Layer Version Permission (%s): %s", id, err) + } input := &lambda.AddLayerVersionPermissionInput{ Action: aws.String(d.Get(names.AttrAction).(string)), LayerName: aws.String(layerName), @@ -115,9 +118,7 @@ func resourceLayerVersionPermissionCreate(ctx context.Context, d *schema.Resourc input.OrganizationId = aws.String(v.(string)) } - _, err := conn.AddLayerVersionPermission(ctx, input) - - if err != nil { + if _, err := conn.AddLayerVersionPermission(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "adding Lambda Layer Version Permission (%s): %s", id, err) } diff --git a/internal/service/lambda/provisioned_concurrency_config.go b/internal/service/lambda/provisioned_concurrency_config.go index f60ea3fbfaa..f02cb0ee809 100644 --- a/internal/service/lambda/provisioned_concurrency_config.go +++ b/internal/service/lambda/provisioned_concurrency_config.go @@ -88,16 +88,17 @@ func resourceProvisionedConcurrencyConfigCreate(ctx context.Context, d *schema.R functionName := d.Get("function_name").(string) qualifier := d.Get("qualifier").(string) - id := errs.Must(flex.FlattenResourceId([]string{functionName, qualifier}, provisionedConcurrencyConfigResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{functionName, qualifier}, provisionedConcurrencyConfigResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating Lambda Provisioned Concurrency Config (%s): %s", id, err) + } input := &lambda.PutProvisionedConcurrencyConfigInput{ FunctionName: aws.String(functionName), ProvisionedConcurrentExecutions: aws.Int32(int32(d.Get("provisioned_concurrent_executions").(int))), Qualifier: aws.String(qualifier), } - _, err := conn.PutProvisionedConcurrencyConfig(ctx, input) - - if err != nil { + if _, err := conn.PutProvisionedConcurrencyConfig(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "creating Lambda Provisioned Concurrency Config (%s): %s", id, err) } From 43d883e6f4796ecc1aad4dac5b3ee1f463a63858 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:48:16 -0400 Subject: [PATCH 20/45] lexv2models: remove use of `errs.Must` --- internal/service/lexv2models/intent_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/lexv2models/intent_test.go b/internal/service/lexv2models/intent_test.go index 6848d1e9f7d..baadd51978f 100644 --- a/internal/service/lexv2models/intent_test.go +++ b/internal/service/lexv2models/intent_test.go @@ -647,7 +647,7 @@ func TestIntentAutoFlex(t *testing.T) { } testTimeStr := "2023-12-08T09:34:01Z" - testTimeTime := errs.Must(time.Parse(time.RFC3339, testTimeStr)) + testTimeTime := errs.Must(time.Parse(time.RFC3339, testTimeStr)) // nosemgrep: ci.avoid-errs-Must intentDescribeTF := tflexv2models.ResourceIntentData{ BotID: types.StringValue(testString), From 1f6bba83c753fd8921cfa5e629f12e546d33d9cf Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:48:04 -0400 Subject: [PATCH 21/45] m2: remove use of `errs.Must` --- internal/service/m2/deployment.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/service/m2/deployment.go b/internal/service/m2/deployment.go index 8eb29695ee6..5543df89c70 100644 --- a/internal/service/m2/deployment.go +++ b/internal/service/m2/deployment.go @@ -118,7 +118,12 @@ func (r *deploymentResource) Create(ctx context.Context, request resource.Create // Set values for unknowns. data.DeploymentID = fwflex.StringToFramework(ctx, output.DeploymentId) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating Mainframe Modernization Deployment", err.Error()) + return + } + data.ID = types.StringValue(id) timeout := r.CreateTimeout(ctx, data.Timeouts) if _, err := waitDeploymentCreated(ctx, conn, data.ApplicationID.ValueString(), data.DeploymentID.ValueString(), timeout); err != nil { @@ -233,7 +238,12 @@ func (r *deploymentResource) Update(ctx context.Context, request resource.Update // Set values for unknowns. new.DeploymentID = fwflex.StringToFramework(ctx, output.DeploymentId) - new.setID() + id, err := new.setID() + if err != nil { + response.Diagnostics.AddError("creating Mainframe Modernization Deployment", err.Error()) + return + } + new.ID = types.StringValue(id) if _, err := waitDeploymentUpdated(ctx, conn, new.ApplicationID.ValueString(), new.DeploymentID.ValueString(), timeout); err != nil { response.Diagnostics.AddError(fmt.Sprintf("waiting for Mainframe Modernization Deployment (%s) update", new.ID.ValueString()), err.Error()) @@ -443,6 +453,11 @@ func (data *deploymentResourceModel) InitFromID() error { return nil } -func (data *deploymentResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.ApplicationID.ValueString(), data.DeploymentID.ValueString()}, deploymentResourceIDPartCount, false))) +func (data *deploymentResourceModel) setID() (string, error) { + parts := []string{ + data.ApplicationID.ValueString(), + data.DeploymentID.ValueString(), + } + + return flex.FlattenResourceId(parts, deploymentResourceIDPartCount, false) } From a756de2c46377e1e5dad4223ae404f64cc5488c2 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:48:37 -0400 Subject: [PATCH 22/45] networkmonitor: remove use of `errs.Must` --- internal/service/networkmonitor/probe.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/service/networkmonitor/probe.go b/internal/service/networkmonitor/probe.go index e07e500122d..8fefba9ca3e 100644 --- a/internal/service/networkmonitor/probe.go +++ b/internal/service/networkmonitor/probe.go @@ -153,7 +153,12 @@ func (r *probeResource) Create(ctx context.Context, request resource.CreateReque // Set values for unknowns. data.ProbeARN = fwflex.StringToFramework(ctx, outputCP.ProbeArn) data.ProbeID = fwflex.StringToFramework(ctx, outputCP.ProbeId) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating CloudWatch Network Monitor Probe (%s)", err.Error()) + return + } + data.ID = types.StringValue(id) outputGP, err := waitProbeReady(ctx, conn, data.MonitorName.ValueString(), data.ProbeID.ValueString()) @@ -427,6 +432,11 @@ func (m *probeResourceModel) InitFromID() error { return nil } -func (m *probeResourceModel) setID() { - m.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{m.MonitorName.ValueString(), m.ProbeID.ValueString()}, probeResourceIDPartCount, false))) +func (m *probeResourceModel) setID() (string, error) { + parts := []string{ + m.MonitorName.ValueString(), + m.ProbeID.ValueString(), + } + + return flex.FlattenResourceId(parts, probeResourceIDPartCount, false) } From b8c96600cbea097dce3529567b14d1d9ac986076 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:48:57 -0400 Subject: [PATCH 23/45] ram: remove use of `errs.Must` --- internal/service/ram/principal_association.go | 8 ++++++-- internal/service/ram/resource_association.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index c2359037530..a014f0313fc 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -72,8 +72,12 @@ func resourcePrincipalAssociationCreate(ctx context.Context, d *schema.ResourceD conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceShareARN, principal := d.Get("resource_share_arn").(string), d.Get(names.AttrPrincipal).(string) - id := errs.Must(flex.FlattenResourceId([]string{resourceShareARN, principal}, principalAssociationResourceIDPartCount, false)) - _, err := findPrincipalAssociationByTwoPartKey(ctx, conn, resourceShareARN, principal) + id, err := flex.FlattenResourceId([]string{resourceShareARN, principal}, principalAssociationResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating RAM Principal Association (%s): %s", id, err) + } + + _, err = findPrincipalAssociationByTwoPartKey(ctx, conn, resourceShareARN, principal) switch { case err == nil: diff --git a/internal/service/ram/resource_association.go b/internal/service/ram/resource_association.go index 69e42c317c4..083ec2daca9 100644 --- a/internal/service/ram/resource_association.go +++ b/internal/service/ram/resource_association.go @@ -64,8 +64,12 @@ func resourceResourceAssociationCreate(ctx context.Context, d *schema.ResourceDa conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceShareARN, resourceARN := d.Get("resource_share_arn").(string), d.Get(names.AttrResourceARN).(string) - id := errs.Must(flex.FlattenResourceId([]string{resourceShareARN, resourceARN}, resourceAssociationResourceIDPartCount, false)) - _, err := findResourceAssociationByTwoPartKey(ctx, conn, resourceShareARN, resourceARN) + id, err := flex.FlattenResourceId([]string{resourceShareARN, resourceARN}, resourceAssociationResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating RAM Resource Association (%s): %s", id, err) + } + + _, err = findResourceAssociationByTwoPartKey(ctx, conn, resourceShareARN, resourceARN) switch { case err == nil: From 9aa74dcc612d876d79696e3c50562559e8b13286 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:49:12 -0400 Subject: [PATCH 24/45] redshiftserverless: remove use of `errs.Must` --- .../custom_domain_association.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/service/redshiftserverless/custom_domain_association.go b/internal/service/redshiftserverless/custom_domain_association.go index 6d1006b5420..0b8d5a7715d 100644 --- a/internal/service/redshiftserverless/custom_domain_association.go +++ b/internal/service/redshiftserverless/custom_domain_association.go @@ -107,7 +107,12 @@ func (r *customDomainAssociationResource) Create(ctx context.Context, request re // Set values for unknowns. data.CustomDomainCertificateExpiryTime = timetypes.NewRFC3339TimePointerValue(output.CustomDomainCertificateExpiryTime) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating Redshift Serverless Custom Domain Association", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -260,6 +265,11 @@ func (data *customDomainAssociationResourceModel) InitFromID() error { return nil } -func (data *customDomainAssociationResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.WorkgroupName.ValueString(), data.CustomDomainName.ValueString()}, customDomainAssociationResourceIDPartCount, false))) +func (data *customDomainAssociationResourceModel) setID() (string, error) { + parts := []string{ + data.WorkgroupName.ValueString(), + data.CustomDomainName.ValueString(), + } + + return flex.FlattenResourceId(parts, customDomainAssociationResourceIDPartCount, false) } From a1b5fa73884ac6932bf9a2a5f1f01f5dd8bf9256 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:49:42 -0400 Subject: [PATCH 25/45] route53: remove use of `errs.Must` --- internal/service/route53/cidr_location.go | 16 +++++++++++++--- internal/service/route53/key_signing_key.go | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/service/route53/cidr_location.go b/internal/service/route53/cidr_location.go index c70bf07548d..c2e77dadb96 100644 --- a/internal/service/route53/cidr_location.go +++ b/internal/service/route53/cidr_location.go @@ -113,7 +113,12 @@ func (r *cidrLocationResource) Create(ctx context.Context, request resource.Crea return } - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating Route 53 CIDR Location (%s)", name), err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -302,8 +307,13 @@ func (data *cidrLocationResourceModel) InitFromID() error { return nil } -func (data *cidrLocationResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.CIDRCollectionID.ValueString(), data.Name.ValueString()}, cidrLocationResourceIDPartCount, false))) +func (data *cidrLocationResourceModel) setID() (string, error) { + parts := []string{ + data.CIDRCollectionID.ValueString(), + data.Name.ValueString(), + } + + return flex.FlattenResourceId(parts, cidrLocationResourceIDPartCount, false) } func findCIDRLocationByTwoPartKey(ctx context.Context, conn *route53.Client, collectionID, locationName string) ([]string, error) { diff --git a/internal/service/route53/key_signing_key.go b/internal/service/route53/key_signing_key.go index 403a070a10f..de240e02faf 100644 --- a/internal/service/route53/key_signing_key.go +++ b/internal/service/route53/key_signing_key.go @@ -131,7 +131,10 @@ func resourceKeySigningKeyCreate(ctx context.Context, d *schema.ResourceData, me hostedZoneID := d.Get(names.AttrHostedZoneID).(string) name := d.Get(names.AttrName).(string) status := d.Get(names.AttrStatus).(string) - id := errs.Must(flex.FlattenResourceId([]string{hostedZoneID, name}, keySigningKeyResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{hostedZoneID, name}, keySigningKeyResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating Route 53 Key Signing Key (%s): %s", id, err) + } input := &route53.CreateKeySigningKeyInput{ CallerReference: aws.String(sdkid.UniqueId()), HostedZoneId: aws.String(hostedZoneID), From 3ef58c7fcfbaf984c562449395190f96058d8665 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:49:53 -0400 Subject: [PATCH 26/45] route53domains: remove use of `errs.Must` --- .../route53domains/delegation_signer_record.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/service/route53domains/delegation_signer_record.go b/internal/service/route53domains/delegation_signer_record.go index e4d041610ff..11f84cdfb04 100644 --- a/internal/service/route53domains/delegation_signer_record.go +++ b/internal/service/route53domains/delegation_signer_record.go @@ -149,7 +149,12 @@ func (r *delegationSignerRecordResource) Create(ctx context.Context, request res // Set values for unknowns. data.DNSSECKeyID = fwflex.StringToFramework(ctx, dnssecKey.Id) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("flattening resource ID Route 53 Domains Domain (%s) DNSSEC key", data.DomainName.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -257,6 +262,11 @@ func (data *delegationSignerRecordResourceModel) InitFromID() error { return nil } -func (data *delegationSignerRecordResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.DomainName.ValueString(), data.DNSSECKeyID.ValueString()}, delegationSignerRecordResourceIDPartCount, false))) +func (data *delegationSignerRecordResourceModel) setID() (string, error) { + parts := []string{ + data.DomainName.ValueString(), + data.DNSSECKeyID.ValueString(), + } + + return flex.FlattenResourceId(parts, delegationSignerRecordResourceIDPartCount, false) } From 20c89855ee3094f5e07c4f46850127302c1705e5 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:50:22 -0400 Subject: [PATCH 27/45] s3control: remove use of `errs.Must` --- internal/service/s3control/access_grant.go | 17 +++++++++++++---- .../service/s3control/access_grants_location.go | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/internal/service/s3control/access_grant.go b/internal/service/s3control/access_grant.go index ce4d1a042d3..6bd3274a3fa 100644 --- a/internal/service/s3control/access_grant.go +++ b/internal/service/s3control/access_grant.go @@ -21,7 +21,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -194,7 +193,12 @@ func (r *accessGrantResource) Create(ctx context.Context, request resource.Creat data.AccessGrantARN = fwflex.StringToFramework(ctx, output.AccessGrantArn) data.AccessGrantID = fwflex.StringToFramework(ctx, output.AccessGrantId) data.GrantScope = fwflex.StringToFramework(ctx, output.GrantScope) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating S3 Access Grant", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -381,8 +385,13 @@ func (data *accessGrantResourceModel) InitFromID() error { return nil } -func (data *accessGrantResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.AccountID.ValueString(), data.AccessGrantID.ValueString()}, accessGrantResourceIDPartCount, false))) +func (data *accessGrantResourceModel) setID() (string, error) { + parts := []string{ + data.AccountID.ValueString(), + data.AccessGrantID.ValueString(), + } + + return flex.FlattenResourceId(parts, accessGrantResourceIDPartCount, false) } // API returns . diff --git a/internal/service/s3control/access_grants_location.go b/internal/service/s3control/access_grants_location.go index ca060273a12..9443dfb0910 100644 --- a/internal/service/s3control/access_grants_location.go +++ b/internal/service/s3control/access_grants_location.go @@ -18,7 +18,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -125,7 +124,12 @@ func (r *accessGrantsLocationResource) Create(ctx context.Context, request resou output := outputRaw.(*s3control.CreateAccessGrantsLocationOutput) data.AccessGrantsLocationARN = fwflex.StringToFramework(ctx, output.AccessGrantsLocationArn) data.AccessGrantsLocationID = fwflex.StringToFramework(ctx, output.AccessGrantsLocationId) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("creating S3 Access Grants Location (%s)", data.LocationScope.ValueString()), err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -318,6 +322,11 @@ func (data *accessGrantsLocationResourceModel) InitFromID() error { return nil } -func (data *accessGrantsLocationResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.AccountID.ValueString(), data.AccessGrantsLocationID.ValueString()}, accessGrantsLocationResourceIDPartCount, false))) +func (data *accessGrantsLocationResourceModel) setID() (string, error) { + parts := []string{ + data.AccountID.ValueString(), + data.AccessGrantsLocationID.ValueString(), + } + + return flex.FlattenResourceId(parts, accessGrantsLocationResourceIDPartCount, false) } From 8568616b86b2535f4278ea7f53b7606f2c731860 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:50:49 -0400 Subject: [PATCH 28/45] securityhub: remove use of `errs.Must` --- internal/service/securityhub/product_subscription.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/service/securityhub/product_subscription.go b/internal/service/securityhub/product_subscription.go index d8006ab8334..269eff521a0 100644 --- a/internal/service/securityhub/product_subscription.go +++ b/internal/service/securityhub/product_subscription.go @@ -14,7 +14,6 @@ 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" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -68,7 +67,11 @@ func resourceProductSubscriptionCreate(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "enabling Security Hub Product Subscription (%s): %s", productARN, err) } - d.SetId(errs.Must(flex.FlattenResourceId([]string{productARN, aws.ToString(output.ProductSubscriptionArn)}, productSubscriptionResourceIDPartCount, false))) + id, err := flex.FlattenResourceId([]string{productARN, aws.ToString(output.ProductSubscriptionArn)}, productSubscriptionResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "enabling Security Hub Product Subscription (%s): %s", productARN, err) + } + d.SetId(id) return append(diags, resourceProductSubscriptionRead(ctx, d, meta)...) } From 9e08d8d008d5742b850997e931ce8b2db7679775 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:51:08 -0400 Subject: [PATCH 29/45] securitylake: remove use of `errs.Must` --- internal/service/securitylake/data_lake.go | 16 ++++++++--- .../securitylake/subscriber_notification.go | 27 +++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/internal/service/securitylake/data_lake.go b/internal/service/securitylake/data_lake.go index 3965c8aff97..2a36dacdc97 100644 --- a/internal/service/securitylake/data_lake.go +++ b/internal/service/securitylake/data_lake.go @@ -327,12 +327,17 @@ func (r *dataLakeResource) Delete(ctx context.Context, request resource.DeleteRe } conn := r.Meta().SecurityLakeClient(ctx) + region, err := regionFromARNString(data.ID.ValueString()) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("deleting Security Lake Data Lake (%s)", data.ID.ValueString()), err.Error()) + return + } input := &securitylake.DeleteDataLakeInput{ - Regions: []string{errs.Must(regionFromARNString(data.ID.ValueString()))}, + Regions: []string{region}, } - _, err := retryDataLakeConflictWithMutex(ctx, func() (*securitylake.DeleteDataLakeOutput, error) { + _, err = retryDataLakeConflictWithMutex(ctx, func() (*securitylake.DeleteDataLakeOutput, error) { return conn.DeleteDataLake(ctx, input) }) @@ -362,8 +367,13 @@ func (r *dataLakeResource) ModifyPlan(ctx context.Context, req resource.ModifyPl } func findDataLakeByARN(ctx context.Context, conn *securitylake.Client, arn string) (*awstypes.DataLakeResource, error) { + region, err := regionFromARNString(arn) + if err != nil { + return nil, err + } + input := &securitylake.ListDataLakesInput{ - Regions: []string{errs.Must(regionFromARNString(arn))}, + Regions: []string{region}, } return findDataLake(ctx, conn, input, func(v *awstypes.DataLakeResource) bool { diff --git a/internal/service/securitylake/subscriber_notification.go b/internal/service/securitylake/subscriber_notification.go index baccf539e54..14c7f045c91 100644 --- a/internal/service/securitylake/subscriber_notification.go +++ b/internal/service/securitylake/subscriber_notification.go @@ -23,7 +23,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/create" - "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" @@ -152,7 +151,12 @@ func (r *subscriberNotificationResource) Create(ctx context.Context, request res // Set values for unknowns. data.EndpointID = fwflex.StringToFramework(ctx, output.SubscriberEndpoint) data.SubscriberEndpoint = fwflex.StringToFramework(ctx, output.SubscriberEndpoint) - data.setID() + id, err := data.setID() + if err != nil { + response.Diagnostics.AddError("creating Security Lake Subscriber Notification", err.Error()) + return + } + data.ID = types.StringValue(id) response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -241,7 +245,15 @@ func (r *subscriberNotificationResource) Update(ctx context.Context, request res new.EndpointID = fwflex.StringToFramework(ctx, output.SubscriberEndpoint) new.SubscriberEndpoint = fwflex.StringToFramework(ctx, output.SubscriberEndpoint) - new.setID() + id, err := new.setID() + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.SecurityLake, create.ErrActionUpdating, ResNameSubscriberNotification, new.ID.String(), err), + err.Error(), + ) + return + } + new.ID = types.StringValue(id) } response.Diagnostics.Append(response.State.Set(ctx, &new)...) @@ -366,8 +378,13 @@ func (data *subscriberNotificationResourceModel) initFromID() error { return nil } -func (data *subscriberNotificationResourceModel) setID() { - data.ID = types.StringValue(errs.Must(flex.FlattenResourceId([]string{data.SubscriberID.ValueString(), "notification"}, subscriberNotificationIdPartCount, false))) +func (data *subscriberNotificationResourceModel) setID() (string, error) { + parts := []string{ + data.SubscriberID.ValueString(), + "notification", + } + + return flex.FlattenResourceId(parts, subscriberNotificationIdPartCount, false) } func refreshConfiguration(ctx context.Context, config fwtypes.ListNestedObjectValueOf[subscriberNotificationResourceConfigurationModel], subscriber *awstypes.SubscriberResource, diags *diag.Diagnostics) fwtypes.ListNestedObjectValueOf[subscriberNotificationResourceConfigurationModel] { From f02599e6a8689bf4be417dca627fca947f8d7efa Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:51:20 -0400 Subject: [PATCH 30/45] ssm: remove use of `errs.Must` --- internal/service/ssm/patch_group.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/service/ssm/patch_group.go b/internal/service/ssm/patch_group.go index 78c7c5d3e66..72c76472ab5 100644 --- a/internal/service/ssm/patch_group.go +++ b/internal/service/ssm/patch_group.go @@ -61,15 +61,16 @@ func resourcePatchGroupCreate(ctx context.Context, d *schema.ResourceData, meta baselineID := d.Get("baseline_id").(string) patchGroup := d.Get("patch_group").(string) - id := errs.Must(flex.FlattenResourceId([]string{patchGroup, baselineID}, patchGroupResourceIDPartCount, false)) + id, err := flex.FlattenResourceId([]string{patchGroup, baselineID}, patchGroupResourceIDPartCount, false) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating SSM Patch Group (%s): %s", id, err) + } input := &ssm.RegisterPatchBaselineForPatchGroupInput{ BaselineId: aws.String(baselineID), PatchGroup: aws.String(patchGroup), } - _, err := conn.RegisterPatchBaselineForPatchGroup(ctx, input) - - if err != nil { + if _, err := conn.RegisterPatchBaselineForPatchGroup(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "creating SSM Patch Group (%s): %s", id, err) } From f76139ca74c262f8c342cef649256b86ff355156 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 23 Sep 2024 16:51:56 -0400 Subject: [PATCH 31/45] wafv2: remove use of `errs.Must` --- internal/service/wafv2/web_acl_association.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/service/wafv2/web_acl_association.go b/internal/service/wafv2/web_acl_association.go index cfcd5e75f5e..f32ee91d224 100644 --- a/internal/service/wafv2/web_acl_association.go +++ b/internal/service/wafv2/web_acl_association.go @@ -67,18 +67,20 @@ func resourceWebACLAssociationCreate(ctx context.Context, d *schema.ResourceData webACLARN := d.Get("web_acl_arn").(string) resourceARN := d.Get(names.AttrResourceARN).(string) - id := errs.Must(flex.FlattenResourceId([]string{webACLARN, resourceARN}, webACLAssociationResourceIDPartCount, true)) + id, err := flex.FlattenResourceId([]string{webACLARN, resourceARN}, webACLAssociationResourceIDPartCount, true) + if err != nil { + return sdkdiag.AppendErrorf(diags, "creating WAFv2 WebACL Association (%s): %s", id, err) + } + input := &wafv2.AssociateWebACLInput{ ResourceArn: aws.String(resourceARN), WebACLArn: aws.String(webACLARN), } log.Printf("[INFO] Creating WAFv2 WebACL Association: %s", d.Id()) - _, err := tfresource.RetryWhenIsA[*awstypes.WAFUnavailableEntityException](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { + if _, err = tfresource.RetryWhenIsA[*awstypes.WAFUnavailableEntityException](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { return conn.AssociateWebACL(ctx, input) - }) - - if err != nil { + }); err != nil { return sdkdiag.AppendErrorf(diags, "creating WAFv2 WebACL Association (%s): %s", id, err) } From 27f6e6b9e2f6da0084a183cdd2f8ce3d6955041f Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:03:52 -0400 Subject: [PATCH 32/45] account: omit `id` from error if `FlattenResourceId` fails --- internal/service/account/region.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/service/account/region.go b/internal/service/account/region.go index 7003d8afd70..622b2f3a902 100644 --- a/internal/service/account/region.go +++ b/internal/service/account/region.go @@ -73,13 +73,14 @@ func resourceRegionUpdate(ctx context.Context, d *schema.ResourceData, meta inte conn := meta.(*conns.AWSClient).AccountClient(ctx) var id string + var err error region := d.Get("region_name").(string) accountID := "" if v, ok := d.GetOk(names.AttrAccountID); ok { accountID = v.(string) - id, err := flex.FlattenResourceId([]string{accountID, region}, regionResourceIDPartCount, false) + id, err = flex.FlattenResourceId([]string{accountID, region}, regionResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "enabling Account Region (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } } else { id = region From 478750e0483b5a8aeaf3020ac7df55282b4f7853 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:19 -0400 Subject: [PATCH 33/45] acmpca: omit `id` from error if `FlattenResourceId` fails --- internal/service/acmpca/permission.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/acmpca/permission.go b/internal/service/acmpca/permission.go index 2b9e99fc585..8b665ebec40 100644 --- a/internal/service/acmpca/permission.go +++ b/internal/service/acmpca/permission.go @@ -83,7 +83,7 @@ func resourcePermissionCreate(ctx context.Context, d *schema.ResourceData, meta sourceAccount := d.Get("source_account").(string) id, err := flex.FlattenResourceId([]string{caARN, principal, sourceAccount}, permissionResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating ACM PCA Permission (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &acmpca.CreatePermissionInput{ From f92a3c208a459c1000cc1d7dc6ee80cc25ffc6f2 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:19 -0400 Subject: [PATCH 34/45] cognitoidp: omit `id` from error if `FlattenResourceId` fails --- internal/service/cognitoidp/user_pool_ui_customization.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/cognitoidp/user_pool_ui_customization.go b/internal/service/cognitoidp/user_pool_ui_customization.go index f51e93fad30..3dd813a602e 100644 --- a/internal/service/cognitoidp/user_pool_ui_customization.go +++ b/internal/service/cognitoidp/user_pool_ui_customization.go @@ -86,7 +86,7 @@ func resourceUserPoolUICustomizationPut(ctx context.Context, d *schema.ResourceD userPoolID, clientID := d.Get(names.AttrUserPoolID).(string), d.Get(names.AttrClientID).(string) id, err := flex.FlattenResourceId([]string{userPoolID, clientID}, userPoolUICustomizationResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating Cognito User Pool UI Customization (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &cognitoidentityprovider.SetUICustomizationInput{ From a9b4cbd954689d8a998e7fe482a9873f1ba6665c Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:19 -0400 Subject: [PATCH 35/45] connect: omit `id` from error if `FlattenResourceId` fails --- internal/service/connect/lambda_function_association.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/connect/lambda_function_association.go b/internal/service/connect/lambda_function_association.go index 26f13f89510..cd400bae6bb 100644 --- a/internal/service/connect/lambda_function_association.go +++ b/internal/service/connect/lambda_function_association.go @@ -62,7 +62,7 @@ func resourceLambdaFunctionAssociationCreate(ctx context.Context, d *schema.Reso functionARN := d.Get(names.AttrFunctionARN).(string) id, err := flex.FlattenResourceId([]string{instanceID, functionARN}, lambdaFunctionAssociationResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating Connect Lambda Function Association (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &connect.AssociateLambdaFunctionInput{ From 85004711b77459b3002789a0cc3a87ddda14e970 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:19 -0400 Subject: [PATCH 36/45] controltower: omit `id` from error if `FlattenResourceId` fails --- internal/service/controltower/control.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index 64169e4058d..73511d89849 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -110,7 +110,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int targetIdentifier := d.Get("target_identifier").(string) id, err := flex.FlattenResourceId([]string{targetIdentifier, controlIdentifier}, controlResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating ControlTower Control (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &controltower.EnableControlInput{ From 887235014e6a3e7e626e95cfc933f44e657c88f9 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 37/45] dynamodb: omit `id` from error if `FlattenResourceId` fails --- internal/service/dynamodb/kinesis_streaming_destination.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/dynamodb/kinesis_streaming_destination.go b/internal/service/dynamodb/kinesis_streaming_destination.go index 897c37800b5..537670c300b 100644 --- a/internal/service/dynamodb/kinesis_streaming_destination.go +++ b/internal/service/dynamodb/kinesis_streaming_destination.go @@ -65,7 +65,7 @@ func resourceKinesisStreamingDestinationCreate(ctx context.Context, d *schema.Re tableName := d.Get(names.AttrTableName).(string) id, err := flex.FlattenResourceId([]string{tableName, streamARN}, kinesisStreamingDestinationResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "enabling DynamoDB Kinesis Streaming Destination (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &dynamodb.EnableKinesisStreamingDestinationInput{ From c1e82a6b5373a40d95dee5b937761cf2bf346b6f Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 38/45] elasticache: omit `id` from error if `FlattenResourceId` fails --- internal/service/elasticache/user_group_association.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/elasticache/user_group_association.go b/internal/service/elasticache/user_group_association.go index 5fd12eea6a9..c32cebf1629 100644 --- a/internal/service/elasticache/user_group_association.go +++ b/internal/service/elasticache/user_group_association.go @@ -64,7 +64,7 @@ func resourceUserGroupAssociationCreate(ctx context.Context, d *schema.ResourceD userID := d.Get("user_id").(string) id, err := flex.FlattenResourceId([]string{userGroupID, userID}, userGroupAssociationResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating ElastiCache User Group Association (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &elasticache.ModifyUserGroupInput{ UserGroupId: aws.String(userGroupID), From fcb8dac3062da0bfbff054ab888e529d74f6df51 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 39/45] lambda: omit `id` from error if `FlattenResourceId` fails --- internal/service/lambda/layer_version_permission.go | 2 +- internal/service/lambda/provisioned_concurrency_config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/lambda/layer_version_permission.go b/internal/service/lambda/layer_version_permission.go index 1486d436a4c..076b023b920 100644 --- a/internal/service/lambda/layer_version_permission.go +++ b/internal/service/lambda/layer_version_permission.go @@ -104,7 +104,7 @@ func resourceLayerVersionPermissionCreate(ctx context.Context, d *schema.Resourc versionNumber := d.Get("version_number").(int) id, err := flex.FlattenResourceId([]string{layerName, strconv.FormatInt(int64(versionNumber), 10)}, layerVersionPermissionResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "adding Lambda Layer Version Permission (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &lambda.AddLayerVersionPermissionInput{ Action: aws.String(d.Get(names.AttrAction).(string)), diff --git a/internal/service/lambda/provisioned_concurrency_config.go b/internal/service/lambda/provisioned_concurrency_config.go index f02cb0ee809..591026b77ce 100644 --- a/internal/service/lambda/provisioned_concurrency_config.go +++ b/internal/service/lambda/provisioned_concurrency_config.go @@ -90,7 +90,7 @@ func resourceProvisionedConcurrencyConfigCreate(ctx context.Context, d *schema.R qualifier := d.Get("qualifier").(string) id, err := flex.FlattenResourceId([]string{functionName, qualifier}, provisionedConcurrencyConfigResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating Lambda Provisioned Concurrency Config (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &lambda.PutProvisionedConcurrencyConfigInput{ FunctionName: aws.String(functionName), From 597e5b682002a8c1e502d84078f51bc6d2d4389b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 40/45] ram: omit `id` from error if `FlattenResourceId` fails --- internal/service/ram/principal_association.go | 2 +- internal/service/ram/resource_association.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index a014f0313fc..2604cf36571 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -74,7 +74,7 @@ func resourcePrincipalAssociationCreate(ctx context.Context, d *schema.ResourceD resourceShareARN, principal := d.Get("resource_share_arn").(string), d.Get(names.AttrPrincipal).(string) id, err := flex.FlattenResourceId([]string{resourceShareARN, principal}, principalAssociationResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating RAM Principal Association (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } _, err = findPrincipalAssociationByTwoPartKey(ctx, conn, resourceShareARN, principal) diff --git a/internal/service/ram/resource_association.go b/internal/service/ram/resource_association.go index 083ec2daca9..80eb5aa18d5 100644 --- a/internal/service/ram/resource_association.go +++ b/internal/service/ram/resource_association.go @@ -66,7 +66,7 @@ func resourceResourceAssociationCreate(ctx context.Context, d *schema.ResourceDa resourceShareARN, resourceARN := d.Get("resource_share_arn").(string), d.Get(names.AttrResourceARN).(string) id, err := flex.FlattenResourceId([]string{resourceShareARN, resourceARN}, resourceAssociationResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating RAM Resource Association (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } _, err = findResourceAssociationByTwoPartKey(ctx, conn, resourceShareARN, resourceARN) From 578ff16e0731c1da4367a0446db5b1731104364b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 41/45] route53: omit `id` from error if `FlattenResourceId` fails --- internal/service/route53/key_signing_key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/route53/key_signing_key.go b/internal/service/route53/key_signing_key.go index de240e02faf..1de00ffdd76 100644 --- a/internal/service/route53/key_signing_key.go +++ b/internal/service/route53/key_signing_key.go @@ -133,7 +133,7 @@ func resourceKeySigningKeyCreate(ctx context.Context, d *schema.ResourceData, me status := d.Get(names.AttrStatus).(string) id, err := flex.FlattenResourceId([]string{hostedZoneID, name}, keySigningKeyResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating Route 53 Key Signing Key (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &route53.CreateKeySigningKeyInput{ CallerReference: aws.String(sdkid.UniqueId()), From e5996f3578cedc637ae22af14681e8d9c150aa34 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 42/45] securityhub: omit `id` from error if `FlattenResourceId` fails --- internal/service/securityhub/product_subscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/securityhub/product_subscription.go b/internal/service/securityhub/product_subscription.go index 269eff521a0..06e27992692 100644 --- a/internal/service/securityhub/product_subscription.go +++ b/internal/service/securityhub/product_subscription.go @@ -69,7 +69,7 @@ func resourceProductSubscriptionCreate(ctx context.Context, d *schema.ResourceDa id, err := flex.FlattenResourceId([]string{productARN, aws.ToString(output.ProductSubscriptionArn)}, productSubscriptionResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "enabling Security Hub Product Subscription (%s): %s", productARN, err) + return sdkdiag.AppendFromErr(diags, err) } d.SetId(id) From 4dcade9b6a94a672f689bddaf440f33665880e17 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 43/45] ssm: omit `id` from error if `FlattenResourceId` fails --- internal/service/ssm/patch_group.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ssm/patch_group.go b/internal/service/ssm/patch_group.go index 72c76472ab5..c0f2aafa6c2 100644 --- a/internal/service/ssm/patch_group.go +++ b/internal/service/ssm/patch_group.go @@ -63,7 +63,7 @@ func resourcePatchGroupCreate(ctx context.Context, d *schema.ResourceData, meta patchGroup := d.Get("patch_group").(string) id, err := flex.FlattenResourceId([]string{patchGroup, baselineID}, patchGroupResourceIDPartCount, false) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating SSM Patch Group (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &ssm.RegisterPatchBaselineForPatchGroupInput{ BaselineId: aws.String(baselineID), From 2ead23c1c147829880b3a0d8d25d01c301be4069 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 25 Sep 2024 16:05:20 -0400 Subject: [PATCH 44/45] wafv2: omit `id` from error if `FlattenResourceId` fails --- internal/service/wafv2/web_acl_association.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/wafv2/web_acl_association.go b/internal/service/wafv2/web_acl_association.go index f32ee91d224..657abf472e5 100644 --- a/internal/service/wafv2/web_acl_association.go +++ b/internal/service/wafv2/web_acl_association.go @@ -69,7 +69,7 @@ func resourceWebACLAssociationCreate(ctx context.Context, d *schema.ResourceData resourceARN := d.Get(names.AttrResourceARN).(string) id, err := flex.FlattenResourceId([]string{webACLARN, resourceARN}, webACLAssociationResourceIDPartCount, true) if err != nil { - return sdkdiag.AppendErrorf(diags, "creating WAFv2 WebACL Association (%s): %s", id, err) + return sdkdiag.AppendFromErr(diags, err) } input := &wafv2.AssociateWebACLInput{ From 52df9b9b5c2764621140e86f0343f0f112d08bc4 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 27 Sep 2024 10:23:33 -0400 Subject: [PATCH 45/45] Update internal/service/bedrockagent/agent_alias.go Co-authored-by: Kit Ewbank --- internal/service/bedrockagent/agent_alias.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/bedrockagent/agent_alias.go b/internal/service/bedrockagent/agent_alias.go index 36fa6e2117c..2572b9419c9 100644 --- a/internal/service/bedrockagent/agent_alias.go +++ b/internal/service/bedrockagent/agent_alias.go @@ -139,7 +139,7 @@ func (r *agentAliasResource) Create(ctx context.Context, request resource.Create data.AgentAliasID = fwflex.StringToFramework(ctx, output.AgentAlias.AgentAliasId) id, err := data.setID() if err != nil { - response.Diagnostics.AddError("flattning resource ID Bedrock Agent Alias", err.Error()) + response.Diagnostics.AddError("creating Bedrock Agent Alias", err.Error()) return } data.ID = types.StringValue(id)