Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apigateway: Modernize Go code #41836

Merged
merged 3 commits into from
Mar 14, 2025
Merged

apigateway: Modernize Go code #41836

merged 3 commits into from
Mar 14, 2025

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented Mar 13, 2025

Description

Modernizing

Modernizing Go code improves readability, maintainability, and aligns with current best practices. Replacing interface{} with any makes the code more concise and idiomatic in Go 1.18+, reducing verbosity without changing functionality. Similarly, updating loop constructs enhances clarity and leverages Go’s modern syntax where applicable. These changes help keep the codebase up to date, making it easier for new contributors to understand and maintain.

Unnecessary Ops

One unexpected advantage of modernizing is that it surfaces bugs. For example, it shows that this code from apigateway/rest_api does not do what you might expect:

for _, v := range output.EndpointConfiguration.VpcEndpointIds { 
	for _, x := range endpointConfiguration.VpcEndpointIds { 
		if v == x { 
			break 
		} 
	} 
	operations = append(operations, types.PatchOperation{ 
		Op:    types.OpRemove, 
		Path:  aws.String(prefix), 
		Value: aws.String(v), 
	}) 
} 

The inner for loop does absolutely nothing. This becomes clear when modernized.

for _, v := range output.EndpointConfiguration.VpcEndpointIds { 
	if slices.Contains(output.EndpointConfiguration.VpcEndpointIds, v) { 

	}
	operations = append(operations, types.PatchOperation{ 
		Op:    types.OpRemove, 
		Path:  aws.String(prefix), 
		Value: aws.String(v), 
	}) 
} 

The stated intent of this section is to align the AWS output endpoint configurations with the endpoint configurations configured in Terraform. To do this, we add those that are missing and remove extras. Using a continue seems to achieve this objective.

for _, v := range output.EndpointConfiguration.VpcEndpointIds { 
	if slices.Contains(output.EndpointConfiguration.VpcEndpointIds, v) { 
		continue
	}
	operations = append(operations, types.PatchOperation{ 
		Op:    types.OpRemove, 
		Path:  aws.String(prefix), 
		Value: aws.String(v), 
	}) 
} 

Relations

Relates #41807
Closes #40865

References

Output from Acceptance Testing

% make t T=TestAccAPIGatewayRestAPI_ K=apigateway
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.7 test ./internal/service/apigateway/... -v -count 1 -parallel 20 -run='TestAccAPIGatewayRestAPI_'  -timeout 360m -vet=off
2025/03/13 15:29:36 Initializing Terraform AWS Provider...
=== RUN   TestAccAPIGatewayRestAPI_basic
=== PAUSE TestAccAPIGatewayRestAPI_basic
=== RUN   TestAccAPIGatewayRestAPI_disappears
=== PAUSE TestAccAPIGatewayRestAPI_disappears
=== RUN   TestAccAPIGatewayRestAPI_endpoint
=== PAUSE TestAccAPIGatewayRestAPI_endpoint
=== RUN   TestAccAPIGatewayRestAPI_Endpoint_private
=== PAUSE TestAccAPIGatewayRestAPI_Endpoint_private
=== RUN   TestAccAPIGatewayRestAPI_apiKeySource
=== PAUSE TestAccAPIGatewayRestAPI_apiKeySource
=== RUN   TestAccAPIGatewayRestAPI_APIKeySource_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_APIKeySource_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_APIKeySource_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_APIKeySource_setByBody
=== RUN   TestAccAPIGatewayRestAPI_binaryMediaTypes
=== PAUSE TestAccAPIGatewayRestAPI_binaryMediaTypes
=== RUN   TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody
=== RUN   TestAccAPIGatewayRestAPI_body
=== PAUSE TestAccAPIGatewayRestAPI_body
=== RUN   TestAccAPIGatewayRestAPI_description
=== PAUSE TestAccAPIGatewayRestAPI_description
=== RUN   TestAccAPIGatewayRestAPI_Description_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_Description_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_Description_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_Description_setByBody
=== RUN   TestAccAPIGatewayRestAPI_disableExecuteAPIEndpoint
=== PAUSE TestAccAPIGatewayRestAPI_disableExecuteAPIEndpoint
=== RUN   TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody
=== RUN   TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs
=== PAUSE TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs
=== RUN   TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody
=== PAUSE TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody
=== RUN   TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody
=== PAUSE TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody
=== RUN   TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody
=== RUN   TestAccAPIGatewayRestAPI_minimumCompressionSize
=== PAUSE TestAccAPIGatewayRestAPI_minimumCompressionSize
=== RUN   TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody
=== RUN   TestAccAPIGatewayRestAPI_Name_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_Name_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_FailOnWarnings
=== PAUSE TestAccAPIGatewayRestAPI_FailOnWarnings
=== RUN   TestAccAPIGatewayRestAPI_parameters
=== PAUSE TestAccAPIGatewayRestAPI_parameters
=== RUN   TestAccAPIGatewayRestAPI_Policy_basic
=== PAUSE TestAccAPIGatewayRestAPI_Policy_basic
=== RUN   TestAccAPIGatewayRestAPI_Policy_order
=== PAUSE TestAccAPIGatewayRestAPI_Policy_order
=== RUN   TestAccAPIGatewayRestAPI_Policy_overrideBody
=== PAUSE TestAccAPIGatewayRestAPI_Policy_overrideBody
=== RUN   TestAccAPIGatewayRestAPI_Policy_setByBody
=== PAUSE TestAccAPIGatewayRestAPI_Policy_setByBody
=== CONT  TestAccAPIGatewayRestAPI_basic
=== CONT  TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody
=== CONT  TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_Description_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_Policy_setByBody
=== CONT  TestAccAPIGatewayRestAPI_apiKeySource
=== CONT  TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody
=== CONT  TestAccAPIGatewayRestAPI_binaryMediaTypes
=== CONT  TestAccAPIGatewayRestAPI_APIKeySource_setByBody
=== CONT  TestAccAPIGatewayRestAPI_APIKeySource_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody
=== CONT  TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_minimumCompressionSize
=== CONT  TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody
=== CONT  TestAccAPIGatewayRestAPI_Policy_basic
=== CONT  TestAccAPIGatewayRestAPI_Policy_overrideBody
=== CONT  TestAccAPIGatewayRestAPI_Policy_order
=== CONT  TestAccAPIGatewayRestAPI_Description_setByBody
=== CONT  TestAccAPIGatewayRestAPI_disableExecuteAPIEndpoint
--- PASS: TestAccAPIGatewayRestAPI_basic (26.93s)
=== CONT  TestAccAPIGatewayRestAPI_FailOnWarnings
--- PASS: TestAccAPIGatewayRestAPI_APIKeySource_overrideBody (58.11s)
=== CONT  TestAccAPIGatewayRestAPI_parameters
--- PASS: TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody (89.44s)
=== CONT  TestAccAPIGatewayRestAPI_body
--- PASS: TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody (119.39s)
=== CONT  TestAccAPIGatewayRestAPI_description
--- PASS: TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody (126.30s)
=== CONT  TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs
--- PASS: TestAccAPIGatewayRestAPI_Description_overrideBody (209.76s)
=== CONT  TestAccAPIGatewayRestAPI_endpoint
--- PASS: TestAccAPIGatewayRestAPI_endpoint (113.73s)
=== CONT  TestAccAPIGatewayRestAPI_Endpoint_private
--- PASS: TestAccAPIGatewayRestAPI_minimumCompressionSize (363.89s)
=== CONT  TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody
--- PASS: TestAccAPIGatewayRestAPI_Policy_overrideBody (430.73s)
=== CONT  TestAccAPIGatewayRestAPI_disappears
--- PASS: TestAccAPIGatewayRestAPI_Policy_order (486.76s)
=== CONT  TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody
--- PASS: TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody (538.52s)
=== CONT  TestAccAPIGatewayRestAPI_Name_overrideBody
--- PASS: TestAccAPIGatewayRestAPI_disappears (111.62s)
=== CONT  TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody
--- PASS: TestAccAPIGatewayRestAPI_parameters (489.14s)
--- PASS: TestAccAPIGatewayRestAPI_Name_overrideBody (47.02s)
--- PASS: TestAccAPIGatewayRestAPI_Policy_setByBody (615.66s)
--- PASS: TestAccAPIGatewayRestAPI_Description_setByBody (722.97s)
--- PASS: TestAccAPIGatewayRestAPI_disableExecuteAPIEndpoint (782.09s)
--- PASS: TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody (833.30s)
--- PASS: TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs (756.12s)
--- PASS: TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody (397.02s)
--- PASS: TestAccAPIGatewayRestAPI_apiKeySource (894.87s)
--- PASS: TestAccAPIGatewayRestAPI_binaryMediaTypes (962.30s)
--- PASS: TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody (434.29s)
--- PASS: TestAccAPIGatewayRestAPI_Endpoint_private (678.72s)
--- PASS: TestAccAPIGatewayRestAPI_Policy_basic (1038.76s)
--- PASS: TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody (1089.93s)
--- PASS: TestAccAPIGatewayRestAPI_body (1082.76s)
--- PASS: TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody (1252.13s)
--- PASS: TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody (918.60s)
--- PASS: TestAccAPIGatewayRestAPI_APIKeySource_setByBody (1368.66s)
--- PASS: TestAccAPIGatewayRestAPI_description (1250.31s)
--- PASS: TestAccAPIGatewayRestAPI_FailOnWarnings (1487.91s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	1519.156s

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@YakDriver YakDriver requested a review from a team as a code owner March 13, 2025 18:43
Copy link

Community Guidelines

This comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀

Voting for Prioritization

  • Please vote on this Pull Request by adding a 👍 reaction to the original post to help the community and maintainers prioritize it.
  • Please see our prioritization guide for additional information on how the maintainers handle prioritization.
  • Please do not leave +1 or other comments that do not add relevant new information or questions; they generate extra noise for others following the Pull Request and do not help prioritize the request.

Pull Request Authors

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/apigateway Issues and PRs that pertain to the apigateway service. size/XL Managed by automation to categorize the size of a PR. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Mar 13, 2025
@github-actions github-actions bot added repository Repository modifications; GitHub Actions, developer docs, issue templates, codeowners, changelog. github_actions Pull requests that update Github_actions code labels Mar 13, 2025
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a CHANGELOG entry for the fixed bug.

Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

@YakDriver YakDriver merged commit fad7327 into main Mar 14, 2025
39 checks passed
@YakDriver YakDriver deleted the td-modernize-go-apigateway branch March 14, 2025 17:11
Copy link

Warning

This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.92.0 milestone Mar 14, 2025
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Mar 20, 2025
Copy link

This functionality has been released in v5.92.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update Github_actions code repository Repository modifications; GitHub Actions, developer docs, issue templates, codeowners, changelog. service/apigateway Issues and PRs that pertain to the apigateway service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unnecessary remove and add operations for vpcEndpointIds in aws_api_gateway_rest_api
2 participants