Skip to content

Commit

Permalink
Merge pull request #41340 from hashicorp/td-more-api-inputs-in-heap
Browse files Browse the repository at this point in the history
Move inputs off heap with autofix: `a` and `w` services
  • Loading branch information
gdavison authored Feb 13, 2025
2 parents 2cb81dd + 5c67639 commit cf75f8e
Show file tree
Hide file tree
Showing 82 changed files with 356 additions and 223 deletions.
41 changes: 38 additions & 3 deletions .ci/semgrep/aws/input-on-heap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,48 @@ rules:
- "internal/service/t*"
- "internal/service/v*"
- "internal/service/w*"
patterns:
- pattern: |
$X := &$PKG.$INPUT{ ... }
- metavariable-regex:
metavariable: $INPUT
regex: \w+Input
severity: WARNING

- id: input-on-heap-inline
languages: [go]
message: Create the $PKG.$INPUT struct on the stack instead of on the heap
paths:
exclude:
- "internal/service/auditmanager"
- "internal/service/b*"
- "internal/service/c*"
- "internal/service/d*"
- "internal/service/e*"
- "internal/service/f*"
- "internal/service/g*"
- "internal/service/i*"
- "internal/service/k*"
- "internal/service/l*"
- "internal/service/m*"
- "internal/service/n*"
- "internal/service/o*"
- "internal/service/p*"
- "internal/service/q*"
- "internal/service/r*"
- "internal/service/s*"
- "internal/service/t*"
- "internal/service/v*"
patterns:
- pattern-either:
- pattern: |
$X := &$PKG.$INPUT{ ... }
- pattern: |
$FUNC(ctx, &$PKG.$INPUT{ ... }, ...)
... = $FUNC(ctx, &$PKG.$INPUT{ ... }, ...)
- metavariable-regex:
metavariable: $INPUT
regex: \w+Input
fix-regex:
regex: '(?s)(.+= \w+\.\w+\(\w+, &)(\w+\.\w+\{.*\})(\))'
replacement: |
input := \2
\1input\3
severity: WARNING
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ func resourceAPIDelete(ctx context.Context, d *schema.ResourceData, meta interfa
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 API: %s", d.Id())
_, err := conn.DeleteApi(ctx, &apigatewayv2.DeleteApiInput{
input := apigatewayv2.DeleteApiInput{
ApiId: aws.String(d.Id()),
})
}
_, err := conn.DeleteApi(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/api_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ func resourceAPIMappingDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 API Mapping (%s)", d.Id())
_, err := conn.DeleteApiMapping(ctx, &apigatewayv2.DeleteApiMappingInput{
input := apigatewayv2.DeleteApiMappingInput{
ApiMappingId: aws.String(d.Id()),
DomainName: aws.String(d.Get(names.AttrDomainName).(string)),
})
}
_, err := conn.DeleteApiMapping(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/api_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ func testAccCheckAPIMappingCreateCertificate(ctx context.Context, t *testing.T,

conn := acctest.Provider.Meta().(*conns.AWSClient).ACMClient(ctx)

output, err := conn.ImportCertificate(ctx, &acm.ImportCertificateInput{
input := acm.ImportCertificateInput{
Certificate: []byte(certificate),
PrivateKey: []byte(privateKey),
Tags: tfacm.Tags(tftags.New(ctx, map[string]interface{}{
"Name": rName,
}).IgnoreAWS()),
})
}
output, err := conn.ImportCertificate(ctx, &input)

if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Deployment (%s)", d.Id())
_, err := conn.DeleteDeployment(ctx, &apigatewayv2.DeleteDeploymentInput{
input := apigatewayv2.DeleteDeploymentInput{
ApiId: aws.String(d.Get("api_id").(string)),
DeploymentId: aws.String(d.Id()),
})
}
_, err := conn.DeleteDeployment(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ func resourceDomainNameDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Domain Name: %s", d.Id())
_, err := conn.DeleteDomainName(ctx, &apigatewayv2.DeleteDomainNameInput{
input := apigatewayv2.DeleteDomainNameInput{
DomainName: aws.String(d.Id()),
})
}
_, err := conn.DeleteDomainName(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,11 @@ func resourceIntegrationDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Integration: %s", d.Id())
_, err := conn.DeleteIntegration(ctx, &apigatewayv2.DeleteIntegrationInput{
input := apigatewayv2.DeleteIntegrationInput{
ApiId: aws.String(d.Get("api_id").(string)),
IntegrationId: aws.String(d.Id()),
})
}
_, err := conn.DeleteIntegration(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/integration_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ func resourceIntegrationResponseDelete(ctx context.Context, d *schema.ResourceDa
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Integration Response: %s", d.Id())
_, err := conn.DeleteIntegrationResponse(ctx, &apigatewayv2.DeleteIntegrationResponseInput{
input := apigatewayv2.DeleteIntegrationResponseInput{
ApiId: aws.String(d.Get("api_id").(string)),
IntegrationId: aws.String(d.Get("integration_id").(string)),
IntegrationResponseId: aws.String(d.Id()),
})
}
_, err := conn.DeleteIntegrationResponse(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ func resourceModelDelete(ctx context.Context, d *schema.ResourceData, meta inter
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Model: %s", d.Id())
_, err := conn.DeleteModel(ctx, &apigatewayv2.DeleteModelInput{
input := apigatewayv2.DeleteModelInput{
ApiId: aws.String(d.Get("api_id").(string)),
ModelId: aws.String(d.Id()),
})
}
_, err := conn.DeleteModel(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ func resourceRouteDelete(ctx context.Context, d *schema.ResourceData, meta inter
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Route: %s", d.Id())
_, err := conn.DeleteRoute(ctx, &apigatewayv2.DeleteRouteInput{
input := apigatewayv2.DeleteRouteInput{
ApiId: aws.String(d.Get("api_id").(string)),
RouteId: aws.String(d.Id()),
})
}
_, err := conn.DeleteRoute(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/route_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ func resourceRouteResponseDelete(ctx context.Context, d *schema.ResourceData, me
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Route Response: %s", d.Id())
_, err := conn.DeleteRouteResponse(ctx, &apigatewayv2.DeleteRouteResponseInput{
input := apigatewayv2.DeleteRouteResponseInput{
ApiId: aws.String(d.Get("api_id").(string)),
RouteId: aws.String(d.Get("route_id").(string)),
RouteResponseId: aws.String(d.Id()),
})
}
_, err := conn.DeleteRouteResponse(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ func resourceStageDelete(ctx context.Context, d *schema.ResourceData, meta inter
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 Stage: %s", d.Id())
_, err := conn.DeleteStage(ctx, &apigatewayv2.DeleteStageInput{
input := apigatewayv2.DeleteStageInput{
ApiId: aws.String(d.Get("api_id").(string)),
StageName: aws.String(d.Id()),
})
}
_, err := conn.DeleteStage(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
3 changes: 2 additions & 1 deletion internal/service/apigatewayv2/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,8 @@ resource "aws_apigatewayv2_stage" "test" {
func testAccPreCheckAPIGatewayAccountCloudWatchRoleARN(ctx context.Context, t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx)

output, err := conn.GetAccount(ctx, &apigateway.GetAccountInput{})
input := apigateway.GetAccountInput{}
output, err := conn.GetAccount(ctx, &input)

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping tests: %s", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigatewayv2/vpc_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ func resourceVPCLinkDelete(ctx context.Context, d *schema.ResourceData, meta int
conn := meta.(*conns.AWSClient).APIGatewayV2Client(ctx)

log.Printf("[DEBUG] Deleting API Gateway v2 VPC Link: %s", d.Id())
_, err := conn.DeleteVpcLink(ctx, &apigatewayv2.DeleteVpcLinkInput{
input := apigatewayv2.DeleteVpcLinkInput{
VpcLinkId: aws.String(d.Id()),
})
}
_, err := conn.DeleteVpcLink(ctx, &input)

if errs.IsA[*awstypes.NotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ func resourceApplicationDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).AppConfigClient(ctx)

log.Printf("[INFO] Deleting AppConfig Application: %s", d.Id())
_, err := conn.DeleteApplication(ctx, &appconfig.DeleteApplicationInput{
input := appconfig.DeleteApplicationInput{
ApplicationId: aws.String(d.Id()),
})
}
_, err := conn.DeleteApplication(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/configuration_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ func resourceConfigurationProfileDelete(ctx context.Context, d *schema.ResourceD
}

log.Printf("[INFO] Deleting AppConfig Configuration Profile: %s", d.Id())
_, err = conn.DeleteConfigurationProfile(ctx, &appconfig.DeleteConfigurationProfileInput{
input := appconfig.DeleteConfigurationProfileInput{
ApplicationId: aws.String(appID),
ConfigurationProfileId: aws.String(confProfID),
})
}
_, err = conn.DeleteConfigurationProfile(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ func dataSourceConfigurationProfileRead(ctx context.Context, d *schema.ResourceD
}

func findConfigurationProfileByApplicationAndProfile(ctx context.Context, conn *appconfig.Client, appId string, cpId string) (*appconfig.GetConfigurationProfileOutput, error) {
res, err := conn.GetConfigurationProfile(ctx, &appconfig.GetConfigurationProfileInput{
input := appconfig.GetConfigurationProfileInput{
ApplicationId: aws.String(appId),
ConfigurationProfileId: aws.String(cpId),
})
}
res, err := conn.GetConfigurationProfile(ctx, &input)

if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/configuration_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,11 @@ func testAccCheckConfigurationProfileExists(ctx context.Context, resourceName st

conn := acctest.Provider.Meta().(*conns.AWSClient).AppConfigClient(ctx)

output, err := conn.GetConfigurationProfile(ctx, &appconfig.GetConfigurationProfileInput{
input := appconfig.GetConfigurationProfileInput{
ApplicationId: aws.String(appID),
ConfigurationProfileId: aws.String(confProfID),
})
}
output, err := conn.GetConfigurationProfile(ctx, &input)

if err != nil {
return fmt.Errorf("error reading AppConfig Configuration Profile (%s) for Application (%s): %w", confProfID, appID, err)
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/deployment_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ func resourceDeploymentStrategyDelete(ctx context.Context, d *schema.ResourceDat
conn := meta.(*conns.AWSClient).AppConfigClient(ctx)

log.Printf("[INFO] Deleting AppConfig Deployment Strategy: %s", d.Id())
_, err := conn.DeleteDeploymentStrategy(ctx, &appconfig.DeleteDeploymentStrategyInput{
input := appconfig.DeleteDeploymentStrategyInput{
DeploymentStrategyId: aws.String(d.Id()),
})
}
_, err := conn.DeleteDeploymentStrategy(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/environment_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ func dataSourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta
}

func findEnvironmentByApplicationAndEnvironment(ctx context.Context, conn *appconfig.Client, appId string, envId string) (*appconfig.GetEnvironmentOutput, error) {
res, err := conn.GetEnvironment(ctx, &appconfig.GetEnvironmentInput{
input := appconfig.GetEnvironmentInput{
ApplicationId: aws.String(appId),
EnvironmentId: aws.String(envId),
})
}
res, err := conn.GetEnvironment(ctx, &input)

if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ func resourceExtensionDelete(ctx context.Context, d *schema.ResourceData, meta i

conn := meta.(*conns.AWSClient).AppConfigClient(ctx)

_, err := conn.DeleteExtension(ctx, &appconfig.DeleteExtensionInput{
input := appconfig.DeleteExtensionInput{
ExtensionIdentifier: aws.String(d.Id()),
})
}
_, err := conn.DeleteExtension(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/extension_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ func resourceExtensionAssociationDelete(ctx context.Context, d *schema.ResourceD
conn := meta.(*conns.AWSClient).AppConfigClient(ctx)

log.Printf("[INFO] Deleting AppConfig Hosted Extension Association: %s", d.Id())
_, err := conn.DeleteExtensionAssociation(ctx, &appconfig.DeleteExtensionAssociationInput{
input := appconfig.DeleteExtensionAssociationInput{
ExtensionAssociationId: aws.String(d.Id()),
})
}
_, err := conn.DeleteExtensionAssociation(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appconfig/hosted_configuration_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ func resourceHostedConfigurationVersionDelete(ctx context.Context, d *schema.Res
}

log.Printf("[INFO] Deleting AppConfig Hosted Configuration Version: %s", d.Id())
_, err = conn.DeleteHostedConfigurationVersion(ctx, &appconfig.DeleteHostedConfigurationVersionInput{
input := appconfig.DeleteHostedConfigurationVersionInput{
ApplicationId: aws.String(appID),
ConfigurationProfileId: aws.String(confProfID),
VersionNumber: aws.Int32(versionNumber),
})
}
_, err = conn.DeleteHostedConfigurationVersion(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ func testAccCheckHostedConfigurationVersionExists(ctx context.Context, resourceN

conn := acctest.Provider.Meta().(*conns.AWSClient).AppConfigClient(ctx)

output, err := conn.GetHostedConfigurationVersion(ctx, &appconfig.GetHostedConfigurationVersionInput{
input := appconfig.GetHostedConfigurationVersionInput{
ApplicationId: aws.String(appID),
ConfigurationProfileId: aws.String(confProfID),
VersionNumber: aws.Int32(versionNumber),
})
}
output, err := conn.GetHostedConfigurationVersion(ctx, &input)

if err != nil {
return fmt.Errorf("error reading AppConfig Hosted Configuration Version (%s): %w", rs.Primary.ID, err)
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appfabric/app_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,11 @@ func (r *appAuthorizationResource) Delete(ctx context.Context, request resource.

conn := r.Meta().AppFabricClient(ctx)

_, err := conn.DeleteAppAuthorization(ctx, &appfabric.DeleteAppAuthorizationInput{
input := appfabric.DeleteAppAuthorizationInput{
AppAuthorizationIdentifier: fwflex.StringFromFramework(ctx, data.AppAuthorizationARN),
AppBundleIdentifier: fwflex.StringFromFramework(ctx, data.AppBundleARN),
})
}
_, err := conn.DeleteAppAuthorization(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return
Expand Down
5 changes: 3 additions & 2 deletions internal/service/appfabric/app_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ func (r *appBundleResource) Delete(ctx context.Context, request resource.DeleteR

conn := r.Meta().AppFabricClient(ctx)

_, err := conn.DeleteAppBundle(ctx, &appfabric.DeleteAppBundleInput{
input := appfabric.DeleteAppBundleInput{
AppBundleIdentifier: data.ID.ValueStringPointer(),
})
}
_, err := conn.DeleteAppBundle(ctx, &input)

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return
Expand Down
Loading

0 comments on commit cf75f8e

Please sign in to comment.