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

Migrate vpc resources to AWS SDK V2 (Part 1) #37534

Merged
merged 21 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc17bd6
d/aws_vpc_prefix_list: covert to aws sdk v2
jar-b May 13, 2024
7c3f580
r/aws_vpc_endpoint: convert to aws sdk v2
jar-b May 13, 2024
eb23ecd
d/aws_vpc_endpoint: convert to aws sdk v2
jar-b May 13, 2024
aeba401
r/aws_vpc_endpoint_policy: convert to aws sdk v2
jar-b May 13, 2024
4aaa59a
d/aws_vpc_route: convert to aws sdk v2
jar-b May 13, 2024
c65ba68
r/aws_vpc_route: convert to aws sdk v2
jar-b May 13, 2024
ecd5c82
r/aws_vpc_route_table: convert to aws sdk v2
jar-b May 13, 2024
0a5584a
r/aws_vpc_route_table_association: convert to aws sdk v2
jar-b May 13, 2024
3b11a74
d/aws_vpc_route_table: convert to aws sdk v2
jar-b May 13, 2024
785a3b0
d/aws_vpc_route_tables: convert to aws sdk v2
jar-b May 13, 2024
02737ad
r/aws_vpc_default_route_table: convert to aws sdk v2
jar-b May 13, 2024
e0263d0
r/aws_vpnsite_gateway_route_propagation: convert to aws sdk v2
jar-b May 13, 2024
66367c2
r/aws_vpc_endpoint_service: convert to aws sdk v2
jar-b May 15, 2024
a81353f
internal/generate/listpages: optional -V2Suffix flag
jar-b May 15, 2024
033c7ee
d/aws_vpc_endpoint_service: convert to aws sdk v2
jar-b May 15, 2024
6c9e653
r/aws_vpc_endpoint_route_table_association: convert to aws sdk v2
jar-b May 15, 2024
4a6b463
r/aws_vpc_endpoint_security_group_association: convert to aws sdk v2
jar-b May 15, 2024
543bbdc
r/aws_vpc_endpoint_subnet_association: convert to aws sdk v2
jar-b May 15, 2024
e9e418a
r/aws_vpc_endpoint_connection_accepter: convert to aws sdk v2
jar-b May 16, 2024
8381af5
r/aws_vpc_endpoint_connection_notification: convert to aws sdk v2
jar-b May 16, 2024
aac92c3
r/aws_vpc_endpoint_connection_service_allowed_principal: convert to a…
jar-b May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/37534.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_vpc_endpoint_service: Fix destroy error when endpoint service is deleted out-of-band
```
2 changes: 2 additions & 0 deletions internal/generate/listpages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Optional Flags:

* `-Paginator`: Name of the pagination token field (default `NextToken`)
* `-Export`: Whether to export the generated functions
* `-AWSSDKVersion`: Version of the AWS Go SDK to use i.e. 1 or 2 (default `1`)
* `-V2Suffix`: Whether to append a V2 suffix to the list functions

To use with `go generate`, add the following directive to a Go file

Expand Down
7 changes: 5 additions & 2 deletions internal/generate/listpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
paginator = flag.String("Paginator", "NextToken", "name of the pagination token field")
export = flag.Bool("Export", false, "whether to export the list functions")
sdkVersion = flag.Int("AWSSDKVersion", sdkV1, "Version of the AWS Go SDK to use i.e. 1 or 2")
v2Suffix = flag.Bool("V2Suffix", false, "whether to append a V2 suffix to the list functions")
)

func usage() {
Expand Down Expand Up @@ -113,7 +114,7 @@ func main() {
}

for _, functionName := range functions {
g.generateFunction(functionName, awsService, awsUpper, *export, *sdkVersion)
g.generateFunction(functionName, awsService, awsUpper, *export, *sdkVersion, *v2Suffix)
}

src := g.format()
Expand Down Expand Up @@ -200,9 +201,10 @@ type FuncSpec struct {
ResultType string
InputPaginator string
OutputPaginator string
V2Suffix bool
}

func (g *Generator) generateFunction(functionName, awsService, awsServiceUpper string, export bool, sdkVersion int) {
func (g *Generator) generateFunction(functionName, awsService, awsServiceUpper string, export bool, sdkVersion int, v2Suffix bool) {
var function *ast.FuncDecl

for _, file := range g.pkg.files {
Expand Down Expand Up @@ -245,6 +247,7 @@ func (g *Generator) generateFunction(functionName, awsService, awsServiceUpper s
ResultType: g.expandTypeField(function.Type.Results, sdkVersion, true), // Assumes we can take the first return parameter
InputPaginator: g.inputPaginator,
OutputPaginator: g.outputPaginator,
V2Suffix: v2Suffix,
}

err := g.tmpl.Execute(&g.buf, funcSpec)
Expand Down
5 changes: 2 additions & 3 deletions internal/generate/listpages/v2/function.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

func {{ .Name }}Pages(ctx context.Context, conn {{ .RecvType }}, input {{ .ParamType }}, fn func({{ .ResultType }}, bool) bool) error {
func {{ .Name }}Pages{{ if .V2Suffix }}V2{{ end }}(ctx context.Context, conn {{ .RecvType }}, input {{ .ParamType }}, fn func({{ .ResultType }}, bool) bool) error {
for {
output, err := conn.{{ .AWSName }}(ctx, input)
if err != nil {
Expand All @@ -14,4 +13,4 @@ func {{ .Name }}Pages(ctx context.Context, conn {{ .RecvType }}, input {{ .Param
input.{{ .InputPaginator }} = output.{{ .OutputPaginator }}
}
return nil
}
}
1 change: 1 addition & 0 deletions internal/service/ec2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const (
errCodeInvalidVPCCIDRBlockAssociationIDNotFound = "InvalidVpcCidrBlockAssociationID.NotFound"
errCodeInvalidVPCEndpointIdNotFound = "InvalidVpcEndpointId.NotFound"
errCodeInvalidVPCEndpointNotFound = "InvalidVpcEndpoint.NotFound"
errCodeInvalidVPCEndpointServiceNotFound = "InvalidVpcEndpointService.NotFound"
errCodeInvalidVPCEndpointServiceIdNotFound = "InvalidVpcEndpointServiceId.NotFound"
errCodeInvalidVPCIDNotFound = "InvalidVpcID.NotFound"
errCodeInvalidVPCPeeringConnectionIDNotFound = "InvalidVpcPeeringConnectionID.NotFound"
Expand Down
36 changes: 36 additions & 0 deletions internal/service/ec2/errorsv2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ec2

import (
"errors"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws"
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
smithy "github.com/aws/smithy-go"
)

func unsuccessfulItemErrorV2(apiObject *awstypes.UnsuccessfulItemError) error {
if apiObject == nil {
return nil
}

return &smithy.GenericAPIError{
Code: aws.ToString(apiObject.Code),
Message: aws.ToString(apiObject.Message),
}
}

func unsuccessfulItemsErrorV2(apiObjects []awstypes.UnsuccessfulItem) error {
var errs []error

for _, apiObject := range apiObjects {
if err := unsuccessfulItemErrorV2(apiObject.Error); err != nil {
errs = append(errs, fmt.Errorf("%s: %w", aws.ToString(apiObject.ResourceId), err))
}
}

return errors.Join(errs...)
}
58 changes: 36 additions & 22 deletions internal/service/ec2/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,42 @@ var (
ResourceVPNGatewayAttachment = resourceVPNGatewayAttachment
ResourceVPNGatewayRoutePropagation = resourceVPNGatewayRoutePropagation

CustomFiltersSchema = customFiltersSchema
FindEBSVolumeAttachment = findVolumeAttachment
FindEIPByAllocationID = findEIPByAllocationID
FindEIPByAssociationID = findEIPByAssociationID
FindEIPDomainNameAttributeByAllocationID = findEIPDomainNameAttributeByAllocationID
FindFastSnapshotRestoreByTwoPartKey = findFastSnapshotRestoreByTwoPartKey
FindInstanceMetadataDefaults = findInstanceMetadataDefaults
FindKeyPairByName = findKeyPairByName
FindNetworkACLByIDV2 = findNetworkACLByIDV2
FindNetworkInterfaceByIDV2 = findNetworkInterfaceByIDV2
FindVolumeAttachmentInstanceByID = findVolumeAttachmentInstanceByID
FlattenNetworkInterfacePrivateIPAddresses = flattenNetworkInterfacePrivateIPAddresses
IPAMServicePrincipal = ipamServicePrincipal
NewAttributeFilterList = newAttributeFilterList
NewAttributeFilterListV2 = newAttributeFilterListV2
NewCustomFilterList = newCustomFilterList
NewTagFilterList = newTagFilterList
ProtocolForValue = protocolForValue
StopInstance = stopInstance
StopEBSVolumeAttachmentInstance = stopVolumeAttachmentInstance
UpdateTags = updateTags
UpdateTagsV2 = updateTagsV2
CustomFiltersSchema = customFiltersSchema
FindEBSVolumeAttachment = findVolumeAttachment
FindEIPByAllocationID = findEIPByAllocationID
FindEIPByAssociationID = findEIPByAssociationID
FindEIPDomainNameAttributeByAllocationID = findEIPDomainNameAttributeByAllocationID
FindFastSnapshotRestoreByTwoPartKey = findFastSnapshotRestoreByTwoPartKey
FindInstanceMetadataDefaults = findInstanceMetadataDefaults
FindKeyPairByName = findKeyPairByName
FindNetworkACLByIDV2 = findNetworkACLByIDV2
FindNetworkInterfaceByIDV2 = findNetworkInterfaceByIDV2
FindRouteByIPv4DestinationV2 = findRouteByIPv4DestinationV2
FindRouteByIPv6DestinationV2 = findRouteByIPv6DestinationV2
FindRouteByPrefixListIDDestinationV2 = findRouteByPrefixListIDDestinationV2
FindRouteTableAssociationByIDV2 = findRouteTableAssociationByIDV2
FindRouteTableByIDV2 = findRouteTableByIDV2
FindVolumeAttachmentInstanceByID = findVolumeAttachmentInstanceByID
FindVPCEndpointByIDV2 = findVPCEndpointByIDV2
FindVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2 = findVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2
FindVPCEndpointConnectionNotificationByIDV2 = findVPCEndpointConnectionNotificationByIDV2
FindVPCEndpointRouteTableAssociationExistsV2 = findVPCEndpointRouteTableAssociationExistsV2
FindVPCEndpointSecurityGroupAssociationExistsV2 = findVPCEndpointSecurityGroupAssociationExistsV2
FindVPCEndpointServiceConfigurationByIDV2 = findVPCEndpointServiceConfigurationByIDV2
FindVPCEndpointServicePermissionV2 = findVPCEndpointServicePermissionV2
FindVPCEndpointSubnetAssociationExistsV2 = findVPCEndpointSubnetAssociationExistsV2
FindVPNGatewayRoutePropagationExistsV2 = findVPNGatewayRoutePropagationExistsV2
FlattenNetworkInterfacePrivateIPAddresses = flattenNetworkInterfacePrivateIPAddresses
IPAMServicePrincipal = ipamServicePrincipal
NewAttributeFilterList = newAttributeFilterList
NewAttributeFilterListV2 = newAttributeFilterListV2
NewCustomFilterList = newCustomFilterList
NewTagFilterList = newTagFilterList
ProtocolForValue = protocolForValue
StopInstance = stopInstance
StopEBSVolumeAttachmentInstance = stopVolumeAttachmentInstance
UpdateTags = updateTags
UpdateTagsV2 = updateTagsV2
)

type (
Expand Down
Loading
Loading