diff --git a/.changelog/37534.txt b/.changelog/37534.txt new file mode 100644 index 000000000000..e621f43c0059 --- /dev/null +++ b/.changelog/37534.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_vpc_endpoint_service: Fix destroy error when endpoint service is deleted out-of-band +``` diff --git a/internal/generate/listpages/README.md b/internal/generate/listpages/README.md index 8a5b20772120..c2f73e5248de 100644 --- a/internal/generate/listpages/README.md +++ b/internal/generate/listpages/README.md @@ -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 diff --git a/internal/generate/listpages/main.go b/internal/generate/listpages/main.go index ec7b474ed4b5..30c8fce24e9e 100644 --- a/internal/generate/listpages/main.go +++ b/internal/generate/listpages/main.go @@ -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() { @@ -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() @@ -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 { @@ -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) diff --git a/internal/generate/listpages/v2/function.tmpl b/internal/generate/listpages/v2/function.tmpl index 64e76190d895..095b3214bb07 100644 --- a/internal/generate/listpages/v2/function.tmpl +++ b/internal/generate/listpages/v2/function.tmpl @@ -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 { @@ -14,4 +13,4 @@ func {{ .Name }}Pages(ctx context.Context, conn {{ .RecvType }}, input {{ .Param input.{{ .InputPaginator }} = output.{{ .OutputPaginator }} } return nil -} \ No newline at end of file +} diff --git a/internal/service/ec2/errors.go b/internal/service/ec2/errors.go index 3b19bd040d9f..faeccad399fb 100644 --- a/internal/service/ec2/errors.go +++ b/internal/service/ec2/errors.go @@ -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" diff --git a/internal/service/ec2/errorsv2.go b/internal/service/ec2/errorsv2.go new file mode 100644 index 000000000000..b9d9db90bcc1 --- /dev/null +++ b/internal/service/ec2/errorsv2.go @@ -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...) +} diff --git a/internal/service/ec2/exports_test.go b/internal/service/ec2/exports_test.go index 5828e5acb7c1..e5d497c984e3 100644 --- a/internal/service/ec2/exports_test.go +++ b/internal/service/ec2/exports_test.go @@ -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 ( diff --git a/internal/service/ec2/findv2.go b/internal/service/ec2/findv2.go index 7209cc6a925c..a7e8683ffb71 100644 --- a/internal/service/ec2/findv2.go +++ b/internal/service/ec2/findv2.go @@ -12,7 +12,9 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -447,3 +449,546 @@ func FindEBSVolumeV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeV return tfresource.AssertSingleValueResult(output) } + +func findPrefixListV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribePrefixListsInput) (*awstypes.PrefixList, error) { + output, err := findPrefixListsV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + return tfresource.AssertSingleValueResult(output) +} + +func findPrefixListsV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribePrefixListsInput) ([]awstypes.PrefixList, error) { + var output []awstypes.PrefixList + + paginator := ec2.NewDescribePrefixListsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + + if err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidPrefixListIdNotFound) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + return nil, err + } + + output = append(output, page.PrefixLists...) + } + + return output, nil +} + +func findVPCEndpointByIDV2(ctx context.Context, conn *ec2.Client, id string) (*awstypes.VpcEndpoint, error) { + input := &ec2.DescribeVpcEndpointsInput{ + VpcEndpointIds: []string{id}, + } + + output, err := findVPCEndpointV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + if output.State == awstypes.StateDeleted { + return nil, &retry.NotFoundError{ + Message: string(output.State), + LastRequest: input, + } + } + + // Eventual consistency check. + if aws.ToString(output.VpcEndpointId) != id { + return nil, &retry.NotFoundError{ + LastRequest: input, + } + } + + return output, nil +} + +func findVPCEndpointV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointsInput) (*awstypes.VpcEndpoint, error) { + output, err := findVPCEndpointsV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + return tfresource.AssertSingleValueResult(output) +} + +func findVPCEndpointsV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointsInput) ([]awstypes.VpcEndpoint, error) { + var output []awstypes.VpcEndpoint + + paginator := ec2.NewDescribeVpcEndpointsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + + if err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointIdNotFound) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + return nil, err + } + + output = append(output, page.VpcEndpoints...) + } + + return output, nil +} + +func findPrefixListByNameV2(ctx context.Context, conn *ec2.Client, name string) (*awstypes.PrefixList, error) { + input := &ec2.DescribePrefixListsInput{ + Filters: newAttributeFilterListV2(map[string]string{ + "prefix-list-name": name, + }), + } + + return findPrefixListV2(ctx, conn, input) +} + +func findVPCEndpointServiceConfigurationByServiceNameV2(ctx context.Context, conn *ec2.Client, name string) (*awstypes.ServiceConfiguration, error) { + input := &ec2.DescribeVpcEndpointServiceConfigurationsInput{ + Filters: newAttributeFilterListV2(map[string]string{ + "service-name": name, + }), + } + + return findVPCEndpointServiceConfigurationV2(ctx, conn, input) +} + +func findVPCEndpointServiceConfigurationV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointServiceConfigurationsInput) (*awstypes.ServiceConfiguration, error) { + output, err := findVPCEndpointServiceConfigurationsV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + return tfresource.AssertSingleValueResult(output) +} + +func findVPCEndpointServiceConfigurationsV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointServiceConfigurationsInput) ([]awstypes.ServiceConfiguration, error) { + var output []awstypes.ServiceConfiguration + + paginator := ec2.NewDescribeVpcEndpointServiceConfigurationsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + + if err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointServiceIdNotFound) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + return nil, err + } + + output = append(output, page.ServiceConfigurations...) + } + + return output, nil +} + +// findRouteTableByIDV2 returns the route table corresponding to the specified identifier. +// Returns NotFoundError if no route table is found. +func findRouteTableByIDV2(ctx context.Context, conn *ec2.Client, routeTableID string) (*awstypes.RouteTable, error) { + input := &ec2.DescribeRouteTablesInput{ + RouteTableIds: []string{routeTableID}, + } + + return findRouteTableV2(ctx, conn, input) +} + +// routeFinderV2 returns the route corresponding to the specified destination. +// Returns NotFoundError if no route is found. +type routeFinderV2 func(context.Context, *ec2.Client, string, string) (*awstypes.Route, error) + +// findRouteByIPv4DestinationV2 returns the route corresponding to the specified IPv4 destination. +// Returns NotFoundError if no route is found. +func findRouteByIPv4DestinationV2(ctx context.Context, conn *ec2.Client, routeTableID, destinationCidr string) (*awstypes.Route, error) { + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) + + if err != nil { + return nil, err + } + + for _, route := range routeTable.Routes { + if types.CIDRBlocksEqual(aws.ToString(route.DestinationCidrBlock), destinationCidr) { + return &route, nil + } + } + + return nil, &retry.NotFoundError{ + LastError: fmt.Errorf("Route in Route Table (%s) with IPv4 destination (%s) not found", routeTableID, destinationCidr), + } +} + +// findRouteByIPv6DestinationV2 returns the route corresponding to the specified IPv6 destination. +// Returns NotFoundError if no route is found. +func findRouteByIPv6DestinationV2(ctx context.Context, conn *ec2.Client, routeTableID, destinationIpv6Cidr string) (*awstypes.Route, error) { + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) + + if err != nil { + return nil, err + } + + for _, route := range routeTable.Routes { + if types.CIDRBlocksEqual(aws.ToString(route.DestinationIpv6CidrBlock), destinationIpv6Cidr) { + return &route, nil + } + } + + return nil, &retry.NotFoundError{ + LastError: fmt.Errorf("Route in Route Table (%s) with IPv6 destination (%s) not found", routeTableID, destinationIpv6Cidr), + } +} + +// findRouteByPrefixListIDDestinationV2 returns the route corresponding to the specified prefix list destination. +// Returns NotFoundError if no route is found. +func findRouteByPrefixListIDDestinationV2(ctx context.Context, conn *ec2.Client, routeTableID, prefixListID string) (*awstypes.Route, error) { + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) + if err != nil { + return nil, err + } + + for _, route := range routeTable.Routes { + if aws.ToString(route.DestinationPrefixListId) == prefixListID { + return &route, nil + } + } + + return nil, &retry.NotFoundError{ + LastError: fmt.Errorf("Route in Route Table (%s) with Prefix List ID destination (%s) not found", routeTableID, prefixListID), + } +} + +// findRouteTableAssociationByIDV2 returns the route table association corresponding to the specified identifier. +// Returns NotFoundError if no route table association is found. +func findRouteTableAssociationByIDV2(ctx context.Context, conn *ec2.Client, associationID string) (*awstypes.RouteTableAssociation, error) { + input := &ec2.DescribeRouteTablesInput{ + Filters: newAttributeFilterListV2(map[string]string{ + "association.route-table-association-id": associationID, + }), + } + + routeTable, err := findRouteTableV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + for _, association := range routeTable.Associations { + if aws.ToString(association.RouteTableAssociationId) == associationID { + if association.AssociationState != nil { + if state := association.AssociationState.State; state == awstypes.RouteTableAssociationStateCodeDisassociated { + return nil, &retry.NotFoundError{Message: string(state)} + } + } + + return &association, nil + } + } + + return nil, &retry.NotFoundError{} +} + +// findMainRouteTableByVPCIDV2 returns the main route table for the specified VPC. +// Returns NotFoundError if no route table is found. +func findMainRouteTableByVPCIDV2(ctx context.Context, conn *ec2.Client, vpcID string) (*awstypes.RouteTable, error) { + input := &ec2.DescribeRouteTablesInput{ + Filters: newAttributeFilterListV2(map[string]string{ + "association.main": "true", + "vpc-id": vpcID, + }), + } + + return findRouteTableV2(ctx, conn, input) +} + +// findVPNGatewayRoutePropagationExistsV2 returns NotFoundError if no route propagation for the specified VPN gateway is found. +func findVPNGatewayRoutePropagationExistsV2(ctx context.Context, conn *ec2.Client, routeTableID, gatewayID string) error { + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) + + if err != nil { + return err + } + + for _, v := range routeTable.PropagatingVgws { + if aws.ToString(v.GatewayId) == gatewayID { + return nil + } + } + + return &retry.NotFoundError{ + LastError: fmt.Errorf("Route Table (%s) VPN Gateway (%s) route propagation not found", routeTableID, gatewayID), + } +} + +func findVPCEndpointServiceConfigurationByIDV2(ctx context.Context, conn *ec2.Client, id string) (*awstypes.ServiceConfiguration, error) { + input := &ec2.DescribeVpcEndpointServiceConfigurationsInput{ + ServiceIds: []string{id}, + } + + output, err := findVPCEndpointServiceConfigurationV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + if state := output.ServiceState; state == awstypes.ServiceStateDeleted || state == awstypes.ServiceStateFailed { + return nil, &retry.NotFoundError{ + Message: string(state), + LastRequest: input, + } + } + + // Eventual consistency check. + if aws.ToString(output.ServiceId) != id { + return nil, &retry.NotFoundError{ + LastRequest: input, + } + } + + return output, nil +} + +func findVPCEndpointServicePermissionsV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointServicePermissionsInput) ([]awstypes.AllowedPrincipal, error) { + var output []awstypes.AllowedPrincipal + + paginator := ec2.NewDescribeVpcEndpointServicePermissionsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + + if err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointServiceIdNotFound) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + return nil, err + } + + output = append(output, page.AllowedPrincipals...) + } + + return output, nil +} + +func findVPCEndpointServicePermissionsByServiceIDV2(ctx context.Context, conn *ec2.Client, id string) ([]awstypes.AllowedPrincipal, error) { + input := &ec2.DescribeVpcEndpointServicePermissionsInput{ + ServiceId: aws.String(id), + } + + return findVPCEndpointServicePermissionsV2(ctx, conn, input) +} + +func findVPCEndpointServicesV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointServicesInput) ([]awstypes.ServiceDetail, []string, error) { + var serviceDetails []awstypes.ServiceDetail + var serviceNames []string + + err := describeVPCEndpointServicesPagesV2(ctx, conn, input, func(page *ec2.DescribeVpcEndpointServicesOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + serviceDetails = append(serviceDetails, page.ServiceDetails...) + serviceNames = append(serviceNames, page.ServiceNames...) + + return !lastPage + }) + + if tfawserr.ErrCodeEquals(err, errCodeInvalidServiceName) { + return nil, nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, nil, err + } + + return serviceDetails, serviceNames, nil +} + +// findVPCEndpointRouteTableAssociationExistsV2 returns NotFoundError if no association for the specified VPC endpoint and route table IDs is found. +func findVPCEndpointRouteTableAssociationExistsV2(ctx context.Context, conn *ec2.Client, vpcEndpointID string, routeTableID string) error { + vpcEndpoint, err := findVPCEndpointByIDV2(ctx, conn, vpcEndpointID) + + if err != nil { + return err + } + + for _, vpcEndpointRouteTableID := range vpcEndpoint.RouteTableIds { + if vpcEndpointRouteTableID == routeTableID { + return nil + } + } + + return &retry.NotFoundError{ + LastError: fmt.Errorf("VPC Endpoint (%s) Route Table (%s) Association not found", vpcEndpointID, routeTableID), + } +} + +// findVPCEndpointSecurityGroupAssociationExistsV2 returns NotFoundError if no association for the specified VPC endpoint and security group IDs is found. +func findVPCEndpointSecurityGroupAssociationExistsV2(ctx context.Context, conn *ec2.Client, vpcEndpointID, securityGroupID string) error { + vpcEndpoint, err := findVPCEndpointByIDV2(ctx, conn, vpcEndpointID) + + if err != nil { + return err + } + + for _, group := range vpcEndpoint.Groups { + if aws.ToString(group.GroupId) == securityGroupID { + return nil + } + } + + return &retry.NotFoundError{ + LastError: fmt.Errorf("VPC Endpoint (%s) Security Group (%s) Association not found", vpcEndpointID, securityGroupID), + } +} + +// findVPCEndpointSubnetAssociationExistsV2 returns NotFoundError if no association for the specified VPC endpoint and subnet IDs is found. +func findVPCEndpointSubnetAssociationExistsV2(ctx context.Context, conn *ec2.Client, vpcEndpointID string, subnetID string) error { + vpcEndpoint, err := findVPCEndpointByIDV2(ctx, conn, vpcEndpointID) + + if err != nil { + return err + } + + for _, vpcEndpointSubnetID := range vpcEndpoint.SubnetIds { + if vpcEndpointSubnetID == subnetID { + return nil + } + } + + return &retry.NotFoundError{ + LastError: fmt.Errorf("VPC Endpoint (%s) Subnet (%s) Association not found", vpcEndpointID, subnetID), + } +} + +func findVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2(ctx context.Context, conn *ec2.Client, serviceID, vpcEndpointID string) (*awstypes.VpcEndpointConnection, error) { + input := &ec2.DescribeVpcEndpointConnectionsInput{ + Filters: newAttributeFilterListV2(map[string]string{ + "service-id": serviceID, + // "InvalidFilter: The filter vpc-endpoint-id is invalid" + // "vpc-endpoint-id ": vpcEndpointID, + }), + } + + var output *awstypes.VpcEndpointConnection + + paginator := ec2.NewDescribeVpcEndpointConnectionsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + if err != nil { + return nil, err + } + + for _, v := range page.VpcEndpointConnections { + v := v + if aws.ToString(v.VpcEndpointId) == vpcEndpointID { + output = &v + break + } + } + } + + if output == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + if vpcEndpointState := string(output.VpcEndpointState); vpcEndpointState == vpcEndpointStateDeleted { + return nil, &retry.NotFoundError{ + Message: vpcEndpointState, + LastRequest: input, + } + } + + return output, nil +} + +func findVPCEndpointConnectionNotificationV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointConnectionNotificationsInput) (*awstypes.ConnectionNotification, error) { + output, err := findVPCEndpointConnectionNotificationsV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + return tfresource.AssertSingleValueResult(output) +} + +func findVPCEndpointConnectionNotificationsV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointConnectionNotificationsInput) ([]awstypes.ConnectionNotification, error) { + var output []awstypes.ConnectionNotification + + paginator := ec2.NewDescribeVpcEndpointConnectionNotificationsPaginator(conn, input) + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + + if err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidConnectionNotification) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + return nil, err + } + + output = append(output, page.ConnectionNotificationSet...) + } + + return output, nil +} + +func findVPCEndpointConnectionNotificationByIDV2(ctx context.Context, conn *ec2.Client, id string) (*awstypes.ConnectionNotification, error) { + input := &ec2.DescribeVpcEndpointConnectionNotificationsInput{ + ConnectionNotificationId: aws.String(id), + } + + output, err := findVPCEndpointConnectionNotificationV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + // Eventual consistency check. + if aws.ToString(output.ConnectionNotificationId) != id { + return nil, &retry.NotFoundError{ + LastRequest: input, + } + } + + return output, nil +} + +func findVPCEndpointServicePermissionV2(ctx context.Context, conn *ec2.Client, serviceID, principalARN string) (*awstypes.AllowedPrincipal, error) { + // Applying a server-side filter on "principal" can lead to errors like + // "An error occurred (InvalidFilter) when calling the DescribeVpcEndpointServicePermissions operation: The filter value arn:aws:iam::123456789012:role/developer contains unsupported characters". + // Apply the filter client-side. + input := &ec2.DescribeVpcEndpointServicePermissionsInput{ + ServiceId: aws.String(serviceID), + } + + allowedPrincipals, err := findVPCEndpointServicePermissionsV2(ctx, conn, input) + + if err != nil { + return nil, err + } + + allowedPrincipals = tfslices.Filter(allowedPrincipals, func(v awstypes.AllowedPrincipal) bool { + return aws.ToString(v.Principal) == principalARN + }) + + return tfresource.AssertSingleValueResult(allowedPrincipals) +} diff --git a/internal/service/ec2/generate.go b/internal/service/ec2/generate.go index 8cafca14ba11..838aa9c10dd3 100644 --- a/internal/service/ec2/generate.go +++ b/internal/service/ec2/generate.go @@ -5,6 +5,7 @@ //go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsOpPaginated -ListTagsInFiltIDName=resource-id -ListTagsInIDElem=Resources -ServiceTagsSlice -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags //go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -GetTag -ListTagsOp=DescribeTags -ListTagsOpPaginated -ListTagsInFiltIDName=resource-id -ServiceTagsSlice -TagsFunc=TagsV2 -KeyValueTagsFunc=keyValueTagsV2 -GetTagsInFunc=getTagsInV2 -SetTagsOutFunc=setTagsOutV2 -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedValueSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UpdateTagsFunc=updateTagsV2 -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags -- tagsv2_gen.go //go:generate go run ../../generate/listpages/main.go -ListOps=DescribeSpotFleetInstances,DescribeSpotFleetRequestHistory,DescribeVpcEndpointServices +//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeVpcEndpointServices -AWSSDKVersion=2 -V2Suffix list_pagesv2_gen.go //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/ec2/list_pagesv2_gen.go b/internal/service/ec2/list_pagesv2_gen.go new file mode 100644 index 000000000000..c218e13a2301 --- /dev/null +++ b/internal/service/ec2/list_pagesv2_gen.go @@ -0,0 +1,27 @@ +// Code generated by "internal/generate/listpages/main.go -ListOps=DescribeVpcEndpointServices -AWSSDKVersion=2 -V2Suffix list_pagesv2_gen.go"; DO NOT EDIT. + +package ec2 + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" +) + +func describeVPCEndpointServicesPagesV2(ctx context.Context, conn *ec2.Client, input *ec2.DescribeVpcEndpointServicesInput, fn func(*ec2.DescribeVpcEndpointServicesOutput, bool) bool) error { + for { + output, err := conn.DescribeVpcEndpointServices(ctx, input) + if err != nil { + return err + } + + lastPage := aws.ToString(output.NextToken) == "" + if !fn(output, lastPage) || lastPage { + break + } + + input.NextToken = output.NextToken + } + return nil +} diff --git a/internal/service/ec2/status.go b/internal/service/ec2/status.go index 264d2e8cfe2e..936844416705 100644 --- a/internal/service/ec2/status.go +++ b/internal/service/ec2/status.go @@ -1326,22 +1326,6 @@ func StatusEBSSnapshotImport(ctx context.Context, conn *ec2_sdkv2.Client, id str } } -func statusVPCEndpointConnectionVPCEndpointState(ctx context.Context, conn *ec2.EC2, serviceID, vpcEndpointID string) retry.StateRefreshFunc { - return func() (interface{}, string, error) { - output, err := FindVPCEndpointConnectionByServiceIDAndVPCEndpointID(ctx, conn, serviceID, vpcEndpointID) - - if tfresource.NotFound(err) { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - return output, aws.StringValue(output.VpcEndpointState), nil - } -} - func StatusSnapshotStorageTier(ctx context.Context, conn *ec2_sdkv2.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindSnapshotTierStatusBySnapshotID(ctx, conn, id) diff --git a/internal/service/ec2/statusv2.go b/internal/service/ec2/statusv2.go index e269aab94d35..5e21db634709 100644 --- a/internal/service/ec2/statusv2.go +++ b/internal/service/ec2/statusv2.go @@ -92,3 +92,142 @@ func statusNetworkInterfaceAttachmentV2(ctx context.Context, conn *ec2.Client, i return output, string(output.Status), nil } } + +func statusVPCEndpointStateV2(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findVPCEndpointByIDV2(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.State), nil + } +} + +func statusRouteV2(ctx context.Context, conn *ec2.Client, routeFinder routeFinderV2, routeTableID, destination string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := routeFinder(ctx, conn, routeTableID, destination) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, RouteStatusReady, nil + } +} + +func statusRouteTableV2(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findRouteTableByIDV2(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, RouteTableStatusReady, nil + } +} + +func statusRouteTableAssociationStateV2(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findRouteTableAssociationByIDV2(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + if output.AssociationState == nil { + // In ISO partitions AssociationState can be nil. + // If the association has been found then we assume it's associated. + state := awstypes.RouteTableAssociationStateCodeAssociated + + return &awstypes.RouteTableAssociationState{State: state}, string(state), nil + } + + return output.AssociationState, string(output.AssociationState.State), nil + } +} + +func statusVPCEndpointServiceStateAvailableV2(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + // Don't call FindVPCEndpointServiceConfigurationByID as it maps useful status codes to NotFoundError. + output, err := findVPCEndpointServiceConfigurationV2(ctx, conn, &ec2.DescribeVpcEndpointServiceConfigurationsInput{ + ServiceIds: []string{id}, + }) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.ServiceState), nil + } +} + +func statusVPCEndpointServiceStateDeletedV2(ctx context.Context, conn *ec2.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findVPCEndpointServiceConfigurationByIDV2(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.ServiceState), nil + } +} + +func statusVPCEndpointRouteTableAssociationV2(ctx context.Context, conn *ec2.Client, vpcEndpointID, routeTableID string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + err := findVPCEndpointRouteTableAssociationExistsV2(ctx, conn, vpcEndpointID, routeTableID) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return "", VPCEndpointRouteTableAssociationStatusReady, nil + } +} + +func statusVPCEndpointConnectionVPCEndpointStateV2(ctx context.Context, conn *ec2.Client, serviceID, vpcEndpointID string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2(ctx, conn, serviceID, vpcEndpointID) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.VpcEndpointState), nil + } +} diff --git a/internal/service/ec2/vpc_default_route_table.go b/internal/service/ec2/vpc_default_route_table.go index 1f58291e2216..2571be9bbb29 100644 --- a/internal/service/ec2/vpc_default_route_table.go +++ b/internal/service/ec2/vpc_default_route_table.go @@ -8,9 +8,10 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -143,36 +144,36 @@ func resourceDefaultRouteTable() *schema.Resource { func resourceDefaultRouteTableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) routeTableID := d.Get("default_route_table_id").(string) - routeTable, err := FindRouteTableByID(ctx, conn, routeTableID) + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 Default Route Table (%s): %s", routeTableID, err) } - d.SetId(aws.StringValue(routeTable.RouteTableId)) + d.SetId(aws.ToString(routeTable.RouteTableId)) // Remove all existing VGW associations. for _, v := range routeTable.PropagatingVgws { - if err := routeTableDisableVGWRoutePropagation(ctx, conn, d.Id(), aws.StringValue(v.GatewayId)); err != nil { + if err := routeTableDisableVGWRoutePropagation(ctx, conn, d.Id(), aws.ToString(v.GatewayId)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } // Delete all existing routes. for _, v := range routeTable.Routes { - if gatewayID := aws.StringValue(v.GatewayId); gatewayID == gatewayIDLocal || gatewayID == gatewayIDVPCLattice { + if gatewayID := aws.ToString(v.GatewayId); gatewayID == gatewayIDLocal || gatewayID == gatewayIDVPCLattice { continue } - if aws.StringValue(v.Origin) == ec2.RouteOriginEnableVgwRoutePropagation { + if v.Origin == awstypes.RouteOriginEnableVgwRoutePropagation { continue } - if v.DestinationPrefixListId != nil && strings.HasPrefix(aws.StringValue(v.GatewayId), "vpce-") { + if v.DestinationPrefixListId != nil && strings.HasPrefix(aws.ToString(v.GatewayId), "vpce-") { // Skipping because VPC endpoint routes are handled separately // See aws_vpc_endpoint continue @@ -183,23 +184,23 @@ func resourceDefaultRouteTableCreate(ctx context.Context, d *schema.ResourceData } var destination string - var routeFinder RouteFinder + var routeFinder routeFinderV2 if v.DestinationCidrBlock != nil { input.DestinationCidrBlock = v.DestinationCidrBlock - destination = aws.StringValue(v.DestinationCidrBlock) - routeFinder = FindRouteByIPv4Destination + destination = aws.ToString(v.DestinationCidrBlock) + routeFinder = findRouteByIPv4DestinationV2 } else if v.DestinationIpv6CidrBlock != nil { input.DestinationIpv6CidrBlock = v.DestinationIpv6CidrBlock - destination = aws.StringValue(v.DestinationIpv6CidrBlock) - routeFinder = FindRouteByIPv6Destination + destination = aws.ToString(v.DestinationIpv6CidrBlock) + routeFinder = findRouteByIPv6DestinationV2 } else if v.DestinationPrefixListId != nil { input.DestinationPrefixListId = v.DestinationPrefixListId - destination = aws.StringValue(v.DestinationPrefixListId) - routeFinder = FindRouteByPrefixListIDDestination + destination = aws.ToString(v.DestinationPrefixListId) + routeFinder = findRouteByPrefixListIDDestinationV2 } - _, err := conn.DeleteRouteWithContext(ctx, input) + _, err := conn.DeleteRoute(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteNotFound) { continue @@ -209,7 +210,7 @@ func resourceDefaultRouteTableCreate(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendErrorf(diags, "deleting Route in EC2 Default Route Table (%s) with destination (%s): %s", d.Id(), destination, err) } - if _, err := WaitRouteDeleted(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitRouteDeletedV2(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route in EC2 Default Route Table (%s) with destination (%s) delete: %s", d.Id(), destination, err) } } @@ -236,7 +237,7 @@ func resourceDefaultRouteTableCreate(ctx context.Context, d *schema.ResourceData } } - if err := createTags(ctx, conn, d.Id(), getTagsIn(ctx)); err != nil { + if err := createTagsV2(ctx, conn, d.Id(), getTagsInV2(ctx)); err != nil { return sdkdiag.AppendErrorf(diags, "setting EC2 Default Route Table (%s) tags: %s", d.Id(), err) } @@ -252,15 +253,15 @@ func resourceDefaultRouteTableRead(ctx context.Context, d *schema.ResourceData, } func resourceDefaultRouteTableImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - routeTable, err := FindMainRouteTableByVPCID(ctx, conn, d.Id()) + routeTable, err := findMainRouteTableByVPCIDV2(ctx, conn, d.Id()) if err != nil { return nil, err } - d.SetId(aws.StringValue(routeTable.RouteTableId)) + d.SetId(aws.ToString(routeTable.RouteTableId)) return []*schema.ResourceData{d}, nil } diff --git a/internal/service/ec2/vpc_default_route_table_test.go b/internal/service/ec2/vpc_default_route_table_test.go index fc8f65e45bf5..5f9c8d3b3298 100644 --- a/internal/service/ec2/vpc_default_route_table_test.go +++ b/internal/service/ec2/vpc_default_route_table_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/aws/aws-sdk-go/service/elbv2" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -24,7 +24,7 @@ import ( func TestAccVPCDefaultRouteTable_basic(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" vpcResourceName := "aws_vpc.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -69,8 +69,8 @@ func TestAccVPCDefaultRouteTable_basic(t *testing.T) { func TestAccVPCDefaultRouteTable_Disappears_vpc(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_default_route_table.test" vpcResourceName := "aws_vpc.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -85,7 +85,7 @@ func TestAccVPCDefaultRouteTable_Disappears_vpc(t *testing.T) { Config: testAccVPCDefaultRouteTableConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckRouteTableExists(ctx, resourceName, &routeTable), - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), acctest.CheckResourceDisappears(ctx, acctest.Provider, tfec2.ResourceVPC(), vpcResourceName), ), ExpectNonEmptyPlan: true, @@ -96,7 +96,7 @@ func TestAccVPCDefaultRouteTable_Disappears_vpc(t *testing.T) { func TestAccVPCDefaultRouteTable_Route_mode(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -165,7 +165,7 @@ func TestAccVPCDefaultRouteTable_Route_mode(t *testing.T) { func TestAccVPCDefaultRouteTable_swap(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" igwResourceName := "aws_internet_gateway.test" rtResourceName := "aws_route_table.test" @@ -238,7 +238,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToTransitGateway(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" tgwResourceName := "aws_ec2_transit_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -275,7 +275,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToVPCEndpoint(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" vpceResourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -283,7 +283,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToVPCEndpoint(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"), + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID, "elasticloadbalancing"), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckRouteTableDestroy(ctx), Steps: []resource.TestStep{ @@ -317,7 +317,7 @@ func TestAccVPCDefaultRouteTable_ipv4ToVPCEndpoint(t *testing.T) { func TestAccVPCDefaultRouteTable_vpcEndpointAssociation(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -350,7 +350,7 @@ func TestAccVPCDefaultRouteTable_vpcEndpointAssociation(t *testing.T) { func TestAccVPCDefaultRouteTable_tags(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -391,7 +391,7 @@ func TestAccVPCDefaultRouteTable_tags(t *testing.T) { func TestAccVPCDefaultRouteTable_conditionalCIDRBlock(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -430,7 +430,7 @@ func TestAccVPCDefaultRouteTable_conditionalCIDRBlock(t *testing.T) { func TestAccVPCDefaultRouteTable_prefixListToInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" igwResourceName := "aws_internet_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -472,7 +472,7 @@ func TestAccVPCDefaultRouteTable_prefixListToInternetGateway(t *testing.T) { func TestAccVPCDefaultRouteTable_revokeExistingRules(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_default_route_table.test" rtResourceName := "aws_route_table.test" eoigwResourceName := "aws_egress_only_internet_gateway.test" @@ -534,14 +534,14 @@ func TestAccVPCDefaultRouteTable_revokeExistingRules(t *testing.T) { func testAccCheckDefaultRouteTableDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_default_route_table" { continue } - _, err := tfec2.FindRouteTableByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindRouteTableByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -1260,7 +1260,7 @@ func testAccPreCheckELBv2GatewayLoadBalancer(ctx context.Context, t *testing.T) continue } - if aws.StringValue(limit.Name) == "gateway-load-balancers" { + if aws.ToString(limit.Name) == "gateway-load-balancers" { return } } diff --git a/internal/service/ec2/vpc_endpoint.go b/internal/service/ec2/vpc_endpoint.go index 6a4ba815a0a5..6a8b356e1c57 100644 --- a/internal/service/ec2/vpc_endpoint.go +++ b/internal/service/ec2/vpc_endpoint.go @@ -10,10 +10,11 @@ import ( "regexp" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" awspolicy "github.com/hashicorp/awspolicyequivalence" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -21,6 +22,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/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" @@ -87,10 +89,10 @@ func ResourceVPCEndpoint() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "dns_record_ip_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(ec2.DnsRecordIpType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.DnsRecordIpType](), }, "private_dns_only_for_inbound_resolver_endpoint": { Type: schema.TypeBool, @@ -100,10 +102,10 @@ func ResourceVPCEndpoint() *schema.Resource { }, }, names.AttrIPAddressType: { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(ec2.IpAddressType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.IpAddressType](), }, "network_interface_ids": { Type: schema.TypeSet, @@ -169,11 +171,11 @@ func ResourceVPCEndpoint() *schema.Resource { names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpc_endpoint_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: ec2.VpcEndpointTypeGateway, - ValidateFunc: validation.StringInSlice(ec2.VpcEndpointType_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: awstypes.VpcEndpointTypeGateway, + ValidateDiagFunc: enum.Validate[awstypes.VpcEndpointType](), }, names.AttrVPCID: { Type: schema.TypeString, @@ -194,15 +196,16 @@ func ResourceVPCEndpoint() *schema.Resource { func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) + partition := meta.(*conns.AWSClient).Partition serviceName := d.Get(names.AttrServiceName).(string) input := &ec2.CreateVpcEndpointInput{ ClientToken: aws.String(id.UniqueId()), PrivateDnsEnabled: aws.Bool(d.Get("private_dns_enabled").(bool)), ServiceName: aws.String(serviceName), - TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeVpcEndpoint), - VpcEndpointType: aws.String(d.Get("vpc_endpoint_type").(string)), + TagSpecifications: getTagSpecificationsInV2(ctx, awstypes.ResourceTypeVpcEndpoint), + VpcEndpointType: awstypes.VpcEndpointType(d.Get("vpc_endpoint_type").(string)), VpcId: aws.String(d.Get(names.AttrVPCID).(string)), } @@ -217,7 +220,7 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk(names.AttrIPAddressType); ok { - input.IpAddressType = aws.String(v.(string)) + input.IpAddressType = awstypes.IpAddressType(v.(string)) } if v, ok := d.GetOk(names.AttrPolicy); ok { @@ -231,23 +234,23 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk("route_table_ids"); ok && v.(*schema.Set).Len() > 0 { - input.RouteTableIds = flex.ExpandStringSet(v.(*schema.Set)) + input.RouteTableIds = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk(names.AttrSecurityGroupIDs); ok && v.(*schema.Set).Len() > 0 { - input.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroupIds = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk(names.AttrSubnetIDs); ok && v.(*schema.Set).Len() > 0 { - input.SubnetIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SubnetIds = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateVpcEndpointWithContext(ctx, input) + output, err := conn.CreateVpcEndpoint(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.TagSpecifications != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.TagSpecifications != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.TagSpecifications = nil - output, err = conn.CreateVpcEndpointWithContext(ctx, input) + output, err = conn.CreateVpcEndpoint(ctx, input) } if err != nil { @@ -255,24 +258,24 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta } vpce := output.VpcEndpoint - d.SetId(aws.StringValue(vpce.VpcEndpointId)) + d.SetId(aws.ToString(vpce.VpcEndpointId)) - if d.Get("auto_accept").(bool) && aws.StringValue(vpce.State) == vpcEndpointStatePendingAcceptance { - if err := vpcEndpointAccept(ctx, conn, d.Id(), aws.StringValue(vpce.ServiceName), d.Timeout(schema.TimeoutCreate)); err != nil { + if d.Get("auto_accept").(bool) && string(vpce.State) == vpcEndpointStatePendingAcceptance { + if err := vpcEndpointAccept(ctx, conn, d.Id(), aws.ToString(vpce.ServiceName), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } - if _, err = WaitVPCEndpointAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err = waitVPCEndpointAvailableV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint (%s) create: %s", serviceName, err) } // For partitions not supporting tag-on-create, attempt tag after create. - if tags := getTagsIn(ctx); input.TagSpecifications == nil && len(tags) > 0 { - err := createTags(ctx, conn, d.Id(), tags) + if tags := getTagsInV2(ctx); input.TagSpecifications == nil && len(tags) > 0 { + err := createTagsV2(ctx, conn, d.Id(), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceVPCEndpointRead(ctx, d, meta)...) } @@ -286,9 +289,9 @@ func resourceVPCEndpointCreate(ctx context.Context, d *schema.ResourceData, meta func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - vpce, err := FindVPCEndpointByID(ctx, conn, d.Id()) + vpce, err := findVPCEndpointByIDV2(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] VPC Endpoint (%s) not found, removing from state", d.Id()) @@ -302,12 +305,12 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, - AccountID: aws.StringValue(vpce.OwnerId), + AccountID: aws.ToString(vpce.OwnerId), Resource: fmt.Sprintf("vpc-endpoint/%s", d.Id()), }.String() - serviceName := aws.StringValue(vpce.ServiceName) + serviceName := aws.ToString(vpce.ServiceName) d.Set(names.AttrARN, arn) if err := d.Set("dns_entry", flattenDNSEntries(vpce.DnsEntries)); err != nil { return sdkdiag.AppendErrorf(diags, "setting dns_entry: %s", err) @@ -320,35 +323,35 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("dns_options", nil) } d.Set(names.AttrIPAddressType, vpce.IpAddressType) - d.Set("network_interface_ids", aws.StringValueSlice(vpce.NetworkInterfaceIds)) + d.Set("network_interface_ids", vpce.NetworkInterfaceIds) d.Set(names.AttrOwnerID, vpce.OwnerId) d.Set("private_dns_enabled", vpce.PrivateDnsEnabled) d.Set("requester_managed", vpce.RequesterManaged) - d.Set("route_table_ids", aws.StringValueSlice(vpce.RouteTableIds)) + d.Set("route_table_ids", vpce.RouteTableIds) d.Set(names.AttrSecurityGroupIDs, flattenSecurityGroupIdentifiers(vpce.Groups)) d.Set(names.AttrServiceName, serviceName) d.Set(names.AttrState, vpce.State) - d.Set(names.AttrSubnetIDs, aws.StringValueSlice(vpce.SubnetIds)) + d.Set(names.AttrSubnetIDs, vpce.SubnetIds) // VPC endpoints don't have types in GovCloud, so set type to default if empty - if v := aws.StringValue(vpce.VpcEndpointType); v == "" { - d.Set("vpc_endpoint_type", ec2.VpcEndpointTypeGateway) + if v := string(vpce.VpcEndpointType); v == "" { + d.Set("vpc_endpoint_type", awstypes.VpcEndpointTypeGateway) } else { d.Set("vpc_endpoint_type", v) } d.Set(names.AttrVPCID, vpce.VpcId) - if pl, err := FindPrefixListByName(ctx, conn, serviceName); err != nil { + if pl, err := findPrefixListByNameV2(ctx, conn, serviceName); err != nil { if tfresource.NotFound(err) { d.Set("cidr_blocks", nil) } else { return sdkdiag.AppendErrorf(diags, "reading EC2 Prefix List (%s): %s", serviceName, err) } } else { - d.Set("cidr_blocks", aws.StringValueSlice(pl.Cidrs)) + d.Set("cidr_blocks", pl.Cidrs) d.Set("prefix_list_id", pl.PrefixListId) } - policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get(names.AttrPolicy).(string), aws.StringValue(vpce.PolicyDocument)) + policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get(names.AttrPolicy).(string), aws.ToString(vpce.PolicyDocument)) if err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -362,14 +365,14 @@ func resourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrPolicy, policyToSet) - setTagsOut(ctx, vpce.Tags) + setTagsOutV2(ctx, vpce.Tags) return diags } func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) if d.HasChange("auto_accept") && d.Get("auto_accept").(bool) && d.Get(names.AttrState).(string) == vpcEndpointStatePendingAcceptance { if err := vpcEndpointAccept(ctx, conn, d.Id(), d.Get(names.AttrServiceName).(string), d.Timeout(schema.TimeoutUpdate)); err != nil { @@ -397,16 +400,16 @@ func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta } if d.HasChange(names.AttrIPAddressType) { - input.IpAddressType = aws.String(d.Get(names.AttrIPAddressType).(string)) + input.IpAddressType = awstypes.IpAddressType(d.Get(names.AttrIPAddressType).(string)) } if d.HasChange("private_dns_enabled") { input.PrivateDnsEnabled = aws.Bool(privateDNSEnabled) } - input.AddRouteTableIds, input.RemoveRouteTableIds = flattenAddAndRemoveStringLists(d, "route_table_ids") - input.AddSecurityGroupIds, input.RemoveSecurityGroupIds = flattenAddAndRemoveStringLists(d, names.AttrSecurityGroupIDs) - input.AddSubnetIds, input.RemoveSubnetIds = flattenAddAndRemoveStringLists(d, names.AttrSubnetIDs) + input.AddRouteTableIds, input.RemoveRouteTableIds = flattenAddAndRemoveStringValueLists(d, "route_table_ids") + input.AddSecurityGroupIds, input.RemoveSecurityGroupIds = flattenAddAndRemoveStringValueLists(d, names.AttrSecurityGroupIDs) + input.AddSubnetIds, input.RemoveSubnetIds = flattenAddAndRemoveStringValueLists(d, names.AttrSubnetIDs) if d.HasChange(names.AttrPolicy) { o, n := d.GetChange(names.AttrPolicy) @@ -426,13 +429,13 @@ func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta } } - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating EC2 VPC Endpoint (%s): %s", d.Id(), err) } - if _, err := WaitVPCEndpointAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := waitVPCEndpointAvailableV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint (%s) update: %s", d.Id(), err) } } @@ -442,15 +445,15 @@ func resourceVPCEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) log.Printf("[DEBUG] Deleting EC2 VPC Endpoint: %s", d.Id()) - output, err := conn.DeleteVpcEndpointsWithContext(ctx, &ec2.DeleteVpcEndpointsInput{ - VpcEndpointIds: aws.StringSlice([]string{d.Id()}), + output, err := conn.DeleteVpcEndpoints(ctx, &ec2.DeleteVpcEndpointsInput{ + VpcEndpointIds: []string{d.Id()}, }) if err == nil && output != nil { - err = UnsuccessfulItemsError(output.Unsuccessful) + err = unsuccessfulItemsErrorV2(output.Unsuccessful) } if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointNotFound) { @@ -461,15 +464,15 @@ func resourceVPCEndpointDelete(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "deleting EC2 VPC Endpoint (%s): %s", d.Id(), err) } - if _, err = WaitVPCEndpointDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err = waitVPCEndpointDeletedV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint (%s) delete: %s", d.Id(), err) } return diags } -func vpcEndpointAccept(ctx context.Context, conn *ec2.EC2, vpceID, serviceName string, timeout time.Duration) error { - serviceConfiguration, err := FindVPCEndpointServiceConfigurationByServiceName(ctx, conn, serviceName) +func vpcEndpointAccept(ctx context.Context, conn *ec2.Client, vpceID, serviceName string, timeout time.Duration) error { + serviceConfiguration, err := findVPCEndpointServiceConfigurationByServiceNameV2(ctx, conn, serviceName) if err != nil { return fmt.Errorf("reading EC2 VPC Endpoint Service Configuration (%s): %w", serviceName, err) @@ -477,16 +480,16 @@ func vpcEndpointAccept(ctx context.Context, conn *ec2.EC2, vpceID, serviceName s input := &ec2.AcceptVpcEndpointConnectionsInput{ ServiceId: serviceConfiguration.ServiceId, - VpcEndpointIds: aws.StringSlice([]string{vpceID}), + VpcEndpointIds: []string{vpceID}, } - _, err = conn.AcceptVpcEndpointConnectionsWithContext(ctx, input) + _, err = conn.AcceptVpcEndpointConnections(ctx, input) if err != nil { return fmt.Errorf("accepting EC2 VPC Endpoint (%s) connection: %w", vpceID, err) } - if _, err = WaitVPCEndpointAccepted(ctx, conn, vpceID, timeout); err != nil { + if _, err = waitVPCEndpointAcceptedV2(ctx, conn, vpceID, timeout); err != nil { return fmt.Errorf("waiting for EC2 VPC Endpoint (%s) acceptance: %w", vpceID, err) } @@ -498,29 +501,29 @@ func isAmazonS3VPCEndpoint(serviceName string) bool { return ok } -func expandDNSOptionsSpecification(tfMap map[string]interface{}) *ec2.DnsOptionsSpecification { +func expandDNSOptionsSpecification(tfMap map[string]interface{}) *awstypes.DnsOptionsSpecification { if tfMap == nil { return nil } - apiObject := &ec2.DnsOptionsSpecification{} + apiObject := &awstypes.DnsOptionsSpecification{} if v, ok := tfMap["dns_record_ip_type"].(string); ok && v != "" { - apiObject.DnsRecordIpType = aws.String(v) + apiObject.DnsRecordIpType = awstypes.DnsRecordIpType(v) } return apiObject } -func expandDNSOptionsSpecificationWithPrivateDNSOnly(tfMap map[string]interface{}) *ec2.DnsOptionsSpecification { +func expandDNSOptionsSpecificationWithPrivateDNSOnly(tfMap map[string]interface{}) *awstypes.DnsOptionsSpecification { if tfMap == nil { return nil } - apiObject := &ec2.DnsOptionsSpecification{} + apiObject := &awstypes.DnsOptionsSpecification{} if v, ok := tfMap["dns_record_ip_type"].(string); ok && v != "" { - apiObject.DnsRecordIpType = aws.String(v) + apiObject.DnsRecordIpType = awstypes.DnsRecordIpType(v) } if v, ok := tfMap["private_dns_only_for_inbound_resolver_endpoint"].(bool); ok { @@ -530,7 +533,7 @@ func expandDNSOptionsSpecificationWithPrivateDNSOnly(tfMap map[string]interface{ return apiObject } -func flattenDNSEntry(apiObject *ec2.DnsEntry) map[string]interface{} { +func flattenDNSEntry(apiObject *awstypes.DnsEntry) map[string]interface{} { if apiObject == nil { return nil } @@ -538,17 +541,17 @@ func flattenDNSEntry(apiObject *ec2.DnsEntry) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.DnsName; v != nil { - tfMap[names.AttrDNSName] = aws.StringValue(v) + tfMap[names.AttrDNSName] = aws.ToString(v) } if v := apiObject.HostedZoneId; v != nil { - tfMap[names.AttrHostedZoneID] = aws.StringValue(v) + tfMap[names.AttrHostedZoneID] = aws.ToString(v) } return tfMap } -func flattenDNSEntries(apiObjects []*ec2.DnsEntry) []interface{} { +func flattenDNSEntries(apiObjects []awstypes.DnsEntry) []interface{} { if len(apiObjects) == 0 { return nil } @@ -556,35 +559,29 @@ func flattenDNSEntries(apiObjects []*ec2.DnsEntry) []interface{} { var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenDNSEntry(apiObject)) + tfList = append(tfList, flattenDNSEntry(&apiObject)) } return tfList } -func flattenDNSOptions(apiObject *ec2.DnsOptions) map[string]interface{} { +func flattenDNSOptions(apiObject *awstypes.DnsOptions) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.DnsRecordIpType; v != nil { - tfMap["dns_record_ip_type"] = aws.StringValue(v) + tfMap := map[string]interface{}{ + "dns_record_ip_type": string(apiObject.DnsRecordIpType), } if v := apiObject.PrivateDnsOnlyForInboundResolverEndpoint; v != nil { - tfMap["private_dns_only_for_inbound_resolver_endpoint"] = aws.BoolValue(v) + tfMap["private_dns_only_for_inbound_resolver_endpoint"] = aws.ToBool(v) } return tfMap } -func flattenSecurityGroupIdentifiers(apiObjects []*ec2.SecurityGroupIdentifier) []string { +func flattenSecurityGroupIdentifiers(apiObjects []awstypes.SecurityGroupIdentifier) []string { if len(apiObjects) == 0 { return nil } @@ -592,32 +589,28 @@ func flattenSecurityGroupIdentifiers(apiObjects []*ec2.SecurityGroupIdentifier) var tfList []string for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, aws.StringValue(apiObject.GroupId)) + tfList = append(tfList, aws.ToString(apiObject.GroupId)) } return tfList } -func flattenAddAndRemoveStringLists(d *schema.ResourceData, key string) ([]*string, []*string) { +func flattenAddAndRemoveStringValueLists(d *schema.ResourceData, key string) ([]string, []string) { if !d.HasChange(key) { return nil, nil } - var add, del []*string + var add, del []string o, n := d.GetChange(key) os := o.(*schema.Set) ns := n.(*schema.Set) - if v := flex.ExpandStringSet(ns.Difference(os)); len(v) > 0 { + if v := flex.ExpandStringValueSet(ns.Difference(os)); len(v) > 0 { add = v } - if v := flex.ExpandStringSet(os.Difference(ns)); len(v) > 0 { + if v := flex.ExpandStringValueSet(os.Difference(ns)); len(v) > 0 { del = v } diff --git a/internal/service/ec2/vpc_endpoint_connection_accepter.go b/internal/service/ec2/vpc_endpoint_connection_accepter.go index f2a10a4e6c6a..d97e32a25651 100644 --- a/internal/service/ec2/vpc_endpoint_connection_accepter.go +++ b/internal/service/ec2/vpc_endpoint_connection_accepter.go @@ -9,9 +9,9 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -52,18 +52,18 @@ func ResourceVPCEndpointConnectionAccepter() *schema.Resource { func resourceVPCEndpointConnectionAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID := d.Get("vpc_endpoint_service_id").(string) vpcEndpointID := d.Get(names.AttrVPCEndpointID).(string) id := VPCEndpointConnectionAccepterCreateResourceID(serviceID, vpcEndpointID) input := &ec2.AcceptVpcEndpointConnectionsInput{ ServiceId: aws.String(serviceID), - VpcEndpointIds: aws.StringSlice([]string{vpcEndpointID}), + VpcEndpointIds: []string{vpcEndpointID}, } - log.Printf("[DEBUG] Accepting VPC Endpoint Connection: %s", input) - _, err := conn.AcceptVpcEndpointConnectionsWithContext(ctx, input) + log.Printf("[DEBUG] Accepting VPC Endpoint Connection: %v", input) + _, err := conn.AcceptVpcEndpointConnections(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "accepting VPC Endpoint Connection (%s): %s", id, err) @@ -71,7 +71,7 @@ func resourceVPCEndpointConnectionAccepterCreate(ctx context.Context, d *schema. d.SetId(id) - _, err = waitVPCEndpointConnectionAccepted(ctx, conn, serviceID, vpcEndpointID, d.Timeout(schema.TimeoutCreate)) + _, err = waitVPCEndpointConnectionAcceptedV2(ctx, conn, serviceID, vpcEndpointID, d.Timeout(schema.TimeoutCreate)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint Connection (%s) to be accepted: %s", d.Id(), err) @@ -82,14 +82,14 @@ func resourceVPCEndpointConnectionAccepterCreate(ctx context.Context, d *schema. func resourceVPCEndpointConnectionAccepterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID, vpcEndpointID, err := VPCEndpointConnectionAccepterParseResourceID(d.Id()) if err != nil { return sdkdiag.AppendFromErr(diags, err) } - vpcEndpointConnection, err := FindVPCEndpointConnectionByServiceIDAndVPCEndpointID(ctx, conn, serviceID, vpcEndpointID) + vpcEndpointConnection, err := findVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2(ctx, conn, serviceID, vpcEndpointID) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] VPC Endpoint Connection %s not found, removing from state", d.Id()) @@ -110,7 +110,7 @@ func resourceVPCEndpointConnectionAccepterRead(ctx context.Context, d *schema.Re func resourceVPCEndpointConnectionAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID, vpcEndpointID, err := VPCEndpointConnectionAccepterParseResourceID(d.Id()) if err != nil { @@ -118,9 +118,9 @@ func resourceVPCEndpointConnectionAccepterDelete(ctx context.Context, d *schema. } log.Printf("[DEBUG] Rejecting VPC Endpoint Connection: %s", d.Id()) - _, err = conn.RejectVpcEndpointConnectionsWithContext(ctx, &ec2.RejectVpcEndpointConnectionsInput{ + _, err = conn.RejectVpcEndpointConnections(ctx, &ec2.RejectVpcEndpointConnectionsInput{ ServiceId: aws.String(serviceID), - VpcEndpointIds: aws.StringSlice([]string{vpcEndpointID}), + VpcEndpointIds: []string{vpcEndpointID}, }) if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointServiceIdNotFound) { diff --git a/internal/service/ec2/vpc_endpoint_connection_accepter_test.go b/internal/service/ec2/vpc_endpoint_connection_accepter_test.go index ab1dbb6beafa..a771b75d9c87 100644 --- a/internal/service/ec2/vpc_endpoint_connection_accepter_test.go +++ b/internal/service/ec2/vpc_endpoint_connection_accepter_test.go @@ -50,7 +50,7 @@ func TestAccVPCEndpointConnectionAccepter_crossAccount(t *testing.T) { func testAccCheckVPCEndpointConnectionAccepterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_connection_accepter" { @@ -63,7 +63,7 @@ func testAccCheckVPCEndpointConnectionAccepterDestroy(ctx context.Context) resou return err } - _, err = tfec2.FindVPCEndpointConnectionByServiceIDAndVPCEndpointID(ctx, conn, serviceID, vpcEndpointID) + _, err = tfec2.FindVPCEndpointConnectionByServiceIDAndVPCEndpointIDV2(ctx, conn, serviceID, vpcEndpointID) if tfresource.NotFound(err) { continue diff --git a/internal/service/ec2/vpc_endpoint_connection_notification.go b/internal/service/ec2/vpc_endpoint_connection_notification.go index dd98feb4473c..a2adcc9a566f 100644 --- a/internal/service/ec2/vpc_endpoint_connection_notification.go +++ b/internal/service/ec2/vpc_endpoint_connection_notification.go @@ -7,9 +7,9 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -71,11 +71,11 @@ func ResourceVPCEndpointConnectionNotification() *schema.Resource { func resourceVPCEndpointConnectionNotificationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.CreateVpcEndpointConnectionNotificationInput{ ClientToken: aws.String(id.UniqueId()), - ConnectionEvents: flex.ExpandStringSet(d.Get("connection_events").(*schema.Set)), + ConnectionEvents: flex.ExpandStringValueSet(d.Get("connection_events").(*schema.Set)), ConnectionNotificationArn: aws.String(d.Get("connection_notification_arn").(string)), } @@ -87,22 +87,22 @@ func resourceVPCEndpointConnectionNotificationCreate(ctx context.Context, d *sch input.VpcEndpointId = aws.String(v.(string)) } - output, err := conn.CreateVpcEndpointConnectionNotificationWithContext(ctx, input) + output, err := conn.CreateVpcEndpointConnectionNotification(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating EC2 VPC Endpoint Connection Notification: %s", err) } - d.SetId(aws.StringValue(output.ConnectionNotification.ConnectionNotificationId)) + d.SetId(aws.ToString(output.ConnectionNotification.ConnectionNotificationId)) return append(diags, resourceVPCEndpointConnectionNotificationRead(ctx, d, meta)...) } func resourceVPCEndpointConnectionNotificationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - cn, err := FindVPCConnectionNotificationByID(ctx, conn, d.Id()) + cn, err := findVPCEndpointConnectionNotificationByIDV2(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EC2 VPC Endpoint Connection Notification %s not found, removing from state", d.Id()) @@ -114,7 +114,7 @@ func resourceVPCEndpointConnectionNotificationRead(ctx context.Context, d *schem return sdkdiag.AppendErrorf(diags, "reading EC2 VPC Endpoint Connection Notification (%s): %s", d.Id(), err) } - d.Set("connection_events", aws.StringValueSlice(cn.ConnectionEvents)) + d.Set("connection_events", cn.ConnectionEvents) d.Set("connection_notification_arn", cn.ConnectionNotificationArn) d.Set("notification_type", cn.ConnectionNotificationType) d.Set(names.AttrState, cn.ConnectionNotificationState) @@ -126,21 +126,21 @@ func resourceVPCEndpointConnectionNotificationRead(ctx context.Context, d *schem func resourceVPCEndpointConnectionNotificationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.ModifyVpcEndpointConnectionNotificationInput{ ConnectionNotificationId: aws.String(d.Id()), } if d.HasChange("connection_events") { - input.ConnectionEvents = flex.ExpandStringSet(d.Get("connection_events").(*schema.Set)) + input.ConnectionEvents = flex.ExpandStringValueSet(d.Get("connection_events").(*schema.Set)) } if d.HasChange("connection_notification_arn") { input.ConnectionNotificationArn = aws.String(d.Get("connection_notification_arn").(string)) } - _, err := conn.ModifyVpcEndpointConnectionNotificationWithContext(ctx, input) + _, err := conn.ModifyVpcEndpointConnectionNotification(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating EC2 VPC Endpoint Connection Notification (%s): %s", d.Id(), err) @@ -151,11 +151,11 @@ func resourceVPCEndpointConnectionNotificationUpdate(ctx context.Context, d *sch func resourceVPCEndpointConnectionNotificationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) log.Printf("[DEBUG] Deleting EC2 VPC Endpoint Connection Notification: %s", d.Id()) - _, err := conn.DeleteVpcEndpointConnectionNotificationsWithContext(ctx, &ec2.DeleteVpcEndpointConnectionNotificationsInput{ - ConnectionNotificationIds: aws.StringSlice([]string{d.Id()}), + _, err := conn.DeleteVpcEndpointConnectionNotifications(ctx, &ec2.DeleteVpcEndpointConnectionNotificationsInput{ + ConnectionNotificationIds: []string{d.Id()}, }) if tfawserr.ErrCodeEquals(err, errCodeInvalidConnectionNotification) { diff --git a/internal/service/ec2/vpc_endpoint_connection_notification_test.go b/internal/service/ec2/vpc_endpoint_connection_notification_test.go index ca1728544497..ff444d6a5513 100644 --- a/internal/service/ec2/vpc_endpoint_connection_notification_test.go +++ b/internal/service/ec2/vpc_endpoint_connection_notification_test.go @@ -58,14 +58,14 @@ func TestAccVPCEndpointConnectionNotification_basic(t *testing.T) { func testAccCheckVPCEndpointConnectionNotificationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_connection_notification" { continue } - _, err := tfec2.FindVPCConnectionNotificationByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindVPCEndpointConnectionNotificationByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -93,9 +93,9 @@ func testAccCheckVPCEndpointConnectionNotificationExists(ctx context.Context, n return fmt.Errorf("No EC2 VPC Endpoint Connection Notification ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - _, err := tfec2.FindVPCConnectionNotificationByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindVPCEndpointConnectionNotificationByIDV2(ctx, conn, rs.Primary.ID) return err } diff --git a/internal/service/ec2/vpc_endpoint_data_source.go b/internal/service/ec2/vpc_endpoint_data_source.go index e43dfc8ba91a..2348b52c3414 100644 --- a/internal/service/ec2/vpc_endpoint_data_source.go +++ b/internal/service/ec2/vpc_endpoint_data_source.go @@ -8,9 +8,10 @@ import ( "fmt" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" @@ -148,11 +149,11 @@ func DataSourceVPCEndpoint() *schema.Resource { func dataSourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig input := &ec2.DescribeVpcEndpointsInput{ - Filters: newAttributeFilterList( + Filters: newAttributeFilterListV2( map[string]string{ "vpc-endpoint-state": d.Get(names.AttrState).(string), "vpc-id": d.Get(names.AttrVPCID).(string), @@ -162,13 +163,13 @@ func dataSourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk(names.AttrID); ok { - input.VpcEndpointIds = aws.StringSlice([]string{v.(string)}) + input.VpcEndpointIds = []string{v.(string)} } - input.Filters = append(input.Filters, newTagFilterList( - Tags(tftags.New(ctx, d.Get(names.AttrTags).(map[string]interface{}))), + input.Filters = append(input.Filters, newTagFilterListV2( + TagsV2(tftags.New(ctx, d.Get(names.AttrTags).(map[string]interface{}))), )...) - input.Filters = append(input.Filters, newCustomFilterList( + input.Filters = append(input.Filters, newCustomFilterListV2( d.Get(names.AttrFilter).(*schema.Set), )...) if len(input.Filters) == 0 { @@ -176,22 +177,22 @@ func dataSourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta input.Filters = nil } - vpce, err := FindVPCEndpoint(ctx, conn, input) + vpce, err := findVPCEndpointV2(ctx, conn, input) if err != nil { return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("EC2 VPC Endpoint", err)) } - d.SetId(aws.StringValue(vpce.VpcEndpointId)) + d.SetId(aws.ToString(vpce.VpcEndpointId)) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, - AccountID: aws.StringValue(vpce.OwnerId), + AccountID: aws.ToString(vpce.OwnerId), Resource: fmt.Sprintf("vpc-endpoint/%s", d.Id()), }.String() - serviceName := aws.StringValue(vpce.ServiceName) + serviceName := aws.ToString(vpce.ServiceName) d.Set(names.AttrARN, arn) if err := d.Set("dns_entry", flattenDNSEntries(vpce.DnsEntries)); err != nil { @@ -205,35 +206,35 @@ func dataSourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta d.Set("dns_options", nil) } d.Set(names.AttrIPAddressType, vpce.IpAddressType) - d.Set("network_interface_ids", aws.StringValueSlice(vpce.NetworkInterfaceIds)) + d.Set("network_interface_ids", vpce.NetworkInterfaceIds) d.Set(names.AttrOwnerID, vpce.OwnerId) d.Set("private_dns_enabled", vpce.PrivateDnsEnabled) d.Set("requester_managed", vpce.RequesterManaged) - d.Set("route_table_ids", aws.StringValueSlice(vpce.RouteTableIds)) + d.Set("route_table_ids", vpce.RouteTableIds) d.Set(names.AttrSecurityGroupIDs, flattenSecurityGroupIdentifiers(vpce.Groups)) d.Set(names.AttrServiceName, serviceName) d.Set(names.AttrState, vpce.State) - d.Set(names.AttrSubnetIDs, aws.StringValueSlice(vpce.SubnetIds)) + d.Set(names.AttrSubnetIDs, vpce.SubnetIds) // VPC endpoints don't have types in GovCloud, so set type to default if empty - if v := aws.StringValue(vpce.VpcEndpointType); v == "" { - d.Set("vpc_endpoint_type", ec2.VpcEndpointTypeGateway) + if v := string(vpce.VpcEndpointType); v == "" { + d.Set("vpc_endpoint_type", awstypes.VpcEndpointTypeGateway) } else { d.Set("vpc_endpoint_type", v) } d.Set(names.AttrVPCID, vpce.VpcId) - if pl, err := FindPrefixListByName(ctx, conn, serviceName); err != nil { + if pl, err := findPrefixListByNameV2(ctx, conn, serviceName); err != nil { if tfresource.NotFound(err) { d.Set("cidr_blocks", nil) } else { return sdkdiag.AppendErrorf(diags, "reading EC2 Prefix List (%s): %s", serviceName, err) } } else { - d.Set("cidr_blocks", aws.StringValueSlice(pl.Cidrs)) + d.Set("cidr_blocks", pl.Cidrs) d.Set("prefix_list_id", pl.PrefixListId) } - policy, err := structure.NormalizeJsonString(aws.StringValue(vpce.PolicyDocument)) + policy, err := structure.NormalizeJsonString(aws.ToString(vpce.PolicyDocument)) if err != nil { return sdkdiag.AppendErrorf(diags, "policy contains invalid JSON: %s", err) @@ -241,7 +242,7 @@ func dataSourceVPCEndpointRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrPolicy, policy) - if err := d.Set(names.AttrTags, KeyValueTags(ctx, vpce.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + if err := d.Set(names.AttrTags, keyValueTagsV2(ctx, vpce.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } diff --git a/internal/service/ec2/vpc_endpoint_policy.go b/internal/service/ec2/vpc_endpoint_policy.go index 951ef58b7567..d977db7b3a46 100644 --- a/internal/service/ec2/vpc_endpoint_policy.go +++ b/internal/service/ec2/vpc_endpoint_policy.go @@ -8,8 +8,9 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" @@ -61,7 +62,7 @@ func ResourceVPCEndpointPolicy() *schema.Resource { func resourceVPCEndpointPolicyPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) req := &ec2.ModifyVpcEndpointInput{ @@ -80,12 +81,12 @@ func resourceVPCEndpointPolicyPut(ctx context.Context, d *schema.ResourceData, m } log.Printf("[DEBUG] Updating VPC Endpoint Policy: %#v", req) - if _, err := conn.ModifyVpcEndpointWithContext(ctx, req); err != nil { + if _, err := conn.ModifyVpcEndpoint(ctx, req); err != nil { return sdkdiag.AppendErrorf(diags, "updating VPC Endpoint Policy: %s", err) } d.SetId(endpointID) - _, err = WaitVPCEndpointAvailable(ctx, conn, endpointID, d.Timeout(schema.TimeoutCreate)) + _, err = waitVPCEndpointAvailableV2(ctx, conn, endpointID, d.Timeout(schema.TimeoutCreate)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint (%s) to policy to set: %s", endpointID, err) @@ -96,9 +97,9 @@ func resourceVPCEndpointPolicyPut(ctx context.Context, d *schema.ResourceData, m func resourceVPCEndpointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - vpce, err := FindVPCEndpointByID(ctx, conn, d.Id()) + vpce, err := findVPCEndpointByIDV2(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] VPC Endpoint Policy (%s) not found, removing from state", d.Id()) @@ -112,7 +113,7 @@ func resourceVPCEndpointPolicyRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrVPCEndpointID, d.Id()) - policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get(names.AttrPolicy).(string), aws.StringValue(vpce.PolicyDocument)) + policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get(names.AttrPolicy).(string), aws.ToString(vpce.PolicyDocument)) if err != nil { return sdkdiag.AppendErrorf(diags, "while setting policy (%s), encountered: %s", policyToSet, err) @@ -130,7 +131,7 @@ func resourceVPCEndpointPolicyRead(ctx context.Context, d *schema.ResourceData, func resourceVPCEndpointPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) req := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(d.Id()), @@ -138,11 +139,14 @@ func resourceVPCEndpointPolicyDelete(ctx context.Context, d *schema.ResourceData } log.Printf("[DEBUG] Resetting VPC Endpoint Policy: %#v", req) - if _, err := conn.ModifyVpcEndpointWithContext(ctx, req); err != nil { + if _, err := conn.ModifyVpcEndpoint(ctx, req); err != nil { + if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointIdNotFound) { + return diags + } return sdkdiag.AppendErrorf(diags, "Resetting VPC Endpoint Policy: %s", err) } - _, err := WaitVPCEndpointAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)) + _, err := waitVPCEndpointAvailableV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint (%s) to be reset: %s", d.Id(), err) diff --git a/internal/service/ec2/vpc_endpoint_policy_test.go b/internal/service/ec2/vpc_endpoint_policy_test.go index 4f1af0e21177..17d298aecb85 100644 --- a/internal/service/ec2/vpc_endpoint_policy_test.go +++ b/internal/service/ec2/vpc_endpoint_policy_test.go @@ -7,7 +7,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -17,7 +17,7 @@ import ( func TestAccVPCEndpointPolicy_basic(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -51,7 +51,7 @@ func TestAccVPCEndpointPolicy_basic(t *testing.T) { func TestAccVPCEndpointPolicy_disappears(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -75,7 +75,7 @@ func TestAccVPCEndpointPolicy_disappears(t *testing.T) { func TestAccVPCEndpointPolicy_disappears_endpoint(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -135,7 +135,8 @@ const policy2 = ` func testAccVPCEndpointPolicyConfig_basic(rName, policy string) string { return fmt.Sprintf(` data "aws_vpc_endpoint_service" "test" { - service = "dynamodb" + service = "dynamodb" + service_type = "Gateway" } resource "aws_vpc" "test" { diff --git a/internal/service/ec2/vpc_endpoint_route_table_association.go b/internal/service/ec2/vpc_endpoint_route_table_association.go index 6c4dc1b5ec6a..e269f1572a55 100644 --- a/internal/service/ec2/vpc_endpoint_route_table_association.go +++ b/internal/service/ec2/vpc_endpoint_route_table_association.go @@ -9,9 +9,9 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -47,7 +47,7 @@ func ResourceVPCEndpointRouteTableAssociation() *schema.Resource { func resourceVPCEndpointRouteTableAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) routeTableID := d.Get("route_table_id").(string) @@ -56,18 +56,18 @@ func resourceVPCEndpointRouteTableAssociationCreate(ctx context.Context, d *sche input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(endpointID), - AddRouteTableIds: aws.StringSlice([]string{routeTableID}), + AddRouteTableIds: []string{routeTableID}, } - log.Printf("[DEBUG] Creating VPC Endpoint Route Table Association: %s", input) - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + log.Printf("[DEBUG] Creating VPC Endpoint Route Table Association: %v", input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating VPC Endpoint Route Table Association (%s): %s", id, err) } d.SetId(VPCEndpointRouteTableAssociationCreateID(endpointID, routeTableID)) - err = WaitVPCEndpointRouteTableAssociationReady(ctx, conn, endpointID, routeTableID) + err = waitVPCEndpointRouteTableAssociationReadyV2(ctx, conn, endpointID, routeTableID) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint Route Table Association (%s) to become available: %s", id, err) @@ -78,7 +78,7 @@ func resourceVPCEndpointRouteTableAssociationCreate(ctx context.Context, d *sche func resourceVPCEndpointRouteTableAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) routeTableID := d.Get("route_table_id").(string) @@ -86,7 +86,7 @@ func resourceVPCEndpointRouteTableAssociationRead(ctx context.Context, d *schema id := fmt.Sprintf("%s/%s", endpointID, routeTableID) _, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (interface{}, error) { - return nil, FindVPCEndpointRouteTableAssociationExists(ctx, conn, endpointID, routeTableID) + return nil, findVPCEndpointRouteTableAssociationExistsV2(ctx, conn, endpointID, routeTableID) }, d.IsNewResource()) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -104,7 +104,7 @@ func resourceVPCEndpointRouteTableAssociationRead(ctx context.Context, d *schema func resourceVPCEndpointRouteTableAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) routeTableID := d.Get("route_table_id").(string) @@ -113,11 +113,11 @@ func resourceVPCEndpointRouteTableAssociationDelete(ctx context.Context, d *sche input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(endpointID), - RemoveRouteTableIds: aws.StringSlice([]string{routeTableID}), + RemoveRouteTableIds: []string{routeTableID}, } log.Printf("[DEBUG] Deleting VPC Endpoint Route Table Association: %s", id) - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointIdNotFound) || tfawserr.ErrCodeEquals(err, errCodeInvalidRouteTableIdNotFound) || tfawserr.ErrCodeEquals(err, errCodeInvalidParameter) { return diags @@ -127,7 +127,7 @@ func resourceVPCEndpointRouteTableAssociationDelete(ctx context.Context, d *sche return sdkdiag.AppendErrorf(diags, "deleting VPC Endpoint Route Table Association (%s): %s", id, err) } - err = WaitVPCEndpointRouteTableAssociationDeleted(ctx, conn, endpointID, routeTableID) + err = waitVPCEndpointRouteTableAssociationDeletedV2(ctx, conn, endpointID, routeTableID) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint Route Table Association (%s) to delete: %s", id, err) diff --git a/internal/service/ec2/vpc_endpoint_route_table_association_test.go b/internal/service/ec2/vpc_endpoint_route_table_association_test.go index a335116031f3..e6a1322f2f5a 100644 --- a/internal/service/ec2/vpc_endpoint_route_table_association_test.go +++ b/internal/service/ec2/vpc_endpoint_route_table_association_test.go @@ -70,14 +70,14 @@ func TestAccVPCEndpointRouteTableAssociation_disappears(t *testing.T) { func testAccCheckVPCEndpointRouteTableAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_route_table_association" { continue } - err := tfec2.FindVPCEndpointRouteTableAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["route_table_id"]) + err := tfec2.FindVPCEndpointRouteTableAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["route_table_id"]) if tfresource.NotFound(err) { continue @@ -105,9 +105,9 @@ func testAccCheckVPCEndpointRouteTableAssociationExists(ctx context.Context, n s return fmt.Errorf("No VPC Endpoint Route Table Association ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - return tfec2.FindVPCEndpointRouteTableAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["route_table_id"]) + return tfec2.FindVPCEndpointRouteTableAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["route_table_id"]) } } diff --git a/internal/service/ec2/vpc_endpoint_security_group_association.go b/internal/service/ec2/vpc_endpoint_security_group_association.go index edb59e6fa185..b3f76d60a7e3 100644 --- a/internal/service/ec2/vpc_endpoint_security_group_association.go +++ b/internal/service/ec2/vpc_endpoint_security_group_association.go @@ -8,9 +8,9 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -49,7 +49,7 @@ func ResourceVPCEndpointSecurityGroupAssociation() *schema.Resource { func resourceVPCEndpointSecurityGroupAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) vpcEndpointID := d.Get(names.AttrVPCEndpointID).(string) securityGroupID := d.Get("security_group_id").(string) @@ -57,21 +57,21 @@ func resourceVPCEndpointSecurityGroupAssociationCreate(ctx context.Context, d *s defaultSecurityGroupID := "" if replaceDefaultAssociation { - vpcEndpoint, err := FindVPCEndpointByID(ctx, conn, vpcEndpointID) + vpcEndpoint, err := findVPCEndpointByIDV2(ctx, conn, vpcEndpointID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading VPC Endpoint (%s): %s", vpcEndpointID, err) } - vpcID := aws.StringValue(vpcEndpoint.VpcId) + vpcID := aws.ToString(vpcEndpoint.VpcId) - defaultSecurityGroup, err := FindVPCDefaultSecurityGroup(ctx, conn, vpcID) + defaultSecurityGroup, err := findVPCDefaultSecurityGroupV2(ctx, conn, vpcID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) default Security Group: %s", vpcID, err) } - defaultSecurityGroupID = aws.StringValue(defaultSecurityGroup.GroupId) + defaultSecurityGroupID = aws.ToString(defaultSecurityGroup.GroupId) if defaultSecurityGroupID == securityGroupID { return sdkdiag.AppendErrorf(diags, "%s is the default Security Group for EC2 VPC (%s)", securityGroupID, vpcID) @@ -80,7 +80,7 @@ func resourceVPCEndpointSecurityGroupAssociationCreate(ctx context.Context, d *s foundDefaultAssociation := false for _, group := range vpcEndpoint.Groups { - if aws.StringValue(group.GroupId) == defaultSecurityGroupID { + if aws.ToString(group.GroupId) == defaultSecurityGroupID { foundDefaultAssociation = true break } @@ -111,14 +111,14 @@ func resourceVPCEndpointSecurityGroupAssociationCreate(ctx context.Context, d *s func resourceVPCEndpointSecurityGroupAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) vpcEndpointID := d.Get(names.AttrVPCEndpointID).(string) securityGroupID := d.Get("security_group_id").(string) // Human friendly ID for error messages since d.Id() is non-descriptive id := fmt.Sprintf("%s/%s", vpcEndpointID, securityGroupID) - err := FindVPCEndpointSecurityGroupAssociationExists(ctx, conn, vpcEndpointID, securityGroupID) + err := findVPCEndpointSecurityGroupAssociationExistsV2(ctx, conn, vpcEndpointID, securityGroupID) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] VPC Endpoint Security Group Association (%s) not found, removing from state", id) @@ -135,29 +135,29 @@ func resourceVPCEndpointSecurityGroupAssociationRead(ctx context.Context, d *sch func resourceVPCEndpointSecurityGroupAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) vpcEndpointID := d.Get(names.AttrVPCEndpointID).(string) securityGroupID := d.Get("security_group_id").(string) replaceDefaultAssociation := d.Get("replace_default_association").(bool) if replaceDefaultAssociation { - vpcEndpoint, err := FindVPCEndpointByID(ctx, conn, vpcEndpointID) + vpcEndpoint, err := findVPCEndpointByIDV2(ctx, conn, vpcEndpointID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading VPC Endpoint (%s): %s", vpcEndpointID, err) } - vpcID := aws.StringValue(vpcEndpoint.VpcId) + vpcID := aws.ToString(vpcEndpoint.VpcId) - defaultSecurityGroup, err := FindVPCDefaultSecurityGroup(ctx, conn, vpcID) + defaultSecurityGroup, err := findVPCDefaultSecurityGroupV2(ctx, conn, vpcID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC (%s) default Security Group: %s", vpcID, err) } // Add back the VPC endpoint/default security group association. - err = createVPCEndpointSecurityGroupAssociation(ctx, conn, vpcEndpointID, aws.StringValue(defaultSecurityGroup.GroupId)) + err = createVPCEndpointSecurityGroupAssociation(ctx, conn, vpcEndpointID, aws.ToString(defaultSecurityGroup.GroupId)) if err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -171,14 +171,14 @@ func resourceVPCEndpointSecurityGroupAssociationDelete(ctx context.Context, d *s } // createVPCEndpointSecurityGroupAssociation creates the specified VPC endpoint/security group association. -func createVPCEndpointSecurityGroupAssociation(ctx context.Context, conn *ec2.EC2, vpcEndpointID, securityGroupID string) error { +func createVPCEndpointSecurityGroupAssociation(ctx context.Context, conn *ec2.Client, vpcEndpointID, securityGroupID string) error { input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(vpcEndpointID), - AddSecurityGroupIds: aws.StringSlice([]string{securityGroupID}), + AddSecurityGroupIds: []string{securityGroupID}, } - log.Printf("[DEBUG] Creating VPC Endpoint Security Group Association: %s", input) - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + log.Printf("[DEBUG] Creating VPC Endpoint Security Group Association: %v", input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if err != nil { return fmt.Errorf("creating VPC Endpoint (%s) Security Group (%s) Association: %w", vpcEndpointID, securityGroupID, err) @@ -188,14 +188,14 @@ func createVPCEndpointSecurityGroupAssociation(ctx context.Context, conn *ec2.EC } // deleteVPCEndpointSecurityGroupAssociation deletes the specified VPC endpoint/security group association. -func deleteVPCEndpointSecurityGroupAssociation(ctx context.Context, conn *ec2.EC2, vpcEndpointID, securityGroupID string) error { +func deleteVPCEndpointSecurityGroupAssociation(ctx context.Context, conn *ec2.Client, vpcEndpointID, securityGroupID string) error { input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(vpcEndpointID), - RemoveSecurityGroupIds: aws.StringSlice([]string{securityGroupID}), + RemoveSecurityGroupIds: []string{securityGroupID}, } - log.Printf("[DEBUG] Deleting VPC Endpoint Security Group Association: %s", input) - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + log.Printf("[DEBUG] Deleting VPC Endpoint Security Group Association: %v", input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointIdNotFound, errCodeInvalidGroupNotFound, errCodeInvalidParameter) { return nil diff --git a/internal/service/ec2/vpc_endpoint_security_group_association_test.go b/internal/service/ec2/vpc_endpoint_security_group_association_test.go index dd645c03589d..1941294d0270 100644 --- a/internal/service/ec2/vpc_endpoint_security_group_association_test.go +++ b/internal/service/ec2/vpc_endpoint_security_group_association_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccVPCEndpointSecurityGroupAssociation_basic(t *testing.T) { ctx := acctest.Context(t) - var v ec2.VpcEndpoint + var v awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_security_group_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -44,7 +44,7 @@ func TestAccVPCEndpointSecurityGroupAssociation_basic(t *testing.T) { func TestAccVPCEndpointSecurityGroupAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var v ec2.VpcEndpoint + var v awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_security_group_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -68,7 +68,7 @@ func TestAccVPCEndpointSecurityGroupAssociation_disappears(t *testing.T) { func TestAccVPCEndpointSecurityGroupAssociation_multiple(t *testing.T) { ctx := acctest.Context(t) - var v ec2.VpcEndpoint + var v awstypes.VpcEndpoint resourceName0 := "aws_vpc_endpoint_security_group_association.test.0" resourceName1 := "aws_vpc_endpoint_security_group_association.test.1" resourceName2 := "aws_vpc_endpoint_security_group_association.test.2" @@ -95,7 +95,7 @@ func TestAccVPCEndpointSecurityGroupAssociation_multiple(t *testing.T) { func TestAccVPCEndpointSecurityGroupAssociation_replaceDefaultAssociation(t *testing.T) { ctx := acctest.Context(t) - var v ec2.VpcEndpoint + var v awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_security_group_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -118,14 +118,14 @@ func TestAccVPCEndpointSecurityGroupAssociation_replaceDefaultAssociation(t *tes func testAccCheckVPCEndpointSecurityGroupAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_security_group_association" { continue } - err := tfec2.FindVPCEndpointSecurityGroupAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["security_group_id"]) + err := tfec2.FindVPCEndpointSecurityGroupAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["security_group_id"]) if tfresource.NotFound(err) { continue @@ -142,7 +142,7 @@ func testAccCheckVPCEndpointSecurityGroupAssociationDestroy(ctx context.Context) } } -func testAccCheckVPCEndpointSecurityGroupAssociationExists(ctx context.Context, n string, v *ec2.VpcEndpoint) resource.TestCheckFunc { +func testAccCheckVPCEndpointSecurityGroupAssociationExists(ctx context.Context, n string, v *awstypes.VpcEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -153,15 +153,15 @@ func testAccCheckVPCEndpointSecurityGroupAssociationExists(ctx context.Context, return fmt.Errorf("No VPC Endpoint Security Group Association ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - output, err := tfec2.FindVPCEndpointByID(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID]) + output, err := tfec2.FindVPCEndpointByIDV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID]) if err != nil { return err } - err = tfec2.FindVPCEndpointSecurityGroupAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["security_group_id"]) + err = tfec2.FindVPCEndpointSecurityGroupAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes["security_group_id"]) if err != nil { return err @@ -173,7 +173,7 @@ func testAccCheckVPCEndpointSecurityGroupAssociationExists(ctx context.Context, } } -func testAccCheckVPCEndpointSecurityGroupAssociationNumAssociations(v *ec2.VpcEndpoint, n int) resource.TestCheckFunc { +func testAccCheckVPCEndpointSecurityGroupAssociationNumAssociations(v *awstypes.VpcEndpoint, n int) resource.TestCheckFunc { return func(s *terraform.State) error { if len := len(v.Groups); len != n { return fmt.Errorf("got %d associations; wanted %d", len, n) diff --git a/internal/service/ec2/vpc_endpoint_service.go b/internal/service/ec2/vpc_endpoint_service.go index 0b4f41ef0370..a2e7c3f1465b 100644 --- a/internal/service/ec2/vpc_endpoint_service.go +++ b/internal/service/ec2/vpc_endpoint_service.go @@ -9,15 +9,16 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -132,8 +133,8 @@ func ResourceVPCEndpointService() *schema.Resource { Optional: true, Computed: true, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(ec2.ServiceConnectivityType_Values(), false), + Type: schema.TypeString, + ValidateDiagFunc: enum.Validate[awstypes.ServiceConnectivityType](), }, }, names.AttrTags: tftags.TagsSchema(), @@ -152,20 +153,20 @@ func ResourceVPCEndpointService() *schema.Resource { func resourceVPCEndpointServiceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.CreateVpcEndpointServiceConfigurationInput{ AcceptanceRequired: aws.Bool(d.Get("acceptance_required").(bool)), ClientToken: aws.String(id.UniqueId()), - TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeVpcEndpointService), + TagSpecifications: getTagSpecificationsInV2(ctx, awstypes.ResourceTypeVpcEndpointService), } if v, ok := d.GetOk("gateway_load_balancer_arns"); ok && v.(*schema.Set).Len() > 0 { - input.GatewayLoadBalancerArns = flex.ExpandStringSet(v.(*schema.Set)) + input.GatewayLoadBalancerArns = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("network_load_balancer_arns"); ok && v.(*schema.Set).Len() > 0 { - input.NetworkLoadBalancerArns = flex.ExpandStringSet(v.(*schema.Set)) + input.NetworkLoadBalancerArns = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("private_dns_name"); ok { @@ -173,29 +174,29 @@ func resourceVPCEndpointServiceCreate(ctx context.Context, d *schema.ResourceDat } if v, ok := d.GetOk("supported_ip_address_types"); ok && v.(*schema.Set).Len() > 0 { - input.SupportedIpAddressTypes = flex.ExpandStringSet(v.(*schema.Set)) + input.SupportedIpAddressTypes = flex.ExpandStringValueSet(v.(*schema.Set)) } - log.Printf("[DEBUG] Creating EC2 VPC Endpoint Service: %s", input) - output, err := conn.CreateVpcEndpointServiceConfigurationWithContext(ctx, input) + log.Printf("[DEBUG] Creating EC2 VPC Endpoint Service: %v", input) + output, err := conn.CreateVpcEndpointServiceConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating EC2 VPC Endpoint Service: %s", err) } - d.SetId(aws.StringValue(output.ServiceConfiguration.ServiceId)) + d.SetId(aws.ToString(output.ServiceConfiguration.ServiceId)) - if _, err := WaitVPCEndpointServiceAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitVPCEndpointServiceAvailableV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint Service (%s) create: %s", d.Id(), err) } if v, ok := d.GetOk("allowed_principals"); ok && v.(*schema.Set).Len() > 0 { input := &ec2.ModifyVpcEndpointServicePermissionsInput{ - AddAllowedPrincipals: flex.ExpandStringSet(v.(*schema.Set)), + AddAllowedPrincipals: flex.ExpandStringValueSet(v.(*schema.Set)), ServiceId: aws.String(d.Id()), } - if _, err := conn.ModifyVpcEndpointServicePermissionsWithContext(ctx, input); err != nil { + if _, err := conn.ModifyVpcEndpointServicePermissions(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "modifying EC2 VPC Endpoint Service (%s) permissions: %s", d.Id(), err) } } @@ -205,9 +206,9 @@ func resourceVPCEndpointServiceCreate(ctx context.Context, d *schema.ResourceDat func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - svcCfg, err := FindVPCEndpointServiceConfigurationByID(ctx, conn, d.Id()) + svcCfg, err := findVPCEndpointServiceConfigurationByIDV2(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EC2 VPC Endpoint Service %s not found, removing from state", d.Id()) @@ -222,17 +223,17 @@ func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, d.Set("acceptance_required", svcCfg.AcceptanceRequired) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, AccountID: meta.(*conns.AWSClient).AccountID, Resource: fmt.Sprintf("vpc-endpoint-service/%s", d.Id()), }.String() d.Set(names.AttrARN, arn) - d.Set(names.AttrAvailabilityZones, aws.StringValueSlice(svcCfg.AvailabilityZones)) - d.Set("base_endpoint_dns_names", aws.StringValueSlice(svcCfg.BaseEndpointDnsNames)) - d.Set("gateway_load_balancer_arns", aws.StringValueSlice(svcCfg.GatewayLoadBalancerArns)) + d.Set(names.AttrAvailabilityZones, svcCfg.AvailabilityZones) + d.Set("base_endpoint_dns_names", svcCfg.BaseEndpointDnsNames) + d.Set("gateway_load_balancer_arns", svcCfg.GatewayLoadBalancerArns) d.Set("manages_vpc_endpoints", svcCfg.ManagesVpcEndpoints) - d.Set("network_load_balancer_arns", aws.StringValueSlice(svcCfg.NetworkLoadBalancerArns)) + d.Set("network_load_balancer_arns", svcCfg.NetworkLoadBalancerArns) d.Set("private_dns_name", svcCfg.PrivateDnsName) // The EC2 API can return a XML structure with no elements. if tfMap := flattenPrivateDNSNameConfiguration(svcCfg.PrivateDnsNameConfiguration); len(tfMap) > 0 { @@ -249,11 +250,11 @@ func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, d.Set("service_type", nil) } d.Set(names.AttrState, svcCfg.ServiceState) - d.Set("supported_ip_address_types", aws.StringValueSlice(svcCfg.SupportedIpAddressTypes)) + d.Set("supported_ip_address_types", svcCfg.SupportedIpAddressTypes) - setTagsOut(ctx, svcCfg.Tags) + setTagsOutV2(ctx, svcCfg.Tags) - allowedPrincipals, err := FindVPCEndpointServicePermissionsByServiceID(ctx, conn, d.Id()) + allowedPrincipals, err := findVPCEndpointServicePermissionsByServiceIDV2(ctx, conn, d.Id()) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC Endpoint Service (%s) permissions: %s", d.Id(), err) @@ -266,7 +267,7 @@ func resourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, func resourceVPCEndpointServiceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) if d.HasChanges("acceptance_required", "gateway_load_balancer_arns", "network_load_balancer_arns", "private_dns_name", "supported_ip_address_types") { input := &ec2.ModifyVpcEndpointServiceConfigurationInput{ @@ -277,23 +278,23 @@ func resourceVPCEndpointServiceUpdate(ctx context.Context, d *schema.ResourceDat input.AcceptanceRequired = aws.Bool(d.Get("acceptance_required").(bool)) } - input.AddGatewayLoadBalancerArns, input.RemoveGatewayLoadBalancerArns = flattenAddAndRemoveStringLists(d, "gateway_load_balancer_arns") - input.AddNetworkLoadBalancerArns, input.RemoveNetworkLoadBalancerArns = flattenAddAndRemoveStringLists(d, "network_load_balancer_arns") + input.AddGatewayLoadBalancerArns, input.RemoveGatewayLoadBalancerArns = flattenAddAndRemoveStringValueLists(d, "gateway_load_balancer_arns") + input.AddNetworkLoadBalancerArns, input.RemoveNetworkLoadBalancerArns = flattenAddAndRemoveStringValueLists(d, "network_load_balancer_arns") if d.HasChange("private_dns_name") { input.PrivateDnsName = aws.String(d.Get("private_dns_name").(string)) } - input.AddSupportedIpAddressTypes, input.RemoveSupportedIpAddressTypes = flattenAddAndRemoveStringLists(d, "supported_ip_address_types") + input.AddSupportedIpAddressTypes, input.RemoveSupportedIpAddressTypes = flattenAddAndRemoveStringValueLists(d, "supported_ip_address_types") - log.Printf("[DEBUG] Updating EC2 VPC Endpoint Service: %s", input) - _, err := conn.ModifyVpcEndpointServiceConfigurationWithContext(ctx, input) + log.Printf("[DEBUG] Updating EC2 VPC Endpoint Service: %v", input) + _, err := conn.ModifyVpcEndpointServiceConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating EC2 VPC Endpoint Service (%s): %s", d.Id(), err) } - if _, err := WaitVPCEndpointServiceAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := waitVPCEndpointServiceAvailableV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint Service (%s) update: %s", d.Id(), err) } } @@ -303,9 +304,9 @@ func resourceVPCEndpointServiceUpdate(ctx context.Context, d *schema.ResourceDat ServiceId: aws.String(d.Id()), } - input.AddAllowedPrincipals, input.RemoveAllowedPrincipals = flattenAddAndRemoveStringLists(d, "allowed_principals") + input.AddAllowedPrincipals, input.RemoveAllowedPrincipals = flattenAddAndRemoveStringValueLists(d, "allowed_principals") - if _, err := conn.ModifyVpcEndpointServicePermissionsWithContext(ctx, input); err != nil { + if _, err := conn.ModifyVpcEndpointServicePermissions(ctx, input); err != nil { return sdkdiag.AppendErrorf(diags, "modifying EC2 VPC Endpoint Service (%s) permissions: %s", d.Id(), err) } } @@ -315,18 +316,18 @@ func resourceVPCEndpointServiceUpdate(ctx context.Context, d *schema.ResourceDat func resourceVPCEndpointServiceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) log.Printf("[INFO] Deleting EC2 VPC Endpoint Service: %s", d.Id()) - output, err := conn.DeleteVpcEndpointServiceConfigurationsWithContext(ctx, &ec2.DeleteVpcEndpointServiceConfigurationsInput{ - ServiceIds: aws.StringSlice([]string{d.Id()}), + output, err := conn.DeleteVpcEndpointServiceConfigurations(ctx, &ec2.DeleteVpcEndpointServiceConfigurationsInput{ + ServiceIds: []string{d.Id()}, }) if err == nil && output != nil { - err = UnsuccessfulItemsError(output.Unsuccessful) + err = unsuccessfulItemsErrorV2(output.Unsuccessful) } - if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointServiceIdNotFound) { + if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointServiceNotFound) { return diags } @@ -334,22 +335,14 @@ func resourceVPCEndpointServiceDelete(ctx context.Context, d *schema.ResourceDat return sdkdiag.AppendErrorf(diags, "deleting EC2 VPC Endpoint Service (%s): %s", d.Id(), err) } - if _, err := WaitVPCEndpointServiceDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitVPCEndpointServiceDeletedV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EC2 VPC Endpoint Service (%s) delete: %s", d.Id(), err) } return diags } -func flattenAllowedPrincipal(apiObject *ec2.AllowedPrincipal) *string { - if apiObject == nil { - return nil - } - - return apiObject.Principal -} - -func flattenAllowedPrincipals(apiObjects []*ec2.AllowedPrincipal) []*string { +func flattenAllowedPrincipals(apiObjects []awstypes.AllowedPrincipal) []*string { if len(apiObjects) == 0 { return nil } @@ -357,17 +350,13 @@ func flattenAllowedPrincipals(apiObjects []*ec2.AllowedPrincipal) []*string { var tfList []*string for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenAllowedPrincipal(apiObject)) + tfList = append(tfList, apiObject.Principal) } return tfList } -func flattenPrivateDNSNameConfiguration(apiObject *ec2.PrivateDnsNameConfiguration) map[string]interface{} { +func flattenPrivateDNSNameConfiguration(apiObject *awstypes.PrivateDnsNameConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -375,19 +364,19 @@ func flattenPrivateDNSNameConfiguration(apiObject *ec2.PrivateDnsNameConfigurati tfMap := map[string]interface{}{} if v := apiObject.Name; v != nil { - tfMap[names.AttrName] = aws.StringValue(v) + tfMap[names.AttrName] = aws.ToString(v) } - if v := apiObject.State; v != nil { - tfMap[names.AttrState] = aws.StringValue(v) + if v := apiObject.State; v != "" { + tfMap[names.AttrState] = string(v) } if v := apiObject.Type; v != nil { - tfMap[names.AttrType] = aws.StringValue(v) + tfMap[names.AttrType] = aws.ToString(v) } if v := apiObject.Value; v != nil { - tfMap[names.AttrValue] = aws.StringValue(v) + tfMap[names.AttrValue] = aws.ToString(v) } return tfMap diff --git a/internal/service/ec2/vpc_endpoint_service_allowed_principal.go b/internal/service/ec2/vpc_endpoint_service_allowed_principal.go index 2ae534a2be20..56185c9ff4de 100644 --- a/internal/service/ec2/vpc_endpoint_service_allowed_principal.go +++ b/internal/service/ec2/vpc_endpoint_service_allowed_principal.go @@ -7,9 +7,9 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -41,13 +41,13 @@ func ResourceVPCEndpointServiceAllowedPrincipal() *schema.Resource { func resourceVPCEndpointServiceAllowedPrincipalCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID := d.Get("vpc_endpoint_service_id").(string) principalARN := d.Get("principal_arn").(string) - output, err := conn.ModifyVpcEndpointServicePermissionsWithContext(ctx, &ec2.ModifyVpcEndpointServicePermissionsInput{ - AddAllowedPrincipals: aws.StringSlice([]string{principalARN}), + output, err := conn.ModifyVpcEndpointServicePermissions(ctx, &ec2.ModifyVpcEndpointServicePermissionsInput{ + AddAllowedPrincipals: []string{principalARN}, ServiceId: aws.String(serviceID), }) @@ -56,8 +56,8 @@ func resourceVPCEndpointServiceAllowedPrincipalCreate(ctx context.Context, d *sc } for _, v := range output.AddedPrincipals { - if aws.StringValue(v.Principal) == principalARN { - d.SetId(aws.StringValue(v.ServicePermissionId)) + if aws.ToString(v.Principal) == principalARN { + d.SetId(aws.ToString(v.ServicePermissionId)) } } @@ -66,12 +66,12 @@ func resourceVPCEndpointServiceAllowedPrincipalCreate(ctx context.Context, d *sc func resourceVPCEndpointServiceAllowedPrincipalRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID := d.Get("vpc_endpoint_service_id").(string) principalARN := d.Get("principal_arn").(string) - output, err := FindVPCEndpointServicePermission(ctx, conn, serviceID, principalARN) + output, err := findVPCEndpointServicePermissionV2(ctx, conn, serviceID, principalARN) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EC2 VPC Endpoint Service Allowed Principal %s not found, removing from state", d.Id()) @@ -83,20 +83,20 @@ func resourceVPCEndpointServiceAllowedPrincipalRead(ctx context.Context, d *sche return sdkdiag.AppendErrorf(diags, "reading EC2 VPC Endpoint Service (%s) Allowed Principal (%s): %s", serviceID, principalARN, err) } - d.SetId(aws.StringValue(output.ServicePermissionId)) + d.SetId(aws.ToString(output.ServicePermissionId)) return diags } func resourceVPCEndpointServiceAllowedPrincipalDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) serviceID := d.Get("vpc_endpoint_service_id").(string) principalARN := d.Get("principal_arn").(string) - _, err := conn.ModifyVpcEndpointServicePermissionsWithContext(ctx, &ec2.ModifyVpcEndpointServicePermissionsInput{ - RemoveAllowedPrincipals: aws.StringSlice([]string{principalARN}), + _, err := conn.ModifyVpcEndpointServicePermissions(ctx, &ec2.ModifyVpcEndpointServicePermissionsInput{ + RemoveAllowedPrincipals: []string{principalARN}, ServiceId: aws.String(serviceID), }) diff --git a/internal/service/ec2/vpc_endpoint_service_allowed_principal_test.go b/internal/service/ec2/vpc_endpoint_service_allowed_principal_test.go index 110cd5fdf7d3..fcc62cacf466 100644 --- a/internal/service/ec2/vpc_endpoint_service_allowed_principal_test.go +++ b/internal/service/ec2/vpc_endpoint_service_allowed_principal_test.go @@ -123,7 +123,10 @@ func TestAccVPCEndpointServiceAllowedPrincipal_migrateID(t *testing.T) { { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Config: testAccVPCEndpointServiceAllowedPrincipalConfig_basic(rName), - PlanOnly: true, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckVPCEndpointServiceAllowedPrincipalExists(ctx, resourceName), + resource.TestMatchResourceAttr(resourceName, names.AttrID, regexache.MustCompile(`^vpce-svc-perm-\w{17}$`)), + ), }, }, }) @@ -171,14 +174,14 @@ func TestAccVPCEndpointServiceAllowedPrincipal_migrateAndTag(t *testing.T) { func testAccCheckVPCEndpointServiceAllowedPrincipalDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_service_allowed_principal" { continue } - _, err := tfec2.FindVPCEndpointServicePermission(ctx, conn, rs.Primary.Attributes["vpc_endpoint_service_id"], rs.Primary.Attributes["principal_arn"]) + _, err := tfec2.FindVPCEndpointServicePermissionV2(ctx, conn, rs.Primary.Attributes["vpc_endpoint_service_id"], rs.Primary.Attributes["principal_arn"]) if tfresource.NotFound(err) { continue @@ -206,9 +209,9 @@ func testAccCheckVPCEndpointServiceAllowedPrincipalExists(ctx context.Context, n return fmt.Errorf("No EC2 VPC Endpoint Service Allowed Principal ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - _, err := tfec2.FindVPCEndpointServicePermission(ctx, conn, rs.Primary.Attributes["vpc_endpoint_service_id"], rs.Primary.Attributes["principal_arn"]) + _, err := tfec2.FindVPCEndpointServicePermissionV2(ctx, conn, rs.Primary.Attributes["vpc_endpoint_service_id"], rs.Primary.Attributes["principal_arn"]) return err } diff --git a/internal/service/ec2/vpc_endpoint_service_data_source.go b/internal/service/ec2/vpc_endpoint_service_data_source.go index ae629c50c36e..89cbf408a36c 100644 --- a/internal/service/ec2/vpc_endpoint_service_data_source.go +++ b/internal/service/ec2/vpc_endpoint_service_data_source.go @@ -9,14 +9,15 @@ import ( "strconv" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/names" @@ -79,10 +80,10 @@ func DataSourceVPCEndpointService() *schema.Resource { ConflictsWith: []string{"service"}, }, "service_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(ec2.ServiceType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.ServiceType](), }, "supported_ip_address_types": { Type: schema.TypeSet, @@ -100,11 +101,11 @@ func DataSourceVPCEndpointService() *schema.Resource { func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig input := &ec2.DescribeVpcEndpointServicesInput{ - Filters: newAttributeFilterList( + Filters: newAttributeFilterListV2( map[string]string{ "service-type": d.Get("service_type").(string), }, @@ -120,25 +121,23 @@ func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceDat } if serviceName != "" { - input.ServiceNames = aws.StringSlice([]string{serviceName}) + input.ServiceNames = []string{serviceName} } if v, ok := d.GetOk(names.AttrTags); ok { - input.Filters = append(input.Filters, newTagFilterList( - Tags(tftags.New(ctx, v.(map[string]interface{}))), - )...) + input.Filters = append(input.Filters, newTagFilterListV2( + TagsV2(tftags.New(ctx, v.(map[string]interface{}))))...) } - input.Filters = append(input.Filters, newCustomFilterList( - d.Get(names.AttrFilter).(*schema.Set), - )...) + input.Filters = append(input.Filters, newCustomFilterListV2( + d.Get(names.AttrFilter).(*schema.Set))...) if len(input.Filters) == 0 { // Don't send an empty filters list; the EC2 API won't accept it. input.Filters = nil } - serviceDetails, serviceNames, err := FindVPCEndpointServices(ctx, conn, input) + serviceDetails, serviceNames, err := findVPCEndpointServicesV2(ctx, conn, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC Endpoint Services: %s", err) @@ -168,23 +167,23 @@ func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceDat } sd := serviceDetails[0] - serviceID := aws.StringValue(sd.ServiceId) - serviceName = aws.StringValue(sd.ServiceName) + serviceID := aws.ToString(sd.ServiceId) + serviceName = aws.ToString(sd.ServiceName) d.SetId(strconv.Itoa(create.StringHashcode(serviceName))) d.Set("acceptance_required", sd.AcceptanceRequired) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, AccountID: meta.(*conns.AWSClient).AccountID, Resource: fmt.Sprintf("vpc-endpoint-service/%s", serviceID), }.String() d.Set(names.AttrARN, arn) - d.Set(names.AttrAvailabilityZones, aws.StringValueSlice(sd.AvailabilityZones)) - d.Set("base_endpoint_dns_names", aws.StringValueSlice(sd.BaseEndpointDnsNames)) + d.Set(names.AttrAvailabilityZones, sd.AvailabilityZones) + d.Set("base_endpoint_dns_names", sd.BaseEndpointDnsNames) d.Set("manages_vpc_endpoints", sd.ManagesVpcEndpoints) d.Set(names.AttrOwner, sd.Owner) d.Set("private_dns_name", sd.PrivateDnsName) @@ -195,10 +194,10 @@ func dataSourceVPCEndpointServiceRead(ctx context.Context, d *schema.ResourceDat } else { d.Set("service_type", nil) } - d.Set("supported_ip_address_types", aws.StringValueSlice(sd.SupportedIpAddressTypes)) + d.Set("supported_ip_address_types", sd.SupportedIpAddressTypes) d.Set("vpc_endpoint_policy_supported", sd.VpcEndpointPolicySupported) - err = d.Set(names.AttrTags, KeyValueTags(ctx, sd.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) + err = d.Set(names.AttrTags, keyValueTagsV2(ctx, sd.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()) if err != nil { return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) diff --git a/internal/service/ec2/vpc_endpoint_service_data_source_test.go b/internal/service/ec2/vpc_endpoint_service_data_source_test.go index c17ba6703c9c..764b9d8270aa 100644 --- a/internal/service/ec2/vpc_endpoint_service_data_source_test.go +++ b/internal/service/ec2/vpc_endpoint_service_data_source_test.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccVPCEndpointServiceDataSource_gateway(t *testing.T) { +func TestAccVPCEndpointServiceDataSource_ServiceType_gateway(t *testing.T) { ctx := acctest.Context(t) datasourceName := "data.aws_vpc_endpoint_service.test" @@ -25,7 +25,7 @@ func TestAccVPCEndpointServiceDataSource_gateway(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccVPCEndpointServiceDataSourceConfig_gateway, + Config: testAccVPCEndpointServiceDataSourceConfig_type("dynamodb", "Gateway"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(datasourceName, "acceptance_required", "false"), acctest.MatchResourceAttrRegionalARN(datasourceName, names.AttrARN, "ec2", regexache.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)), @@ -45,7 +45,7 @@ func TestAccVPCEndpointServiceDataSource_gateway(t *testing.T) { }) } -func TestAccVPCEndpointServiceDataSource_interface(t *testing.T) { +func TestAccVPCEndpointServiceDataSource_ServiceType_interface(t *testing.T) { ctx := acctest.Context(t) datasourceName := "data.aws_vpc_endpoint_service.test" @@ -55,7 +55,7 @@ func TestAccVPCEndpointServiceDataSource_interface(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccVPCEndpointServiceDataSourceConfig_interface, + Config: testAccVPCEndpointServiceDataSourceConfig_type("ec2", "Interface"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(datasourceName, "acceptance_required", "false"), acctest.MatchResourceAttrRegionalARN(datasourceName, names.AttrARN, "ec2", regexache.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)), @@ -168,46 +168,6 @@ func TestAccVPCEndpointServiceDataSource_CustomFilter_tags(t *testing.T) { }) } -func TestAccVPCEndpointServiceDataSource_ServiceType_gateway(t *testing.T) { - ctx := acctest.Context(t) - datasourceName := "data.aws_vpc_endpoint_service.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccVPCEndpointServiceDataSourceConfig_type("s3", "Gateway"), - Check: resource.ComposeTestCheckFunc( - testAccCheckResourceAttrRegionalReverseDNSService(datasourceName, names.AttrServiceName, "s3"), - resource.TestCheckResourceAttr(datasourceName, "service_type", "Gateway"), - ), - }, - }, - }) -} - -func TestAccVPCEndpointServiceDataSource_ServiceType_interface(t *testing.T) { - ctx := acctest.Context(t) - datasourceName := "data.aws_vpc_endpoint_service.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccVPCEndpointServiceDataSourceConfig_type("ec2", "Interface"), - Check: resource.ComposeTestCheckFunc( - testAccCheckResourceAttrRegionalReverseDNSService(datasourceName, names.AttrServiceName, "ec2"), - resource.TestCheckResourceAttr(datasourceName, "service_type", "Interface"), - ), - }, - }, - }) -} - // testAccCheckResourceAttrRegionalReverseDNSService ensures the Terraform state exactly matches a service reverse DNS hostname with region and partition DNS suffix // // For example: com.amazonaws.us-west-2.s3 @@ -219,18 +179,6 @@ func testAccCheckResourceAttrRegionalReverseDNSService(resourceName, attributeNa } } -const testAccVPCEndpointServiceDataSourceConfig_gateway = ` -data "aws_vpc_endpoint_service" "test" { - service = "dynamodb" -} -` - -const testAccVPCEndpointServiceDataSourceConfig_interface = ` -data "aws_vpc_endpoint_service" "test" { - service = "ec2" -} -` - func testAccVPCEndpointServiceDataSourceConfig_type(service string, serviceType string) string { return fmt.Sprintf(` data "aws_vpc_endpoint_service" "test" { diff --git a/internal/service/ec2/vpc_endpoint_service_test.go b/internal/service/ec2/vpc_endpoint_service_test.go index 3fbd438cf573..e49e1edb08f1 100644 --- a/internal/service/ec2/vpc_endpoint_service_test.go +++ b/internal/service/ec2/vpc_endpoint_service_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccVPCEndpointService_basic(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -64,7 +64,7 @@ func TestAccVPCEndpointService_basic(t *testing.T) { func TestAccVPCEndpointService_disappears(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -88,7 +88,7 @@ func TestAccVPCEndpointService_disappears(t *testing.T) { func TestAccVPCEndpointService_tags(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -134,7 +134,7 @@ func TestAccVPCEndpointService_tags(t *testing.T) { func TestAccVPCEndpointService_networkLoadBalancerARNs(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -169,7 +169,7 @@ func TestAccVPCEndpointService_networkLoadBalancerARNs(t *testing.T) { func TestAccVPCEndpointService_supportedIPAddressTypes(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -207,7 +207,7 @@ func TestAccVPCEndpointService_supportedIPAddressTypes(t *testing.T) { func TestAccVPCEndpointService_allowedPrincipals(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -249,7 +249,7 @@ func TestAccVPCEndpointService_allowedPrincipals(t *testing.T) { func TestAccVPCEndpointService_gatewayLoadBalancerARNs(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit @@ -284,7 +284,7 @@ func TestAccVPCEndpointService_gatewayLoadBalancerARNs(t *testing.T) { func TestAccVPCEndpointService_privateDNSName(t *testing.T) { ctx := acctest.Context(t) - var svcCfg ec2.ServiceConfiguration + var svcCfg awstypes.ServiceConfiguration resourceName := "aws_vpc_endpoint_service.test" rName := sdkacctest.RandomWithPrefix("tfacctest") // 32 character limit domainName1 := acctest.RandomSubdomain() @@ -325,14 +325,14 @@ func TestAccVPCEndpointService_privateDNSName(t *testing.T) { func testAccCheckVPCEndpointServiceDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_service" { continue } - _, err := tfec2.FindVPCEndpointServiceConfigurationByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindVPCEndpointServiceConfigurationByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -349,7 +349,7 @@ func testAccCheckVPCEndpointServiceDestroy(ctx context.Context) resource.TestChe } } -func testAccCheckVPCEndpointServiceExists(ctx context.Context, n string, v *ec2.ServiceConfiguration) resource.TestCheckFunc { +func testAccCheckVPCEndpointServiceExists(ctx context.Context, n string, v *awstypes.ServiceConfiguration) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -360,9 +360,9 @@ func testAccCheckVPCEndpointServiceExists(ctx context.Context, n string, v *ec2. return fmt.Errorf("No EC2 VPC Endpoint Service ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - output, err := tfec2.FindVPCEndpointServiceConfigurationByID(ctx, conn, rs.Primary.ID) + output, err := tfec2.FindVPCEndpointServiceConfigurationByIDV2(ctx, conn, rs.Primary.ID) if err != nil { return err diff --git a/internal/service/ec2/vpc_endpoint_subnet_association.go b/internal/service/ec2/vpc_endpoint_subnet_association.go index e03bf9f9768a..dfd1d5a82156 100644 --- a/internal/service/ec2/vpc_endpoint_subnet_association.go +++ b/internal/service/ec2/vpc_endpoint_subnet_association.go @@ -10,9 +10,9 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -54,7 +54,7 @@ func ResourceVPCEndpointSubnetAssociation() *schema.Resource { func resourceVPCEndpointSubnetAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) subnetID := d.Get(names.AttrSubnetID).(string) @@ -63,10 +63,10 @@ func resourceVPCEndpointSubnetAssociationCreate(ctx context.Context, d *schema.R input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(endpointID), - AddSubnetIds: aws.StringSlice([]string{subnetID}), + AddSubnetIds: []string{subnetID}, } - log.Printf("[DEBUG] Creating VPC Endpoint Subnet Association: %s", input) + log.Printf("[DEBUG] Creating VPC Endpoint Subnet Association: %v", input) // See https://github.com/hashicorp/terraform-provider-aws/issues/3382. // Prevent concurrent subnet association requests and delay between requests. @@ -79,7 +79,7 @@ func resourceVPCEndpointSubnetAssociationCreate(ctx context.Context, d *schema.R Timeout: 3 * time.Minute, Target: []string{"ok"}, Refresh: func() (interface{}, string, error) { - output, err := conn.ModifyVpcEndpointWithContext(ctx, input) + output, err := conn.ModifyVpcEndpoint(ctx, input) return output, "ok", err }, @@ -92,7 +92,7 @@ func resourceVPCEndpointSubnetAssociationCreate(ctx context.Context, d *schema.R d.SetId(VPCEndpointSubnetAssociationCreateID(endpointID, subnetID)) - _, err = WaitVPCEndpointAvailable(ctx, conn, endpointID, d.Timeout(schema.TimeoutCreate)) + _, err = waitVPCEndpointAvailableV2(ctx, conn, endpointID, d.Timeout(schema.TimeoutCreate)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint (%s) to become available: %s", endpointID, err) @@ -103,14 +103,14 @@ func resourceVPCEndpointSubnetAssociationCreate(ctx context.Context, d *schema.R func resourceVPCEndpointSubnetAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) subnetID := d.Get(names.AttrSubnetID).(string) // Human friendly ID for error messages since d.Id() is non-descriptive id := fmt.Sprintf("%s/%s", endpointID, subnetID) - err := FindVPCEndpointSubnetAssociationExists(ctx, conn, endpointID, subnetID) + err := findVPCEndpointSubnetAssociationExistsV2(ctx, conn, endpointID, subnetID) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] VPC Endpoint Subnet Association (%s) not found, removing from state", id) @@ -127,7 +127,7 @@ func resourceVPCEndpointSubnetAssociationRead(ctx context.Context, d *schema.Res func resourceVPCEndpointSubnetAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) endpointID := d.Get(names.AttrVPCEndpointID).(string) subnetID := d.Get(names.AttrSubnetID).(string) @@ -136,11 +136,11 @@ func resourceVPCEndpointSubnetAssociationDelete(ctx context.Context, d *schema.R input := &ec2.ModifyVpcEndpointInput{ VpcEndpointId: aws.String(endpointID), - RemoveSubnetIds: aws.StringSlice([]string{subnetID}), + RemoveSubnetIds: []string{subnetID}, } log.Printf("[DEBUG] Deleting VPC Endpoint Subnet Association: %s", id) - _, err := conn.ModifyVpcEndpointWithContext(ctx, input) + _, err := conn.ModifyVpcEndpoint(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeInvalidVPCEndpointIdNotFound) || tfawserr.ErrCodeEquals(err, errCodeInvalidSubnetIdNotFound) || tfawserr.ErrCodeEquals(err, errCodeInvalidParameter) { return diags @@ -150,7 +150,7 @@ func resourceVPCEndpointSubnetAssociationDelete(ctx context.Context, d *schema.R return sdkdiag.AppendErrorf(diags, "deleting VPC Endpoint Subnet Association (%s): %s", id, err) } - _, err = WaitVPCEndpointAvailable(ctx, conn, endpointID, d.Timeout(schema.TimeoutDelete)) + _, err = waitVPCEndpointAvailableV2(ctx, conn, endpointID, d.Timeout(schema.TimeoutDelete)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for VPC Endpoint (%s) to become available: %s", endpointID, err) diff --git a/internal/service/ec2/vpc_endpoint_subnet_association_test.go b/internal/service/ec2/vpc_endpoint_subnet_association_test.go index c264ba1bb639..8a23b886c19a 100644 --- a/internal/service/ec2/vpc_endpoint_subnet_association_test.go +++ b/internal/service/ec2/vpc_endpoint_subnet_association_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccVPCEndpointSubnetAssociation_basic(t *testing.T) { ctx := acctest.Context(t) - var vpce ec2.VpcEndpoint + var vpce awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_subnet_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -49,7 +49,7 @@ func TestAccVPCEndpointSubnetAssociation_basic(t *testing.T) { func TestAccVPCEndpointSubnetAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var vpce ec2.VpcEndpoint + var vpce awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint_subnet_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -73,7 +73,7 @@ func TestAccVPCEndpointSubnetAssociation_disappears(t *testing.T) { func TestAccVPCEndpointSubnetAssociation_multiple(t *testing.T) { ctx := acctest.Context(t) - var vpce ec2.VpcEndpoint + var vpce awstypes.VpcEndpoint resourceName0 := "aws_vpc_endpoint_subnet_association.test.0" resourceName1 := "aws_vpc_endpoint_subnet_association.test.1" resourceName2 := "aws_vpc_endpoint_subnet_association.test.2" @@ -99,14 +99,14 @@ func TestAccVPCEndpointSubnetAssociation_multiple(t *testing.T) { func testAccCheckVPCEndpointSubnetAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint_subnet_association" { continue } - err := tfec2.FindVPCEndpointSubnetAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes[names.AttrSubnetID]) + err := tfec2.FindVPCEndpointSubnetAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes[names.AttrSubnetID]) if tfresource.NotFound(err) { continue @@ -123,7 +123,7 @@ func testAccCheckVPCEndpointSubnetAssociationDestroy(ctx context.Context) resour } } -func testAccCheckVPCEndpointSubnetAssociationExists(ctx context.Context, n string, vpce *ec2.VpcEndpoint) resource.TestCheckFunc { +func testAccCheckVPCEndpointSubnetAssociationExists(ctx context.Context, n string, vpce *awstypes.VpcEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -134,15 +134,15 @@ func testAccCheckVPCEndpointSubnetAssociationExists(ctx context.Context, n strin return fmt.Errorf("No ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - out, err := tfec2.FindVPCEndpointByID(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID]) + out, err := tfec2.FindVPCEndpointByIDV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID]) if err != nil { return err } - err = tfec2.FindVPCEndpointSubnetAssociationExists(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes[names.AttrSubnetID]) + err = tfec2.FindVPCEndpointSubnetAssociationExistsV2(ctx, conn, rs.Primary.Attributes[names.AttrVPCEndpointID], rs.Primary.Attributes[names.AttrSubnetID]) if err != nil { return err diff --git a/internal/service/ec2/vpc_endpoint_test.go b/internal/service/ec2/vpc_endpoint_test.go index 07c479916344..94ebdba6ebe2 100644 --- a/internal/service/ec2/vpc_endpoint_test.go +++ b/internal/service/ec2/vpc_endpoint_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccVPCEndpoint_gatewayBasic(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -65,7 +65,7 @@ func TestAccVPCEndpoint_gatewayBasic(t *testing.T) { func TestAccVPCEndpoint_interfaceBasic(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -110,7 +110,7 @@ func TestAccVPCEndpoint_interfaceBasic(t *testing.T) { func TestAccVPCEndpoint_interfacePrivateDNS(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -155,7 +155,7 @@ func TestAccVPCEndpoint_interfacePrivateDNS(t *testing.T) { func TestAccVPCEndpoint_interfacePrivateDNSNoGateway(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -188,7 +188,7 @@ func TestAccVPCEndpoint_interfacePrivateDNSNoGateway(t *testing.T) { func TestAccVPCEndpoint_disappears(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -212,7 +212,7 @@ func TestAccVPCEndpoint_disappears(t *testing.T) { func TestAccVPCEndpoint_tags(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -258,7 +258,7 @@ func TestAccVPCEndpoint_tags(t *testing.T) { func TestAccVPCEndpoint_gatewayWithRouteTableAndPolicy(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -295,7 +295,7 @@ func TestAccVPCEndpoint_gatewayWithRouteTableAndPolicy(t *testing.T) { func TestAccVPCEndpoint_gatewayPolicy(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint // This policy checks the DiffSuppressFunc policy1 := ` { @@ -364,7 +364,7 @@ func TestAccVPCEndpoint_gatewayPolicy(t *testing.T) { func TestAccVPCEndpoint_ignoreEquivalent(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -390,7 +390,7 @@ func TestAccVPCEndpoint_ignoreEquivalent(t *testing.T) { func TestAccVPCEndpoint_ipAddressType(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -432,7 +432,7 @@ func TestAccVPCEndpoint_ipAddressType(t *testing.T) { func TestAccVPCEndpoint_interfaceWithSubnetAndSecurityGroup(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -464,6 +464,13 @@ func TestAccVPCEndpoint_interfaceWithSubnetAndSecurityGroup(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // There is a known issue with import verification of computed sets with + // terraform-plugin-testing > 1.6. The only current workaround is ignoring + // the impacted attribute. + // Ref: https://github.com/hashicorp/terraform-plugin-testing/issues/269 + "network_interface_ids", + }, }, }, }) @@ -471,7 +478,7 @@ func TestAccVPCEndpoint_interfaceWithSubnetAndSecurityGroup(t *testing.T) { func TestAccVPCEndpoint_interfaceNonAWSServiceAcceptOnCreate(t *testing.T) { // nosempgrep:aws-in-func-name ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -500,7 +507,7 @@ func TestAccVPCEndpoint_interfaceNonAWSServiceAcceptOnCreate(t *testing.T) { // func TestAccVPCEndpoint_interfaceNonAWSServiceAcceptOnUpdate(t *testing.T) { // nosempgrep:aws-in-func-name ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -536,7 +543,7 @@ func TestAccVPCEndpoint_interfaceNonAWSServiceAcceptOnUpdate(t *testing.T) { // func TestAccVPCEndpoint_VPCEndpointType_gatewayLoadBalancer(t *testing.T) { ctx := acctest.Context(t) - var endpoint ec2.VpcEndpoint + var endpoint awstypes.VpcEndpoint vpcEndpointServiceResourceName := "aws_vpc_endpoint_service.test" resourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -565,14 +572,14 @@ func TestAccVPCEndpoint_VPCEndpointType_gatewayLoadBalancer(t *testing.T) { func testAccCheckVPCEndpointDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_endpoint" { continue } - _, err := tfec2.FindVPCEndpointByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindVPCEndpointByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -587,7 +594,7 @@ func testAccCheckVPCEndpointDestroy(ctx context.Context) resource.TestCheckFunc } } -func testAccCheckVPCEndpointExists(ctx context.Context, n string, v *ec2.VpcEndpoint) resource.TestCheckFunc { +func testAccCheckVPCEndpointExists(ctx context.Context, n string, v *awstypes.VpcEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -598,9 +605,9 @@ func testAccCheckVPCEndpointExists(ctx context.Context, n string, v *ec2.VpcEndp return fmt.Errorf("No EC2 VPC Endpoint ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - output, err := tfec2.FindVPCEndpointByID(ctx, conn, rs.Primary.ID) + output, err := tfec2.FindVPCEndpointByIDV2(ctx, conn, rs.Primary.ID) if err != nil { return err diff --git a/internal/service/ec2/vpc_managed_prefix_list.go b/internal/service/ec2/vpc_managed_prefix_list.go index 8de5026cd80f..de0a44e1bd2c 100644 --- a/internal/service/ec2/vpc_managed_prefix_list.go +++ b/internal/service/ec2/vpc_managed_prefix_list.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" diff --git a/internal/service/ec2/vpc_prefix_list_data_source.go b/internal/service/ec2/vpc_prefix_list_data_source.go index 0dd68cccccec..c48b0ac54af5 100644 --- a/internal/service/ec2/vpc_prefix_list_data_source.go +++ b/internal/service/ec2/vpc_prefix_list_data_source.go @@ -7,8 +7,8 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -48,32 +48,32 @@ func DataSourcePrefixList() *schema.Resource { func dataSourcePrefixListRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.DescribePrefixListsInput{} if v, ok := d.GetOk(names.AttrName); ok { - input.Filters = append(input.Filters, newAttributeFilterList(map[string]string{ + input.Filters = append(input.Filters, newAttributeFilterListV2(map[string]string{ "prefix-list-name": v.(string), })...) } if v, ok := d.GetOk("prefix_list_id"); ok { - input.PrefixListIds = aws.StringSlice([]string{v.(string)}) + input.PrefixListIds = []string{v.(string)} } - input.Filters = append(input.Filters, newCustomFilterList( + input.Filters = append(input.Filters, newCustomFilterListV2( d.Get(names.AttrFilter).(*schema.Set), )...) - pl, err := FindPrefixList(ctx, conn, input) + pl, err := findPrefixListV2(ctx, conn, input) if err != nil { return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("EC2 Prefix List", err)) } - d.SetId(aws.StringValue(pl.PrefixListId)) - d.Set("cidr_blocks", aws.StringValueSlice(pl.Cidrs)) + d.SetId(aws.ToString(pl.PrefixListId)) + d.Set("cidr_blocks", pl.Cidrs) d.Set(names.AttrName, pl.PrefixListName) return diags diff --git a/internal/service/ec2/vpc_route.go b/internal/service/ec2/vpc_route.go index c953d4f5bd94..a1fbdaeb6870 100644 --- a/internal/service/ec2/vpc_route.go +++ b/internal/service/ec2/vpc_route.go @@ -10,9 +10,10 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -182,7 +183,7 @@ func resourceRoute() *schema.Resource { func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) destinationAttributeKey, destination, err := routeDestinationAttribute(d) if err != nil { @@ -199,18 +200,18 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter RouteTableId: aws.String(routeTableID), } - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destination := aws.String(destination); destinationAttributeKey { case routeDestinationCIDRBlock: input.DestinationCidrBlock = destination - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case routeDestinationIPv6CIDRBlock: input.DestinationIpv6CidrBlock = destination - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case routeDestinationPrefixListID: input.DestinationPrefixListId = destination - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return sdkdiag.AppendErrorf(diags, "creating Route: unexpected route destination attribute: %q", destinationAttributeKey) } @@ -244,7 +245,7 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter switch { case err == nil: - if aws.StringValue(route.Origin) == ec2.RouteOriginCreateRoute { + if route.Origin == awstypes.RouteOriginCreateRoute { return sdkdiag.AppendFromErr(diags, routeAlreadyExistsError(routeTableID, destination)) } case tfresource.NotFound(err): @@ -254,7 +255,7 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter _, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { - return conn.CreateRouteWithContext(ctx, input) + return conn.CreateRoute(ctx, input) }, errCodeInvalidParameterException, errCodeInvalidTransitGatewayIDNotFound, @@ -271,7 +272,7 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter d.SetId(RouteCreateID(routeTableID, destination)) - if _, err := WaitRouteReady(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitRouteReadyV2(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route in Route Table (%s) with destination (%s) create: %s", routeTableID, destination, err) } @@ -280,7 +281,7 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) destinationAttributeKey, destination, err := routeDestinationAttribute(d) @@ -288,14 +289,14 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendFromErr(diags, err) } - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destinationAttributeKey { case routeDestinationCIDRBlock: - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case routeDestinationIPv6CIDRBlock: - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case routeDestinationPrefixListID: - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return sdkdiag.AppendErrorf(diags, "reading Route: unexpected route destination attribute: %q", destinationAttributeKey) } @@ -315,14 +316,14 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendErrorf(diags, "reading Route in Route Table (%s) with destination (%s): %s", routeTableID, destination, err) } - route := outputRaw.(*ec2.Route) + route := outputRaw.(*awstypes.Route) d.Set("carrier_gateway_id", route.CarrierGatewayId) d.Set("core_network_arn", route.CoreNetworkArn) d.Set(routeDestinationCIDRBlock, route.DestinationCidrBlock) d.Set(routeDestinationIPv6CIDRBlock, route.DestinationIpv6CidrBlock) d.Set(routeDestinationPrefixListID, route.DestinationPrefixListId) // VPC Endpoint ID is returned in Gateway ID field - if strings.HasPrefix(aws.StringValue(route.GatewayId), "vpce-") { + if strings.HasPrefix(aws.ToString(route.GatewayId), "vpce-") { d.Set("gateway_id", "") d.Set(names.AttrVPCEndpointID, route.GatewayId) } else { @@ -345,7 +346,7 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa func resourceRouteUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) destinationAttributeKey, destination, err := routeDestinationAttribute(d) @@ -364,18 +365,18 @@ func resourceRouteUpdate(ctx context.Context, d *schema.ResourceData, meta inter RouteTableId: aws.String(routeTableID), } - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destination := aws.String(destination); destinationAttributeKey { case routeDestinationCIDRBlock: input.DestinationCidrBlock = destination - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case routeDestinationIPv6CIDRBlock: input.DestinationIpv6CidrBlock = destination - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case routeDestinationPrefixListID: input.DestinationPrefixListId = destination - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return sdkdiag.AppendErrorf(diags, "updating Route: unexpected route destination attribute: %q", destinationAttributeKey) } @@ -410,14 +411,14 @@ func resourceRouteUpdate(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "updating Route: unexpected route target attribute: %q", targetAttributeKey) } - log.Printf("[DEBUG] Updating Route: %s", input) - _, err = conn.ReplaceRouteWithContext(ctx, input) + log.Printf("[DEBUG] Updating Route: %v", input) + _, err = conn.ReplaceRoute(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating Route in Route Table (%s) with destination (%s): %s", routeTableID, destination, err) } - if _, err := WaitRouteReady(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := waitRouteReadyV2(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route in Route Table (%s) with destination (%s) update: %s", routeTableID, destination, err) } @@ -426,7 +427,7 @@ func resourceRouteUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceRouteDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) destinationAttributeKey, destination, err := routeDestinationAttribute(d) @@ -439,26 +440,26 @@ func resourceRouteDelete(ctx context.Context, d *schema.ResourceData, meta inter RouteTableId: aws.String(routeTableID), } - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destination := aws.String(destination); destinationAttributeKey { case routeDestinationCIDRBlock: input.DestinationCidrBlock = destination - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case routeDestinationIPv6CIDRBlock: input.DestinationIpv6CidrBlock = destination - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case routeDestinationPrefixListID: input.DestinationPrefixListId = destination - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return sdkdiag.AppendErrorf(diags, "deleting Route: unexpected route destination attribute: %q", destinationAttributeKey) } - log.Printf("[DEBUG] Deleting Route: %s", input) + log.Printf("[DEBUG] Deleting Route: %v", input) _, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { - return conn.DeleteRouteWithContext(ctx, input) + return conn.DeleteRoute(ctx, input) }, errCodeInvalidParameterException, ) @@ -476,7 +477,7 @@ func resourceRouteDelete(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "deleting Route in Route Table (%s) with destination (%s): %s", routeTableID, destination, err) } - if _, err := WaitRouteDeleted(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitRouteDeletedV2(ctx, conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route in Route Table (%s) with destination (%s) delete: %s", routeTableID, destination, err) } diff --git a/internal/service/ec2/vpc_route_data_source.go b/internal/service/ec2/vpc_route_data_source.go index 92cec3c9238e..6523746f1d60 100644 --- a/internal/service/ec2/vpc_route_data_source.go +++ b/internal/service/ec2/vpc_route_data_source.go @@ -8,8 +8,8 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -110,78 +110,78 @@ func DataSourceRoute() *schema.Resource { func dataSourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) routeTableID := d.Get("route_table_id").(string) - routeTable, err := FindRouteTableByID(ctx, conn, routeTableID) + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading Route Table (%s): %s", routeTableID, err) } - routes := []*ec2.Route{} + routes := []awstypes.Route{} for _, r := range routeTable.Routes { - if aws.StringValue(r.Origin) == ec2.RouteOriginEnableVgwRoutePropagation { + if r.Origin == awstypes.RouteOriginEnableVgwRoutePropagation { continue } - if r.DestinationPrefixListId != nil && strings.HasPrefix(aws.StringValue(r.GatewayId), "vpce-") { + if r.DestinationPrefixListId != nil && strings.HasPrefix(aws.ToString(r.GatewayId), "vpce-") { // Skipping because VPC endpoint routes are handled separately // See aws_vpc_endpoint continue } - if v, ok := d.GetOk("destination_cidr_block"); ok && aws.StringValue(r.DestinationCidrBlock) != v.(string) { + if v, ok := d.GetOk("destination_cidr_block"); ok && aws.ToString(r.DestinationCidrBlock) != v.(string) { continue } - if v, ok := d.GetOk("destination_ipv6_cidr_block"); ok && aws.StringValue(r.DestinationIpv6CidrBlock) != v.(string) { + if v, ok := d.GetOk("destination_ipv6_cidr_block"); ok && aws.ToString(r.DestinationIpv6CidrBlock) != v.(string) { continue } - if v, ok := d.GetOk("destination_prefix_list_id"); ok && aws.StringValue(r.DestinationPrefixListId) != v.(string) { + if v, ok := d.GetOk("destination_prefix_list_id"); ok && aws.ToString(r.DestinationPrefixListId) != v.(string) { continue } - if v, ok := d.GetOk("carrier_gateway_id"); ok && aws.StringValue(r.CarrierGatewayId) != v.(string) { + if v, ok := d.GetOk("carrier_gateway_id"); ok && aws.ToString(r.CarrierGatewayId) != v.(string) { continue } - if v, ok := d.GetOk("core_network_arn"); ok && aws.StringValue(r.CoreNetworkArn) != v.(string) { + if v, ok := d.GetOk("core_network_arn"); ok && aws.ToString(r.CoreNetworkArn) != v.(string) { continue } - if v, ok := d.GetOk("egress_only_gateway_id"); ok && aws.StringValue(r.EgressOnlyInternetGatewayId) != v.(string) { + if v, ok := d.GetOk("egress_only_gateway_id"); ok && aws.ToString(r.EgressOnlyInternetGatewayId) != v.(string) { continue } - if v, ok := d.GetOk("gateway_id"); ok && aws.StringValue(r.GatewayId) != v.(string) { + if v, ok := d.GetOk("gateway_id"); ok && aws.ToString(r.GatewayId) != v.(string) { continue } - if v, ok := d.GetOk(names.AttrInstanceID); ok && aws.StringValue(r.InstanceId) != v.(string) { + if v, ok := d.GetOk(names.AttrInstanceID); ok && aws.ToString(r.InstanceId) != v.(string) { continue } - if v, ok := d.GetOk("local_gateway_id"); ok && aws.StringValue(r.LocalGatewayId) != v.(string) { + if v, ok := d.GetOk("local_gateway_id"); ok && aws.ToString(r.LocalGatewayId) != v.(string) { continue } - if v, ok := d.GetOk("nat_gateway_id"); ok && aws.StringValue(r.NatGatewayId) != v.(string) { + if v, ok := d.GetOk("nat_gateway_id"); ok && aws.ToString(r.NatGatewayId) != v.(string) { continue } - if v, ok := d.GetOk(names.AttrNetworkInterfaceID); ok && aws.StringValue(r.NetworkInterfaceId) != v.(string) { + if v, ok := d.GetOk(names.AttrNetworkInterfaceID); ok && aws.ToString(r.NetworkInterfaceId) != v.(string) { continue } - if v, ok := d.GetOk(names.AttrTransitGatewayID); ok && aws.StringValue(r.TransitGatewayId) != v.(string) { + if v, ok := d.GetOk(names.AttrTransitGatewayID); ok && aws.ToString(r.TransitGatewayId) != v.(string) { continue } - if v, ok := d.GetOk("vpc_peering_connection_id"); ok && aws.StringValue(r.VpcPeeringConnectionId) != v.(string) { + if v, ok := d.GetOk("vpc_peering_connection_id"); ok && aws.ToString(r.VpcPeeringConnectionId) != v.(string) { continue } @@ -198,11 +198,11 @@ func dataSourceRouteRead(ctx context.Context, d *schema.ResourceData, meta inter route := routes[0] - if destination := aws.StringValue(route.DestinationCidrBlock); destination != "" { + if destination := aws.ToString(route.DestinationCidrBlock); destination != "" { d.SetId(RouteCreateID(routeTableID, destination)) - } else if destination := aws.StringValue(route.DestinationIpv6CidrBlock); destination != "" { + } else if destination := aws.ToString(route.DestinationIpv6CidrBlock); destination != "" { d.SetId(RouteCreateID(routeTableID, destination)) - } else if destination := aws.StringValue(route.DestinationPrefixListId); destination != "" { + } else if destination := aws.ToString(route.DestinationPrefixListId); destination != "" { d.SetId(RouteCreateID(routeTableID, destination)) } diff --git a/internal/service/ec2/vpc_route_data_source_test.go b/internal/service/ec2/vpc_route_data_source_test.go index 43dc52069994..300902cb81fc 100644 --- a/internal/service/ec2/vpc_route_data_source_test.go +++ b/internal/service/ec2/vpc_route_data_source_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -174,8 +174,8 @@ func TestAccVPCRouteDataSource_destinationPrefixListID(t *testing.T) { func TestAccVPCRouteDataSource_gatewayVPCEndpoint(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpce ec2.VpcEndpoint + var routeTable awstypes.RouteTable + var vpce awstypes.VpcEndpoint rtResourceName := "aws_route_table.test" vpceResourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/ec2/vpc_route_table.go b/internal/service/ec2/vpc_route_table.go index 84d18567a2db..b6d7a37970da 100644 --- a/internal/service/ec2/vpc_route_table.go +++ b/internal/service/ec2/vpc_route_table.go @@ -11,10 +11,11 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -167,23 +168,23 @@ func resourceRouteTable() *schema.Resource { func resourceRouteTableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.CreateRouteTableInput{ ClientToken: aws.String(id.UniqueId()), - TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeRouteTable), + TagSpecifications: getTagSpecificationsInV2(ctx, awstypes.ResourceTypeRouteTable), VpcId: aws.String(d.Get(names.AttrVPCID).(string)), } - output, err := conn.CreateRouteTableWithContext(ctx, input) + output, err := conn.CreateRouteTable(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Route Table: %s", err) } - d.SetId(aws.StringValue(output.RouteTable.RouteTableId)) + d.SetId(aws.ToString(output.RouteTable.RouteTableId)) - if _, err := WaitRouteTableReady(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitRouteTableReadyV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route Table (%s) create: %s", d.Id(), err) } @@ -212,10 +213,10 @@ func resourceRouteTableCreate(ctx context.Context, d *schema.ResourceData, meta func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (interface{}, error) { - return FindRouteTableByID(ctx, conn, d.Id()) + return findRouteTableByIDV2(ctx, conn, d.Id()) }, d.IsNewResource()) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -228,11 +229,11 @@ func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "reading Route Table (%s): %s", d.Id(), err) } - routeTable := outputRaw.(*ec2.RouteTable) - ownerID := aws.StringValue(routeTable.OwnerId) + routeTable := outputRaw.(*awstypes.RouteTable) + ownerID := aws.ToString(routeTable.OwnerId) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, AccountID: ownerID, Resource: fmt.Sprintf("route-table/%s", d.Id()), @@ -241,7 +242,7 @@ func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta in d.Set(names.AttrOwnerID, ownerID) propagatingVGWs := make([]string, 0, len(routeTable.PropagatingVgws)) for _, v := range routeTable.PropagatingVgws { - propagatingVGWs = append(propagatingVGWs, aws.StringValue(v.GatewayId)) + propagatingVGWs = append(propagatingVGWs, aws.ToString(v.GatewayId)) } if err := d.Set("propagating_vgws", propagatingVGWs); err != nil { return sdkdiag.AppendErrorf(diags, "setting propagating_vgws: %s", err) @@ -252,14 +253,14 @@ func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta in d.Set(names.AttrVPCID, routeTable.VpcId) // Ignore the AmazonFSx service tag in addition to standard ignores. - setTagsOut(ctx, Tags(KeyValueTags(ctx, routeTable.Tags).Ignore(tftags.New(ctx, []string{"AmazonFSx"})))) + setTagsOutV2(ctx, TagsV2(keyValueTagsV2(ctx, routeTable.Tags).Ignore(tftags.New(ctx, []string{"AmazonFSx"})))) return diags } func resourceRouteTableUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) if d.HasChange("propagating_vgws") { o, n := d.GetChange("propagating_vgws") @@ -350,9 +351,9 @@ func resourceRouteTableUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - routeTable, err := FindRouteTableByID(ctx, conn, d.Id()) + routeTable, err := findRouteTableByIDV2(ctx, conn, d.Id()) if tfresource.NotFound(err) { return diags @@ -364,7 +365,7 @@ func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta // Do all the disassociations for _, v := range routeTable.Associations { - v := aws.StringValue(v.RouteTableAssociationId) + v := aws.ToString(v.RouteTableAssociationId) if err := routeTableAssociationDelete(ctx, conn, v, d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "deleting Route Table (%s): %s", d.Id(), err) @@ -372,7 +373,7 @@ func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta } log.Printf("[INFO] Deleting Route Table: %s", d.Id()) - _, err = conn.DeleteRouteTableWithContext(ctx, &ec2.DeleteRouteTableInput{ + _, err = conn.DeleteRouteTable(ctx, &ec2.DeleteRouteTableInput{ RouteTableId: aws.String(d.Id()), }) @@ -384,7 +385,7 @@ func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "deleting Route Table (%s): %s", d.Id(), err) } - if _, err := WaitRouteTableDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitRouteTableDeletedV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route Table (%s) delete: %s", d.Id(), err) } @@ -456,7 +457,7 @@ func resourceRouteTableHash(v interface{}) int { } // routeTableAddRoute adds a route to the specified route table. -func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { +func routeTableAddRoute(ctx context.Context, conn *ec2.Client, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { if err := validNestedExactlyOneOf(tfMap, routeTableValidDestinations); err != nil { return fmt.Errorf("creating route: %w", err) } @@ -466,15 +467,15 @@ func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, destinationAttributeKey, destination := routeTableRouteDestinationAttribute(tfMap) - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destinationAttributeKey { case "cidr_block": - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case "ipv6_cidr_block": - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case "destination_prefix_list_id": - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return fmt.Errorf("creating Route: unexpected route destination attribute: %q", destinationAttributeKey) } @@ -508,7 +509,7 @@ func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.CreateRouteWithContext(ctx, input) + return conn.CreateRoute(ctx, input) }, errCodeInvalidParameterException, errCodeInvalidTransitGatewayIDNotFound, @@ -518,7 +519,7 @@ func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, return fmt.Errorf("creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err) } - if _, err := WaitRouteReady(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { + if _, err := waitRouteReadyV2(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { return fmt.Errorf("waiting for Route in Route Table (%s) with destination (%s) create: %w", routeTableID, destination, err) } @@ -526,30 +527,30 @@ func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, } // routeTableDeleteRoute deletes a route from the specified route table. -func routeTableDeleteRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { +func routeTableDeleteRoute(ctx context.Context, conn *ec2.Client, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { destinationAttributeKey, destination := routeTableRouteDestinationAttribute(tfMap) input := &ec2.DeleteRouteInput{ RouteTableId: aws.String(routeTableID), } - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destination := aws.String(destination); destinationAttributeKey { case "cidr_block": input.DestinationCidrBlock = destination - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case "ipv6_cidr_block": input.DestinationIpv6CidrBlock = destination - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case "destination_prefix_list_id": input.DestinationPrefixListId = destination - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return fmt.Errorf("deleting Route: unexpected route destination attribute: %q", destinationAttributeKey) } - _, err := conn.DeleteRouteWithContext(ctx, input) + _, err := conn.DeleteRoute(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteNotFound) { return nil @@ -559,7 +560,7 @@ func routeTableDeleteRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri return fmt.Errorf("deleting Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err) } - if _, err := WaitRouteDeleted(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { + if _, err := waitRouteDeletedV2(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { return fmt.Errorf("waiting for Route in Route Table (%s) with destination (%s) delete: %w", routeTableID, destination, err) } @@ -567,7 +568,7 @@ func routeTableDeleteRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri } // routeTableUpdateRoute updates a route in the specified route table. -func routeTableUpdateRoute(ctx context.Context, conn *ec2.EC2, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { +func routeTableUpdateRoute(ctx context.Context, conn *ec2.Client, routeTableID string, tfMap map[string]interface{}, timeout time.Duration) error { if err := validNestedExactlyOneOf(tfMap, routeTableValidDestinations); err != nil { return fmt.Errorf("updating route: %w", err) } @@ -577,15 +578,15 @@ func routeTableUpdateRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri destinationAttributeKey, destination := routeTableRouteDestinationAttribute(tfMap) - var routeFinder RouteFinder + var routeFinder routeFinderV2 switch destinationAttributeKey { case "cidr_block": - routeFinder = FindRouteByIPv4Destination + routeFinder = findRouteByIPv4DestinationV2 case "ipv6_cidr_block": - routeFinder = FindRouteByIPv6Destination + routeFinder = findRouteByIPv6DestinationV2 case "destination_prefix_list_id": - routeFinder = FindRouteByPrefixListIDDestination + routeFinder = findRouteByPrefixListIDDestinationV2 default: return fmt.Errorf("creating Route: unexpected route destination attribute: %q", destinationAttributeKey) } @@ -598,13 +599,13 @@ func routeTableUpdateRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri input.RouteTableId = aws.String(routeTableID) - _, err := conn.ReplaceRouteWithContext(ctx, input) + _, err := conn.ReplaceRoute(ctx, input) if err != nil { return fmt.Errorf("updating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err) } - if _, err := WaitRouteReady(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { + if _, err := waitRouteReadyV2(ctx, conn, routeFinder, routeTableID, destination, timeout); err != nil { return fmt.Errorf("waiting for Route in Route Table (%s) with destination (%s) update: %w", routeTableID, destination, err) } @@ -613,13 +614,13 @@ func routeTableUpdateRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri // routeTableDisableVGWRoutePropagation attempts to disable VGW route propagation. // Any error is returned. -func routeTableDisableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, routeTableID, gatewayID string) error { +func routeTableDisableVGWRoutePropagation(ctx context.Context, conn *ec2.Client, routeTableID, gatewayID string) error { input := &ec2.DisableVgwRoutePropagationInput{ GatewayId: aws.String(gatewayID), RouteTableId: aws.String(routeTableID), } - _, err := conn.DisableVgwRoutePropagationWithContext(ctx, input) + _, err := conn.DisableVgwRoutePropagation(ctx, input) if err != nil { return fmt.Errorf("disabling Route Table (%s) VPN Gateway (%s) route propagation: %w", routeTableID, gatewayID, err) @@ -631,7 +632,7 @@ func routeTableDisableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, ro // routeTableEnableVGWRoutePropagation attempts to enable VGW route propagation. // The specified eventual consistency timeout is respected. // Any error is returned. -func routeTableEnableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, routeTableID, gatewayID string, timeout time.Duration) error { +func routeTableEnableVGWRoutePropagation(ctx context.Context, conn *ec2.Client, routeTableID, gatewayID string, timeout time.Duration) error { input := &ec2.EnableVgwRoutePropagationInput{ GatewayId: aws.String(gatewayID), RouteTableId: aws.String(routeTableID), @@ -639,7 +640,7 @@ func routeTableEnableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, rou _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.EnableVgwRoutePropagationWithContext(ctx, input) + return conn.EnableVgwRoutePropagation(ctx, input) }, errCodeGatewayNotAttached, ) @@ -779,7 +780,7 @@ func expandReplaceRouteInput(tfMap map[string]interface{}) *ec2.ReplaceRouteInpu return apiObject } -func flattenRoute(apiObject *ec2.Route) map[string]interface{} { +func flattenRoute(apiObject *awstypes.Route) map[string]interface{} { if apiObject == nil { return nil } @@ -787,61 +788,61 @@ func flattenRoute(apiObject *ec2.Route) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.DestinationCidrBlock; v != nil { - tfMap["cidr_block"] = aws.StringValue(v) + tfMap["cidr_block"] = aws.ToString(v) } if v := apiObject.DestinationIpv6CidrBlock; v != nil { - tfMap["ipv6_cidr_block"] = aws.StringValue(v) + tfMap["ipv6_cidr_block"] = aws.ToString(v) } if v := apiObject.DestinationPrefixListId; v != nil { - tfMap["destination_prefix_list_id"] = aws.StringValue(v) + tfMap["destination_prefix_list_id"] = aws.ToString(v) } if v := apiObject.CarrierGatewayId; v != nil { - tfMap["carrier_gateway_id"] = aws.StringValue(v) + tfMap["carrier_gateway_id"] = aws.ToString(v) } if v := apiObject.CoreNetworkArn; v != nil { - tfMap["core_network_arn"] = aws.StringValue(v) + tfMap["core_network_arn"] = aws.ToString(v) } if v := apiObject.EgressOnlyInternetGatewayId; v != nil { - tfMap["egress_only_gateway_id"] = aws.StringValue(v) + tfMap["egress_only_gateway_id"] = aws.ToString(v) } if v := apiObject.GatewayId; v != nil { - if strings.HasPrefix(aws.StringValue(v), "vpce-") { - tfMap[names.AttrVPCEndpointID] = aws.StringValue(v) + if strings.HasPrefix(aws.ToString(v), "vpce-") { + tfMap[names.AttrVPCEndpointID] = aws.ToString(v) } else { - tfMap["gateway_id"] = aws.StringValue(v) + tfMap["gateway_id"] = aws.ToString(v) } } if v := apiObject.LocalGatewayId; v != nil { - tfMap["local_gateway_id"] = aws.StringValue(v) + tfMap["local_gateway_id"] = aws.ToString(v) } if v := apiObject.NatGatewayId; v != nil { - tfMap["nat_gateway_id"] = aws.StringValue(v) + tfMap["nat_gateway_id"] = aws.ToString(v) } if v := apiObject.NetworkInterfaceId; v != nil { - tfMap[names.AttrNetworkInterfaceID] = aws.StringValue(v) + tfMap[names.AttrNetworkInterfaceID] = aws.ToString(v) } if v := apiObject.TransitGatewayId; v != nil { - tfMap[names.AttrTransitGatewayID] = aws.StringValue(v) + tfMap[names.AttrTransitGatewayID] = aws.ToString(v) } if v := apiObject.VpcPeeringConnectionId; v != nil { - tfMap["vpc_peering_connection_id"] = aws.StringValue(v) + tfMap["vpc_peering_connection_id"] = aws.ToString(v) } return tfMap } -func flattenRoutes(ctx context.Context, conn *ec2.EC2, d *schema.ResourceData, apiObjects []*ec2.Route) []interface{} { +func flattenRoutes(ctx context.Context, conn *ec2.Client, d *schema.ResourceData, apiObjects []awstypes.Route) []interface{} { if len(apiObjects) == 0 { return nil } @@ -849,42 +850,38 @@ func flattenRoutes(ctx context.Context, conn *ec2.EC2, d *schema.ResourceData, a var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - if gatewayID := aws.StringValue(apiObject.GatewayId); gatewayID == gatewayIDVPCLattice { + if gatewayID := aws.ToString(apiObject.GatewayId); gatewayID == gatewayIDVPCLattice { continue } // local routes from config need to be included but not default local routes, as determined by hasLocalConfig // see local route tests - if gatewayID := aws.StringValue(apiObject.GatewayId); gatewayID == gatewayIDLocal && !hasLocalConfig(d, apiObject) { + if gatewayID := aws.ToString(apiObject.GatewayId); gatewayID == gatewayIDLocal && !hasLocalConfig(d, apiObject) { continue } - if aws.StringValue(apiObject.Origin) == ec2.RouteOriginEnableVgwRoutePropagation { + if apiObject.Origin == awstypes.RouteOriginEnableVgwRoutePropagation { continue } - if apiObject.DestinationPrefixListId != nil && strings.HasPrefix(aws.StringValue(apiObject.GatewayId), "vpce-") { + if apiObject.DestinationPrefixListId != nil && strings.HasPrefix(aws.ToString(apiObject.GatewayId), "vpce-") { // Skipping because VPC endpoint routes are handled separately // See aws_vpc_endpoint continue } // Skip cross-account ENIs for AWS services. - if networkInterfaceID := aws.StringValue(apiObject.NetworkInterfaceId); networkInterfaceID != "" { - networkInterface, err := FindNetworkInterfaceByID(ctx, conn, networkInterfaceID) + if networkInterfaceID := aws.ToString(apiObject.NetworkInterfaceId); networkInterfaceID != "" { + networkInterface, err := findNetworkInterfaceByIDV2(ctx, conn, networkInterfaceID) if err == nil && networkInterface.Attachment != nil { - if ownerID, instanceOwnerID := aws.StringValue(networkInterface.OwnerId), aws.StringValue(networkInterface.Attachment.InstanceOwnerId); ownerID != "" && instanceOwnerID != ownerID { + if ownerID, instanceOwnerID := aws.ToString(networkInterface.OwnerId), aws.ToString(networkInterface.Attachment.InstanceOwnerId); ownerID != "" && instanceOwnerID != ownerID { continue } } } - tfList = append(tfList, flattenRoute(apiObject)) + tfList = append(tfList, flattenRoute(&apiObject)) } return tfList @@ -897,16 +894,13 @@ func flattenRoutes(ctx context.Context, conn *ec2.EC2, d *schema.ResourceData, a // config. However, in this case, a local gateway route in ResourceData must // come from config because of the gatekeeping done by hasLocalConfig and // flattenRoutes. -func hasLocalConfig(d *schema.ResourceData, apiObject *ec2.Route) bool { - if apiObject.GatewayId == nil { - return false - } +func hasLocalConfig(d *schema.ResourceData, apiObject awstypes.Route) bool { if v, ok := d.GetOk("route"); ok && v.(*schema.Set).Len() > 0 { for _, v := range v.(*schema.Set).List() { v := v.(map[string]interface{}) - if v["cidr_block"].(string) != aws.StringValue(apiObject.DestinationCidrBlock) && - v["destination_prefix_list_id"] != aws.StringValue(apiObject.DestinationPrefixListId) && - v["ipv6_cidr_block"] != aws.StringValue(apiObject.DestinationIpv6CidrBlock) { + if v["cidr_block"].(string) != aws.ToString(apiObject.DestinationCidrBlock) && + v["destination_prefix_list_id"] != aws.ToString(apiObject.DestinationPrefixListId) && + v["ipv6_cidr_block"] != aws.ToString(apiObject.DestinationIpv6CidrBlock) { continue } diff --git a/internal/service/ec2/vpc_route_table_association.go b/internal/service/ec2/vpc_route_table_association.go index 1ee7a23a3d84..deb376546048 100644 --- a/internal/service/ec2/vpc_route_table_association.go +++ b/internal/service/ec2/vpc_route_table_association.go @@ -10,9 +10,10 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -61,7 +62,7 @@ func ResourceRouteTableAssociation() *schema.Resource { func resourceRouteTableAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) routeTableID := d.Get("route_table_id").(string) input := &ec2.AssociateRouteTableInput{ @@ -78,7 +79,7 @@ func resourceRouteTableAssociationCreate(ctx context.Context, d *schema.Resource output, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, ec2PropagationTimeout, func() (interface{}, error) { - return conn.AssociateRouteTableWithContext(ctx, input) + return conn.AssociateRouteTable(ctx, input) }, errCodeInvalidRouteTableIDNotFound, ) @@ -87,9 +88,9 @@ func resourceRouteTableAssociationCreate(ctx context.Context, d *schema.Resource return sdkdiag.AppendErrorf(diags, "creating Route Table (%s) Association: %s", routeTableID, err) } - d.SetId(aws.StringValue(output.(*ec2.AssociateRouteTableOutput).AssociationId)) + d.SetId(aws.ToString(output.(*ec2.AssociateRouteTableOutput).AssociationId)) - if _, err := WaitRouteTableAssociationCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitRouteTableAssociationCreatedV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route Table Association (%s) create: %s", d.Id(), err) } @@ -98,10 +99,10 @@ func resourceRouteTableAssociationCreate(ctx context.Context, d *schema.Resource func resourceRouteTableAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, ec2PropagationTimeout, func() (interface{}, error) { - return FindRouteTableAssociationByID(ctx, conn, d.Id()) + return findRouteTableAssociationByIDV2(ctx, conn, d.Id()) }, d.IsNewResource()) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -114,7 +115,7 @@ func resourceRouteTableAssociationRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "reading Route Table Association (%s): %s", d.Id(), err) } - association := outputRaw.(*ec2.RouteTableAssociation) + association := outputRaw.(*awstypes.RouteTableAssociation) d.Set("gateway_id", association.GatewayId) d.Set("route_table_id", association.RouteTableId) @@ -125,15 +126,15 @@ func resourceRouteTableAssociationRead(ctx context.Context, d *schema.ResourceDa func resourceRouteTableAssociationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.ReplaceRouteTableAssociationInput{ AssociationId: aws.String(d.Id()), RouteTableId: aws.String(d.Get("route_table_id").(string)), } - log.Printf("[DEBUG] Updating Route Table Association: %s", input) - output, err := conn.ReplaceRouteTableAssociationWithContext(ctx, input) + log.Printf("[DEBUG] Updating Route Table Association: %v", input) + output, err := conn.ReplaceRouteTableAssociation(ctx, input) // This whole thing with the resource ID being changed on update seems unsustainable. // Keeping it here for backwards compatibility... @@ -150,9 +151,9 @@ func resourceRouteTableAssociationUpdate(ctx context.Context, d *schema.Resource // I don't think we'll ever reach this code for a subnet/gateway route table association. // It would only come in to play for a VPC main route table association. - d.SetId(aws.StringValue(output.NewAssociationId)) + d.SetId(aws.ToString(output.NewAssociationId)) - if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := waitRouteTableAssociationUpdatedV2(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for Route Table Association (%s) update: %s", d.Id(), err) } @@ -161,7 +162,7 @@ func resourceRouteTableAssociationUpdate(ctx context.Context, d *schema.Resource func resourceRouteTableAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) if err := routeTableAssociationDelete(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -180,9 +181,9 @@ func resourceRouteTableAssociationImport(ctx context.Context, d *schema.Resource log.Printf("[DEBUG] Importing route table association, target: %s, route table: %s", targetID, routeTableID) - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) - routeTable, err := FindRouteTableByID(ctx, conn, routeTableID) + routeTable, err := findRouteTableByIDV2(ctx, conn, routeTableID) if err != nil { return nil, err @@ -191,16 +192,16 @@ func resourceRouteTableAssociationImport(ctx context.Context, d *schema.Resource var associationID string for _, association := range routeTable.Associations { - if aws.StringValue(association.SubnetId) == targetID { + if aws.ToString(association.SubnetId) == targetID { d.Set(names.AttrSubnetID, targetID) - associationID = aws.StringValue(association.RouteTableAssociationId) + associationID = aws.ToString(association.RouteTableAssociationId) break } - if aws.StringValue(association.GatewayId) == targetID { + if aws.ToString(association.GatewayId) == targetID { d.Set("gateway_id", targetID) - associationID = aws.StringValue(association.RouteTableAssociationId) + associationID = aws.ToString(association.RouteTableAssociationId) break } @@ -217,9 +218,9 @@ func resourceRouteTableAssociationImport(ctx context.Context, d *schema.Resource } // routeTableAssociationDelete attempts to delete a route table association. -func routeTableAssociationDelete(ctx context.Context, conn *ec2.EC2, associationID string, timeout time.Duration) error { +func routeTableAssociationDelete(ctx context.Context, conn *ec2.Client, associationID string, timeout time.Duration) error { log.Printf("[INFO] Deleting Route Table Association: %s", associationID) - _, err := conn.DisassociateRouteTableWithContext(ctx, &ec2.DisassociateRouteTableInput{ + _, err := conn.DisassociateRouteTable(ctx, &ec2.DisassociateRouteTableInput{ AssociationId: aws.String(associationID), }) @@ -231,7 +232,7 @@ func routeTableAssociationDelete(ctx context.Context, conn *ec2.EC2, association return fmt.Errorf("deleting Route Table Association (%s): %w", associationID, err) } - if _, err := WaitRouteTableAssociationDeleted(ctx, conn, associationID, timeout); err != nil { + if _, err := waitRouteTableAssociationDeletedV2(ctx, conn, associationID, timeout); err != nil { return fmt.Errorf("deleting Route Table Association (%s): waiting for completion: %w", associationID, err) } diff --git a/internal/service/ec2/vpc_route_table_association_test.go b/internal/service/ec2/vpc_route_table_association_test.go index ba9aef2f5f03..633e9a4c81b7 100644 --- a/internal/service/ec2/vpc_route_table_association_test.go +++ b/internal/service/ec2/vpc_route_table_association_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccVPCRouteTableAssociation_Subnet_basic(t *testing.T) { ctx := acctest.Context(t) - var rta ec2.RouteTableAssociation + var rta awstypes.RouteTableAssociation resourceName := "aws_route_table_association.test" resourceNameRouteTable := "aws_route_table.test" resourceNameSubnet := "aws_subnet.test" @@ -53,7 +53,7 @@ func TestAccVPCRouteTableAssociation_Subnet_basic(t *testing.T) { func TestAccVPCRouteTableAssociation_Subnet_changeRouteTable(t *testing.T) { ctx := acctest.Context(t) - var rta ec2.RouteTableAssociation + var rta awstypes.RouteTableAssociation resourceName := "aws_route_table_association.test" resourceNameRouteTable1 := "aws_route_table.test" resourceNameRouteTable2 := "aws_route_table.test2" @@ -88,7 +88,7 @@ func TestAccVPCRouteTableAssociation_Subnet_changeRouteTable(t *testing.T) { func TestAccVPCRouteTableAssociation_Gateway_basic(t *testing.T) { ctx := acctest.Context(t) - var rta ec2.RouteTableAssociation + var rta awstypes.RouteTableAssociation resourceName := "aws_route_table_association.test" resourceNameRouteTable := "aws_route_table.test" resourceNameGateway := "aws_internet_gateway.test" @@ -120,7 +120,7 @@ func TestAccVPCRouteTableAssociation_Gateway_basic(t *testing.T) { func TestAccVPCRouteTableAssociation_Gateway_changeRouteTable(t *testing.T) { ctx := acctest.Context(t) - var rta ec2.RouteTableAssociation + var rta awstypes.RouteTableAssociation resourceName := "aws_route_table_association.test" resourceNameRouteTable1 := "aws_route_table.test" resourceNameRouteTable2 := "aws_route_table.test2" @@ -155,7 +155,7 @@ func TestAccVPCRouteTableAssociation_Gateway_changeRouteTable(t *testing.T) { func TestAccVPCRouteTableAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var rta ec2.RouteTableAssociation + var rta awstypes.RouteTableAssociation resourceName := "aws_route_table_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -179,14 +179,14 @@ func TestAccVPCRouteTableAssociation_disappears(t *testing.T) { func testAccCheckRouteTableAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_route_table_association" { continue } - _, err := tfec2.FindRouteTableAssociationByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindRouteTableAssociationByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -203,7 +203,7 @@ func testAccCheckRouteTableAssociationDestroy(ctx context.Context) resource.Test } } -func testAccCheckRouteTableAssociationExists(ctx context.Context, n string, v *ec2.RouteTableAssociation) resource.TestCheckFunc { +func testAccCheckRouteTableAssociationExists(ctx context.Context, n string, v *awstypes.RouteTableAssociation) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -214,9 +214,9 @@ func testAccCheckRouteTableAssociationExists(ctx context.Context, n string, v *e return fmt.Errorf("No ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - association, err := tfec2.FindRouteTableAssociationByID(ctx, conn, rs.Primary.ID) + association, err := tfec2.FindRouteTableAssociationByIDV2(ctx, conn, rs.Primary.ID) if err != nil { return err diff --git a/internal/service/ec2/vpc_route_table_data_source.go b/internal/service/ec2/vpc_route_table_data_source.go index 8fb2a779c5f3..fa3025ed31da 100644 --- a/internal/service/ec2/vpc_route_table_data_source.go +++ b/internal/service/ec2/vpc_route_table_data_source.go @@ -10,9 +10,10 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -185,7 +186,7 @@ func DataSourceRouteTable() *schema.Resource { func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig req := &ec2.DescribeRouteTablesInput{} @@ -199,7 +200,7 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta if !rtbOk && !vpcIdOk && !subnetIdOk && !gatewayIdOk && !filterOk && !tagsOk { return sdkdiag.AppendErrorf(diags, "one of route_table_id, vpc_id, subnet_id, gateway_id, filters, or tags must be assigned") } - req.Filters = newAttributeFilterList( + req.Filters = newAttributeFilterListV2( map[string]string{ "route-table-id": rtbId.(string), "vpc-id": vpcId.(string), @@ -207,14 +208,14 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta "association.gateway-id": gatewayId.(string), }, ) - req.Filters = append(req.Filters, newTagFilterList( - Tags(tftags.New(ctx, tags.(map[string]interface{}))), + req.Filters = append(req.Filters, newTagFilterListV2( + TagsV2(tftags.New(ctx, tags.(map[string]interface{}))), )...) - req.Filters = append(req.Filters, newCustomFilterList( + req.Filters = append(req.Filters, newCustomFilterListV2( filter.(*schema.Set), )...) - resp, err := conn.DescribeRouteTablesWithContext(ctx, req) + resp, err := conn.DescribeRouteTables(ctx, req) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 VPC Route Table: %s", err) } @@ -227,12 +228,12 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta rt := resp.RouteTables[0] - d.SetId(aws.StringValue(rt.RouteTableId)) + d.SetId(aws.ToString(rt.RouteTableId)) - ownerID := aws.StringValue(rt.OwnerId) + ownerID := aws.ToString(rt.OwnerId) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Service: ec2.ServiceName, + Service: names.EC2, Region: meta.(*conns.AWSClient).Region, AccountID: ownerID, Resource: fmt.Sprintf("route-table/%s", d.Id()), @@ -244,7 +245,7 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta d.Set(names.AttrVPCID, rt.VpcId) //Ignore the AmazonFSx service tag in addition to standard ignores - if err := d.Set(names.AttrTags, KeyValueTags(ctx, rt.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Ignore(tftags.New(ctx, []string{"AmazonFSx"})).Map()); err != nil { + if err := d.Set(names.AttrTags, keyValueTagsV2(ctx, rt.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Ignore(tftags.New(ctx, []string{"AmazonFSx"})).Map()); err != nil { return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) } @@ -259,30 +260,30 @@ func dataSourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta return diags } -func dataSourceRoutesRead(ctx context.Context, conn *ec2.EC2, ec2Routes []*ec2.Route) []map[string]interface{} { +func dataSourceRoutesRead(ctx context.Context, conn *ec2.Client, ec2Routes []awstypes.Route) []map[string]interface{} { routes := make([]map[string]interface{}, 0, len(ec2Routes)) // Loop through the routes and add them to the set for _, r := range ec2Routes { - if gatewayID := aws.StringValue(r.GatewayId); gatewayID == gatewayIDLocal || gatewayID == gatewayIDVPCLattice { + if gatewayID := aws.ToString(r.GatewayId); gatewayID == gatewayIDLocal || gatewayID == gatewayIDVPCLattice { continue } - if aws.StringValue(r.Origin) == ec2.RouteOriginEnableVgwRoutePropagation { + if r.Origin == awstypes.RouteOriginEnableVgwRoutePropagation { continue } - if r.DestinationPrefixListId != nil && strings.HasPrefix(aws.StringValue(r.GatewayId), "vpce-") { + if r.DestinationPrefixListId != nil && strings.HasPrefix(aws.ToString(r.GatewayId), "vpce-") { // Skipping because VPC endpoint routes are handled separately // See aws_vpc_endpoint continue } // Skip cross-account ENIs for AWS services. - if networkInterfaceID := aws.StringValue(r.NetworkInterfaceId); networkInterfaceID != "" { - networkInterface, err := FindNetworkInterfaceByID(ctx, conn, networkInterfaceID) + if networkInterfaceID := aws.ToString(r.NetworkInterfaceId); networkInterfaceID != "" { + networkInterface, err := findNetworkInterfaceByIDV2(ctx, conn, networkInterfaceID) if err == nil && networkInterface.Attachment != nil { - if ownerID, instanceOwnerID := aws.StringValue(networkInterface.OwnerId), aws.StringValue(networkInterface.Attachment.InstanceOwnerId); ownerID != "" && instanceOwnerID != ownerID { + if ownerID, instanceOwnerID := aws.ToString(networkInterface.OwnerId), aws.ToString(networkInterface.Attachment.InstanceOwnerId); ownerID != "" && instanceOwnerID != ownerID { log.Printf("[DEBUG] Skip cross-account ENI (%s)", networkInterfaceID) continue } @@ -292,47 +293,47 @@ func dataSourceRoutesRead(ctx context.Context, conn *ec2.EC2, ec2Routes []*ec2.R m := make(map[string]interface{}) if r.DestinationCidrBlock != nil { - m["cidr_block"] = aws.StringValue(r.DestinationCidrBlock) + m["cidr_block"] = aws.ToString(r.DestinationCidrBlock) } if r.DestinationIpv6CidrBlock != nil { - m["ipv6_cidr_block"] = aws.StringValue(r.DestinationIpv6CidrBlock) + m["ipv6_cidr_block"] = aws.ToString(r.DestinationIpv6CidrBlock) } if r.DestinationPrefixListId != nil { - m["destination_prefix_list_id"] = aws.StringValue(r.DestinationPrefixListId) + m["destination_prefix_list_id"] = aws.ToString(r.DestinationPrefixListId) } if r.CarrierGatewayId != nil { - m["carrier_gateway_id"] = aws.StringValue(r.CarrierGatewayId) + m["carrier_gateway_id"] = aws.ToString(r.CarrierGatewayId) } if r.CoreNetworkArn != nil { - m["core_network_arn"] = aws.StringValue(r.CoreNetworkArn) + m["core_network_arn"] = aws.ToString(r.CoreNetworkArn) } if r.EgressOnlyInternetGatewayId != nil { - m["egress_only_gateway_id"] = aws.StringValue(r.EgressOnlyInternetGatewayId) + m["egress_only_gateway_id"] = aws.ToString(r.EgressOnlyInternetGatewayId) } if r.GatewayId != nil { if strings.HasPrefix(*r.GatewayId, "vpce-") { - m[names.AttrVPCEndpointID] = aws.StringValue(r.GatewayId) + m[names.AttrVPCEndpointID] = aws.ToString(r.GatewayId) } else { - m["gateway_id"] = aws.StringValue(r.GatewayId) + m["gateway_id"] = aws.ToString(r.GatewayId) } } if r.NatGatewayId != nil { - m["nat_gateway_id"] = aws.StringValue(r.NatGatewayId) + m["nat_gateway_id"] = aws.ToString(r.NatGatewayId) } if r.LocalGatewayId != nil { - m["local_gateway_id"] = aws.StringValue(r.LocalGatewayId) + m["local_gateway_id"] = aws.ToString(r.LocalGatewayId) } if r.InstanceId != nil { - m[names.AttrInstanceID] = aws.StringValue(r.InstanceId) + m[names.AttrInstanceID] = aws.ToString(r.InstanceId) } if r.TransitGatewayId != nil { - m[names.AttrTransitGatewayID] = aws.StringValue(r.TransitGatewayId) + m[names.AttrTransitGatewayID] = aws.ToString(r.TransitGatewayId) } if r.VpcPeeringConnectionId != nil { - m["vpc_peering_connection_id"] = aws.StringValue(r.VpcPeeringConnectionId) + m["vpc_peering_connection_id"] = aws.ToString(r.VpcPeeringConnectionId) } if r.NetworkInterfaceId != nil { - m[names.AttrNetworkInterfaceID] = aws.StringValue(r.NetworkInterfaceId) + m[names.AttrNetworkInterfaceID] = aws.ToString(r.NetworkInterfaceId) } routes = append(routes, m) @@ -340,21 +341,21 @@ func dataSourceRoutesRead(ctx context.Context, conn *ec2.EC2, ec2Routes []*ec2.R return routes } -func dataSourceAssociationsRead(ec2Assocations []*ec2.RouteTableAssociation) []map[string]interface{} { +func dataSourceAssociationsRead(ec2Assocations []awstypes.RouteTableAssociation) []map[string]interface{} { associations := make([]map[string]interface{}, 0, len(ec2Assocations)) // Loop through the routes and add them to the set for _, a := range ec2Assocations { m := make(map[string]interface{}) - m["route_table_id"] = aws.StringValue(a.RouteTableId) - m["route_table_association_id"] = aws.StringValue(a.RouteTableAssociationId) + m["route_table_id"] = aws.ToString(a.RouteTableId) + m["route_table_association_id"] = aws.ToString(a.RouteTableAssociationId) // GH[11134] if a.SubnetId != nil { - m[names.AttrSubnetID] = aws.StringValue(a.SubnetId) + m[names.AttrSubnetID] = aws.ToString(a.SubnetId) } if a.GatewayId != nil { - m["gateway_id"] = aws.StringValue(a.GatewayId) + m["gateway_id"] = aws.ToString(a.GatewayId) } - m["main"] = aws.BoolValue(a.Main) + m["main"] = aws.ToBool(a.Main) associations = append(associations, m) } return associations diff --git a/internal/service/ec2/vpc_route_table_test.go b/internal/service/ec2/vpc_route_table_test.go index 1f3d0ada44ac..291720a435cd 100644 --- a/internal/service/ec2/vpc_route_table_test.go +++ b/internal/service/ec2/vpc_route_table_test.go @@ -10,8 +10,9 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -25,7 +26,7 @@ import ( func TestAccVPCRouteTable_basic(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -58,7 +59,7 @@ func TestAccVPCRouteTable_basic(t *testing.T) { func TestAccVPCRouteTable_disappears(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -82,7 +83,7 @@ func TestAccVPCRouteTable_disappears(t *testing.T) { func TestAccVPCRouteTable_Disappears_subnetAssociation(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -106,7 +107,7 @@ func TestAccVPCRouteTable_Disappears_subnetAssociation(t *testing.T) { func TestAccVPCRouteTable_ipv4ToInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -156,7 +157,7 @@ func TestAccVPCRouteTable_ipv4ToInternetGateway(t *testing.T) { func TestAccVPCRouteTable_ipv4ToInstance(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" instanceResourceName := "aws_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -193,7 +194,7 @@ func TestAccVPCRouteTable_ipv4ToInstance(t *testing.T) { func TestAccVPCRouteTable_ipv6ToEgressOnlyInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" eoigwResourceName := "aws_egress_only_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -235,7 +236,7 @@ func TestAccVPCRouteTable_ipv6ToEgressOnlyInternetGateway(t *testing.T) { func TestAccVPCRouteTable_tags(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -321,7 +322,7 @@ func TestAccVPCRouteTable_requireRouteTarget(t *testing.T) { func TestAccVPCRouteTable_Route_mode(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -402,7 +403,7 @@ func TestAccVPCRouteTable_ipv4ToTransitGateway(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" tgwResourceName := "aws_ec2_transit_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -443,7 +444,7 @@ func TestAccVPCRouteTable_ipv4ToVPCEndpoint(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" vpceResourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -451,7 +452,7 @@ func TestAccVPCRouteTable_ipv4ToVPCEndpoint(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"), + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID, "elasticloadbalancing"), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckRouteTableDestroy(ctx), Steps: []resource.TestStep{ @@ -480,7 +481,7 @@ func TestAccVPCRouteTable_ipv4ToVPCEndpoint(t *testing.T) { func TestAccVPCRouteTable_ipv4ToCarrierGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" cgwResourceName := "aws_ec2_carrier_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -517,7 +518,7 @@ func TestAccVPCRouteTable_ipv4ToCarrierGateway(t *testing.T) { func TestAccVPCRouteTable_ipv4ToLocalGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" lgwDataSourceName := "data.aws_ec2_local_gateway.first" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -554,7 +555,7 @@ func TestAccVPCRouteTable_ipv4ToLocalGateway(t *testing.T) { func TestAccVPCRouteTable_ipv4ToVPCPeeringConnection(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" pcxResourceName := "aws_vpc_peering_connection.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -591,7 +592,7 @@ func TestAccVPCRouteTable_ipv4ToVPCPeeringConnection(t *testing.T) { func TestAccVPCRouteTable_vgwRoutePropagation(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" vgwResourceName1 := "aws_vpn_gateway.test1" vgwResourceName2 := "aws_vpn_gateway.test2" @@ -642,7 +643,7 @@ func TestAccVPCRouteTable_vgwRoutePropagation(t *testing.T) { func TestAccVPCRouteTable_conditionalCIDRBlock(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -680,7 +681,7 @@ func TestAccVPCRouteTable_conditionalCIDRBlock(t *testing.T) { func TestAccVPCRouteTable_ipv4ToNatGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" ngwResourceName := "aws_nat_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -717,7 +718,7 @@ func TestAccVPCRouteTable_ipv4ToNatGateway(t *testing.T) { func TestAccVPCRouteTable_IPv6ToNetworkInterface_unattached(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" eniResourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -754,7 +755,7 @@ func TestAccVPCRouteTable_IPv6ToNetworkInterface_unattached(t *testing.T) { func TestAccVPCRouteTable_IPv4ToNetworkInterfaces_unattached(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" eni1ResourceName := "aws_network_interface.test1" eni2ResourceName := "aws_network_interface.test2" @@ -834,7 +835,7 @@ func TestAccVPCRouteTable_IPv4ToNetworkInterfaces_unattached(t *testing.T) { func TestAccVPCRouteTable_vpcMultipleCIDRs(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -868,8 +869,8 @@ func TestAccVPCRouteTable_vpcMultipleCIDRs(t *testing.T) { func TestAccVPCRouteTable_gatewayVPCEndpoint(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpce ec2.VpcEndpoint + var routeTable awstypes.RouteTable + var vpce awstypes.VpcEndpoint resourceName := "aws_route_table.test" vpceResourceName := "aws_vpc_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -908,7 +909,7 @@ func TestAccVPCRouteTable_gatewayVPCEndpoint(t *testing.T) { func TestAccVPCRouteTable_multipleRoutes(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" eoigwResourceName := "aws_egress_only_internet_gateway.test" igwResourceName := "aws_internet_gateway.test" @@ -994,7 +995,7 @@ func TestAccVPCRouteTable_multipleRoutes(t *testing.T) { func TestAccVPCRouteTable_prefixListToInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable + var routeTable awstypes.RouteTable resourceName := "aws_route_table.test" igwResourceName := "aws_internet_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1031,8 +1032,8 @@ func TestAccVPCRouteTable_prefixListToInternetGateway(t *testing.T) { func TestAccVPCRouteTable_localRoute(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_route_table.test" vpcResourceName := "aws_vpc.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1046,7 +1047,7 @@ func TestAccVPCRouteTable_localRoute(t *testing.T) { { Config: testAccVPCRouteTableConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), ), @@ -1063,8 +1064,8 @@ func TestAccVPCRouteTable_localRoute(t *testing.T) { func TestAccVPCRouteTable_localRouteAdoptUpdate(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_route_table.test" vpcResourceName := "aws_vpc.test" eniResourceName := "aws_network_interface.test" @@ -1087,7 +1088,7 @@ func TestAccVPCRouteTable_localRouteAdoptUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4NetworkInterfaceToLocal(rName, vpcCIDR, localGatewayCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "route.*", map[string]string{ @@ -1099,7 +1100,7 @@ func TestAccVPCRouteTable_localRouteAdoptUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4LocalNetworkInterface(rName, vpcCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), testAccCheckRouteTableRoute(resourceName, "cidr_block", vpcCIDR, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), @@ -1108,7 +1109,7 @@ func TestAccVPCRouteTable_localRouteAdoptUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4NetworkInterfaceToLocal(rName, vpcCIDR, localGatewayCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "route.*", map[string]string{ @@ -1123,8 +1124,8 @@ func TestAccVPCRouteTable_localRouteAdoptUpdate(t *testing.T) { func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_route_table.test" rteResourceName := "aws_route.test" vpcResourceName := "aws_vpc.test" @@ -1150,7 +1151,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4NoRoute(rName), Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), ), @@ -1159,9 +1160,9 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { Config: testAccVPCRouteConfig_ipv4Local(rName), ResourceName: rteResourceName, ImportState: true, - ImportStateIdFunc: func(rt *ec2.RouteTable, v *ec2.Vpc) resource.ImportStateIdFunc { + ImportStateIdFunc: func(rt *awstypes.RouteTable, v *awstypes.Vpc) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { - return fmt.Sprintf("%s_%s", aws.StringValue(rt.RouteTableId), aws.StringValue(v.CidrBlock)), nil + return fmt.Sprintf("%s_%s", aws.ToString(rt.RouteTableId), aws.ToString(v.CidrBlock)), nil } }(&routeTable, &vpc), ImportStatePersist: true, @@ -1172,7 +1173,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4LocalToNetworkInterface(rName), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckResourceAttr(rteResourceName, "gateway_id", ""), @@ -1182,7 +1183,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4LocalNetworkInterface(rName, vpcCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), testAccCheckRouteTableRoute(resourceName, "cidr_block", vpcCIDR, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), @@ -1191,7 +1192,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4NetworkInterfaceToLocal(rName, vpcCIDR, localGatewayCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "route.*", map[string]string{ @@ -1203,7 +1204,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { { Config: testAccVPCRouteTableConfig_ipv4LocalNetworkInterface(rName, vpcCIDR, subnetCIDR), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, resourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), testAccCheckRouteTableRoute(resourceName, "cidr_block", vpcCIDR, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), @@ -1213,7 +1214,7 @@ func TestAccVPCRouteTable_localRouteImportUpdate(t *testing.T) { }) } -func testAccCheckRouteTableExists(ctx context.Context, n string, v *ec2.RouteTable) resource.TestCheckFunc { +func testAccCheckRouteTableExists(ctx context.Context, n string, v *awstypes.RouteTable) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -1224,9 +1225,9 @@ func testAccCheckRouteTableExists(ctx context.Context, n string, v *ec2.RouteTab return fmt.Errorf("No ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - routeTable, err := tfec2.FindRouteTableByID(ctx, conn, rs.Primary.ID) + routeTable, err := tfec2.FindRouteTableByIDV2(ctx, conn, rs.Primary.ID) if err != nil { return err @@ -1240,14 +1241,14 @@ func testAccCheckRouteTableExists(ctx context.Context, n string, v *ec2.RouteTab func testAccCheckRouteTableDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_route_table" { continue } - _, err := tfec2.FindRouteTableByID(ctx, conn, rs.Primary.ID) + _, err := tfec2.FindRouteTableByIDV2(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { continue @@ -1264,7 +1265,7 @@ func testAccCheckRouteTableDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckRouteTableNumberOfRoutes(routeTable *ec2.RouteTable, n int) resource.TestCheckFunc { +func testAccCheckRouteTableNumberOfRoutes(routeTable *awstypes.RouteTable, n int) resource.TestCheckFunc { return func(s *terraform.State) error { if len := len(routeTable.Routes); len != n { return fmt.Errorf("Route Table has incorrect number of routes (Expected=%d, Actual=%d)\n", n, len) @@ -1324,13 +1325,13 @@ func testAccCheckRouteTablePrefixListRoute(resourceName, prefixListResourceName, // testAccCheckRouteTableWaitForVPCEndpointRoute returns a TestCheckFunc which waits for // a route to the specified VPC endpoint's prefix list to appear in the specified route table. -func testAccCheckRouteTableWaitForVPCEndpointRoute(ctx context.Context, routeTable *ec2.RouteTable, vpce *ec2.VpcEndpoint) resource.TestCheckFunc { +func testAccCheckRouteTableWaitForVPCEndpointRoute(ctx context.Context, routeTable *awstypes.RouteTable, vpce *awstypes.VpcEndpoint) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - resp, err := conn.DescribePrefixListsWithContext(ctx, &ec2.DescribePrefixListsInput{ - Filters: tfec2.NewAttributeFilterList(map[string]string{ - "prefix-list-name": aws.StringValue(vpce.ServiceName), + resp, err := conn.DescribePrefixLists(ctx, &ec2.DescribePrefixListsInput{ + Filters: tfec2.NewAttributeFilterListV2(map[string]string{ + "prefix-list-name": aws.ToString(vpce.ServiceName), }), }) if err != nil { @@ -1341,11 +1342,11 @@ func testAccCheckRouteTableWaitForVPCEndpointRoute(ctx context.Context, routeTab return fmt.Errorf("Prefix List not found") } - plId := aws.StringValue(resp.PrefixLists[0].PrefixListId) + plId := aws.ToString(resp.PrefixLists[0].PrefixListId) err = retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError { - resp, err := conn.DescribeRouteTablesWithContext(ctx, &ec2.DescribeRouteTablesInput{ - RouteTableIds: []*string{routeTable.RouteTableId}, + resp, err := conn.DescribeRouteTables(ctx, &ec2.DescribeRouteTablesInput{ + RouteTableIds: []string{aws.ToString(routeTable.RouteTableId)}, }) if err != nil { return retry.NonRetryableError(err) @@ -1355,7 +1356,7 @@ func testAccCheckRouteTableWaitForVPCEndpointRoute(ctx context.Context, routeTab } for _, route := range resp.RouteTables[0].Routes { - if aws.StringValue(route.DestinationPrefixListId) == plId { + if aws.ToString(route.DestinationPrefixListId) == plId { return nil } } diff --git a/internal/service/ec2/vpc_route_tables_data_source.go b/internal/service/ec2/vpc_route_tables_data_source.go index 23d66ca12407..4b3dd0cda73a 100644 --- a/internal/service/ec2/vpc_route_tables_data_source.go +++ b/internal/service/ec2/vpc_route_tables_data_source.go @@ -7,8 +7,8 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -44,23 +44,23 @@ func DataSourceRouteTables() *schema.Resource { func dataSourceRouteTablesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) input := &ec2.DescribeRouteTablesInput{} if v, ok := d.GetOk(names.AttrVPCID); ok { - input.Filters = append(input.Filters, newAttributeFilterList( + input.Filters = append(input.Filters, newAttributeFilterListV2( map[string]string{ "vpc-id": v.(string), }, )...) } - input.Filters = append(input.Filters, newTagFilterList( - Tags(tftags.New(ctx, d.Get(names.AttrTags).(map[string]interface{}))), + input.Filters = append(input.Filters, newTagFilterListV2( + TagsV2(tftags.New(ctx, d.Get(names.AttrTags).(map[string]interface{}))), )...) - input.Filters = append(input.Filters, newCustomFilterList( + input.Filters = append(input.Filters, newCustomFilterListV2( d.Get(names.AttrFilter).(*schema.Set), )...) @@ -68,7 +68,7 @@ func dataSourceRouteTablesRead(ctx context.Context, d *schema.ResourceData, meta input.Filters = nil } - output, err := FindRouteTables(ctx, conn, input) + output, err := findRouteTablesV2(ctx, conn, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EC2 Route Tables: %s", err) @@ -77,7 +77,7 @@ func dataSourceRouteTablesRead(ctx context.Context, d *schema.ResourceData, meta var routeTableIDs []string for _, v := range output { - routeTableIDs = append(routeTableIDs, aws.StringValue(v.RouteTableId)) + routeTableIDs = append(routeTableIDs, aws.ToString(v.RouteTableId)) } d.SetId(meta.(*conns.AWSClient).Region) diff --git a/internal/service/ec2/vpc_route_test.go b/internal/service/ec2/vpc_route_test.go index 159368709b09..15334acbf243 100644 --- a/internal/service/ec2/vpc_route_test.go +++ b/internal/service/ec2/vpc_route_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -24,8 +24,8 @@ import ( // IPv4 to Internet Gateway. func TestAccVPCRoute_basic(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route - var routeTable ec2.RouteTable + var route awstypes.Route + var routeTable awstypes.RouteTable resourceName := "aws_route.test" igwResourceName := "aws_internet_gateway.test" rtResourceName := "aws_route_table.test" @@ -56,8 +56,8 @@ func TestAccVPCRoute_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -75,7 +75,7 @@ func TestAccVPCRoute_basic(t *testing.T) { func TestAccVPCRoute_disappears(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) destinationCidr := "10.3.0.0/16" @@ -100,7 +100,7 @@ func TestAccVPCRoute_disappears(t *testing.T) { func TestAccVPCRoute_Disappears_routeTable(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" rtResourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -126,7 +126,7 @@ func TestAccVPCRoute_Disappears_routeTable(t *testing.T) { func TestAccVPCRoute_ipv6ToEgressOnlyInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eoigwResourceName := "aws_egress_only_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -154,8 +154,8 @@ func TestAccVPCRoute_ipv6ToEgressOnlyInternetGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -178,7 +178,7 @@ func TestAccVPCRoute_ipv6ToEgressOnlyInternetGateway(t *testing.T) { func TestAccVPCRoute_ipv6ToInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" igwResourceName := "aws_internet_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -206,8 +206,8 @@ func TestAccVPCRoute_ipv6ToInternetGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -225,7 +225,7 @@ func TestAccVPCRoute_ipv6ToInternetGateway(t *testing.T) { func TestAccVPCRoute_ipv6ToInstance(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" instanceResourceName := "aws_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -253,8 +253,8 @@ func TestAccVPCRoute_ipv6ToInstance(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, instanceResourceName, "primary_network_interface_id"), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -272,7 +272,7 @@ func TestAccVPCRoute_ipv6ToInstance(t *testing.T) { func TestAccVPCRoute_IPv6ToNetworkInterface_unattached(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eniResourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -300,8 +300,8 @@ func TestAccVPCRoute_IPv6ToNetworkInterface_unattached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateBlackhole), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateBlackhole)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -319,7 +319,7 @@ func TestAccVPCRoute_IPv6ToNetworkInterface_unattached(t *testing.T) { func TestAccVPCRoute_ipv6ToVPCPeeringConnection(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" pcxResourceName := "aws_vpc_peering_connection.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -347,8 +347,8 @@ func TestAccVPCRoute_ipv6ToVPCPeeringConnection(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttrPair(resourceName, "vpc_peering_connection_id", pcxResourceName, names.AttrID), @@ -366,7 +366,7 @@ func TestAccVPCRoute_ipv6ToVPCPeeringConnection(t *testing.T) { func TestAccVPCRoute_ipv6ToVPNGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" vgwResourceName := "aws_vpn_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -394,8 +394,8 @@ func TestAccVPCRoute_ipv6ToVPNGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -413,7 +413,7 @@ func TestAccVPCRoute_ipv6ToVPNGateway(t *testing.T) { func TestAccVPCRoute_ipv4ToVPNGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" vgwResourceName := "aws_vpn_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -441,8 +441,8 @@ func TestAccVPCRoute_ipv4ToVPNGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -460,7 +460,7 @@ func TestAccVPCRoute_ipv4ToVPNGateway(t *testing.T) { func TestAccVPCRoute_ipv4ToInstance(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" instanceResourceName := "aws_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -488,8 +488,8 @@ func TestAccVPCRoute_ipv4ToInstance(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, instanceResourceName, "primary_network_interface_id"), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -507,7 +507,7 @@ func TestAccVPCRoute_ipv4ToInstance(t *testing.T) { func TestAccVPCRoute_IPv4ToNetworkInterface_unattached(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eniResourceName := "aws_network_interface.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -535,8 +535,8 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_unattached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateBlackhole), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateBlackhole)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -554,7 +554,7 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_unattached(t *testing.T) { func TestAccVPCRoute_IPv4ToNetworkInterface_attached(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eniResourceName := "aws_network_interface.test" instanceResourceName := "aws_instance.test" @@ -583,8 +583,8 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_attached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -602,7 +602,7 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_attached(t *testing.T) { func TestAccVPCRoute_IPv4ToNetworkInterface_twoAttachments(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eni1ResourceName := "aws_network_interface.test1" eni2ResourceName := "aws_network_interface.test2" @@ -632,8 +632,8 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_twoAttachments(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eni1ResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -655,8 +655,8 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_twoAttachments(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eni2ResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -674,7 +674,7 @@ func TestAccVPCRoute_IPv4ToNetworkInterface_twoAttachments(t *testing.T) { func TestAccVPCRoute_ipv4ToVPCPeeringConnection(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" pcxResourceName := "aws_vpc_peering_connection.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -702,8 +702,8 @@ func TestAccVPCRoute_ipv4ToVPCPeeringConnection(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttrPair(resourceName, "vpc_peering_connection_id", pcxResourceName, names.AttrID), @@ -721,7 +721,7 @@ func TestAccVPCRoute_ipv4ToVPCPeeringConnection(t *testing.T) { func TestAccVPCRoute_ipv4ToNatGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" ngwResourceName := "aws_nat_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -749,8 +749,8 @@ func TestAccVPCRoute_ipv4ToNatGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, "nat_gateway_id", ngwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -768,7 +768,7 @@ func TestAccVPCRoute_ipv4ToNatGateway(t *testing.T) { func TestAccVPCRoute_ipv6ToNatGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" ngwResourceName := "aws_nat_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -796,8 +796,8 @@ func TestAccVPCRoute_ipv6ToNatGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, "nat_gateway_id", ngwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -815,8 +815,8 @@ func TestAccVPCRoute_ipv6ToNatGateway(t *testing.T) { func TestAccVPCRoute_doesNotCrashWithVPCEndpoint(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route - var routeTable ec2.RouteTable + var route awstypes.Route + var routeTable awstypes.RouteTable resourceName := "aws_route.test" rtResourceName := "aws_route_table.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -851,7 +851,7 @@ func TestAccVPCRoute_ipv4ToTransitGateway(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" tgwResourceName := "aws_ec2_transit_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -879,8 +879,8 @@ func TestAccVPCRoute_ipv4ToTransitGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, tgwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -902,7 +902,7 @@ func TestAccVPCRoute_ipv6ToTransitGateway(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" tgwResourceName := "aws_ec2_transit_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -930,8 +930,8 @@ func TestAccVPCRoute_ipv6ToTransitGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, tgwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -949,7 +949,7 @@ func TestAccVPCRoute_ipv6ToTransitGateway(t *testing.T) { func TestAccVPCRoute_ipv4ToCarrierGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" cgwResourceName := "aws_ec2_carrier_gateway.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -977,8 +977,8 @@ func TestAccVPCRoute_ipv4ToCarrierGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -996,7 +996,7 @@ func TestAccVPCRoute_ipv4ToCarrierGateway(t *testing.T) { func TestAccVPCRoute_ipv4ToLocalGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" localGatewayDataSourceName := "data.aws_ec2_local_gateway.first" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1024,8 +1024,8 @@ func TestAccVPCRoute_ipv4ToLocalGateway(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "local_gateway_id", localGatewayDataSourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1043,7 +1043,7 @@ func TestAccVPCRoute_ipv4ToLocalGateway(t *testing.T) { func TestAccVPCRoute_ipv6ToLocalGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" localGatewayDataSourceName := "data.aws_ec2_local_gateway.first" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1071,8 +1071,8 @@ func TestAccVPCRoute_ipv6ToLocalGateway(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "local_gateway_id", localGatewayDataSourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1090,7 +1090,7 @@ func TestAccVPCRoute_ipv6ToLocalGateway(t *testing.T) { func TestAccVPCRoute_conditionalCIDRBlock(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) destinationCidr := "10.2.0.0/16" @@ -1134,7 +1134,7 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" vgwResourceName := "aws_vpn_gateway.test" igwResourceName := "aws_internet_gateway.test" @@ -1148,7 +1148,7 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"), + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID, "elasticloadbalancing"), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckRouteDestroy(ctx), Steps: []resource.TestStep{ @@ -1168,8 +1168,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1191,8 +1191,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1214,8 +1214,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, "nat_gateway_id", ngwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1238,8 +1238,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateBlackhole), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateBlackhole)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1261,8 +1261,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, tgwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1284,8 +1284,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrVPCEndpointID, vpcEndpointResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1307,8 +1307,8 @@ func TestAccVPCRoute_IPv4Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttrPair(resourceName, "vpc_peering_connection_id", pcxResourceName, names.AttrID), @@ -1330,7 +1330,7 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" vgwResourceName := "aws_vpn_gateway.test" igwResourceName := "aws_internet_gateway.test" @@ -1362,8 +1362,8 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1385,8 +1385,8 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1408,8 +1408,8 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1431,8 +1431,8 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateBlackhole), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateBlackhole)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1454,8 +1454,8 @@ func TestAccVPCRoute_IPv6Update_target(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttrPair(resourceName, "vpc_peering_connection_id", pcxResourceName, names.AttrID), @@ -1477,7 +1477,7 @@ func TestAccVPCRoute_ipv4ToVPCEndpoint(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_route.test" vpcEndpointResourceName := "aws_vpc_endpoint.test" @@ -1485,7 +1485,7 @@ func TestAccVPCRoute_ipv4ToVPCEndpoint(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"), + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID, "elasticloadbalancing"), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckRouteDestroy(ctx), Steps: []resource.TestStep{ @@ -1505,8 +1505,8 @@ func TestAccVPCRoute_ipv4ToVPCEndpoint(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrVPCEndpointID, vpcEndpointResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1528,7 +1528,7 @@ func TestAccVPCRoute_ipv6ToVPCEndpoint(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_route.test" vpcEndpointResourceName := "aws_vpc_endpoint.test" @@ -1536,7 +1536,7 @@ func TestAccVPCRoute_ipv6ToVPCEndpoint(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"), + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID, "elasticloadbalancing"), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckRouteDestroy(ctx), Steps: []resource.TestStep{ @@ -1556,8 +1556,8 @@ func TestAccVPCRoute_ipv6ToVPCEndpoint(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrVPCEndpointID, vpcEndpointResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1575,8 +1575,8 @@ func TestAccVPCRoute_ipv6ToVPCEndpoint(t *testing.T) { func TestAccVPCRoute_localRouteCreateError(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc rtResourceName := "aws_route_table.test" vpcResourceName := "aws_vpc.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1590,7 +1590,7 @@ func TestAccVPCRoute_localRouteCreateError(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4NoRoute(rName), Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), ), @@ -1606,8 +1606,8 @@ func TestAccVPCRoute_localRouteCreateError(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/11455. func TestAccVPCRoute_localRouteImport(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_route.test" rtResourceName := "aws_route_table.test" vpcResourceName := "aws_vpc.test" @@ -1622,7 +1622,7 @@ func TestAccVPCRoute_localRouteImport(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4NoRoute(rName), Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), ), @@ -1631,9 +1631,9 @@ func TestAccVPCRoute_localRouteImport(t *testing.T) { Config: testAccVPCRouteConfig_ipv4Local(rName), ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: func(rt *ec2.RouteTable, v *ec2.Vpc) resource.ImportStateIdFunc { + ImportStateIdFunc: func(rt *awstypes.RouteTable, v *awstypes.Vpc) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { - return fmt.Sprintf("%s_%s", aws.StringValue(rt.RouteTableId), aws.StringValue(v.CidrBlock)), nil + return fmt.Sprintf("%s_%s", aws.ToString(rt.RouteTableId), aws.ToString(v.CidrBlock)), nil } }(&routeTable, &vpc), // Don't verify the state as the local route isn't actually in the pre-import state. @@ -1647,8 +1647,8 @@ func TestAccVPCRoute_localRouteImport(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/21350. func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { ctx := acctest.Context(t) - var routeTable ec2.RouteTable - var vpc ec2.Vpc + var routeTable awstypes.RouteTable + var vpc awstypes.Vpc resourceName := "aws_route.test" rtResourceName := "aws_route_table.test" vpcResourceName := "aws_vpc.test" @@ -1664,7 +1664,7 @@ func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4NoRoute(rName), Check: resource.ComposeTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), ), @@ -1673,9 +1673,9 @@ func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { Config: testAccVPCRouteConfig_ipv4Local(rName), ResourceName: resourceName, ImportState: true, - ImportStateIdFunc: func(rt *ec2.RouteTable, v *ec2.Vpc) resource.ImportStateIdFunc { + ImportStateIdFunc: func(rt *awstypes.RouteTable, v *awstypes.Vpc) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { - return fmt.Sprintf("%s_%s", aws.StringValue(rt.RouteTableId), aws.StringValue(v.CidrBlock)), nil + return fmt.Sprintf("%s_%s", aws.ToString(rt.RouteTableId), aws.ToString(v.CidrBlock)), nil } }(&routeTable, &vpc), ImportStatePersist: true, @@ -1686,7 +1686,7 @@ func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4LocalToNetworkInterface(rName), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckResourceAttr(resourceName, "gateway_id", ""), @@ -1696,7 +1696,7 @@ func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { { Config: testAccVPCRouteConfig_ipv4LocalRestore(rName), Check: resource.ComposeAggregateTestCheckFunc( - acctest.CheckVPCExists(ctx, vpcResourceName, &vpc), + acctest.CheckVPCExistsV2(ctx, vpcResourceName, &vpc), testAccCheckRouteTableExists(ctx, rtResourceName, &routeTable), testAccCheckRouteTableNumberOfRoutes(&routeTable, 1), resource.TestCheckResourceAttr(resourceName, "gateway_id", "local"), @@ -1708,7 +1708,7 @@ func TestAccVPCRoute_localRouteImportAndUpdate(t *testing.T) { func TestAccVPCRoute_prefixListToInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" igwResourceName := "aws_internet_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1736,8 +1736,8 @@ func TestAccVPCRoute_prefixListToInternetGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1755,7 +1755,7 @@ func TestAccVPCRoute_prefixListToInternetGateway(t *testing.T) { func TestAccVPCRoute_prefixListToVPNGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" vgwResourceName := "aws_vpn_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1783,8 +1783,8 @@ func TestAccVPCRoute_prefixListToVPNGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1802,7 +1802,7 @@ func TestAccVPCRoute_prefixListToVPNGateway(t *testing.T) { func TestAccVPCRoute_prefixListToInstance(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" instanceResourceName := "aws_instance.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1830,8 +1830,8 @@ func TestAccVPCRoute_prefixListToInstance(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, instanceResourceName, "primary_network_interface_id"), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1849,7 +1849,7 @@ func TestAccVPCRoute_prefixListToInstance(t *testing.T) { func TestAccVPCRoute_PrefixListToNetworkInterface_unattached(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eniResourceName := "aws_network_interface.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1877,8 +1877,8 @@ func TestAccVPCRoute_PrefixListToNetworkInterface_unattached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateBlackhole), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateBlackhole)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1896,7 +1896,7 @@ func TestAccVPCRoute_PrefixListToNetworkInterface_unattached(t *testing.T) { func TestAccVPCRoute_PrefixListToNetworkInterface_attached(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eniResourceName := "aws_network_interface.test" instanceResourceName := "aws_instance.test" @@ -1925,8 +1925,8 @@ func TestAccVPCRoute_PrefixListToNetworkInterface_attached(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, names.AttrNetworkInterfaceID, eniResourceName, names.AttrID), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -1944,7 +1944,7 @@ func TestAccVPCRoute_PrefixListToNetworkInterface_attached(t *testing.T) { func TestAccVPCRoute_prefixListToVPCPeeringConnection(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" pcxResourceName := "aws_vpc_peering_connection.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -1972,8 +1972,8 @@ func TestAccVPCRoute_prefixListToVPCPeeringConnection(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttrPair(resourceName, "vpc_peering_connection_id", pcxResourceName, names.AttrID), @@ -1991,7 +1991,7 @@ func TestAccVPCRoute_prefixListToVPCPeeringConnection(t *testing.T) { func TestAccVPCRoute_prefixListToNatGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" ngwResourceName := "aws_nat_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -2019,8 +2019,8 @@ func TestAccVPCRoute_prefixListToNatGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttrPair(resourceName, "nat_gateway_id", ngwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -2042,7 +2042,7 @@ func TestAccVPCRoute_prefixListToTransitGateway(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" tgwResourceName := "aws_ec2_transit_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -2070,8 +2070,8 @@ func TestAccVPCRoute_prefixListToTransitGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttrPair(resourceName, names.AttrTransitGatewayID, tgwResourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -2089,7 +2089,7 @@ func TestAccVPCRoute_prefixListToTransitGateway(t *testing.T) { func TestAccVPCRoute_prefixListToCarrierGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" cgwResourceName := "aws_ec2_carrier_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -2121,8 +2121,8 @@ func TestAccVPCRoute_prefixListToCarrierGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -2140,7 +2140,7 @@ func TestAccVPCRoute_prefixListToCarrierGateway(t *testing.T) { func TestAccVPCRoute_prefixListToLocalGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" localGatewayDataSourceName := "data.aws_ec2_local_gateway.first" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -2172,8 +2172,8 @@ func TestAccVPCRoute_prefixListToLocalGateway(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "local_gateway_id", localGatewayDataSourceName, names.AttrID), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -2191,7 +2191,7 @@ func TestAccVPCRoute_prefixListToLocalGateway(t *testing.T) { func TestAccVPCRoute_prefixListToEgressOnlyInternetGateway(t *testing.T) { ctx := acctest.Context(t) - var route ec2.Route + var route awstypes.Route resourceName := "aws_route.test" eoigwResourceName := "aws_egress_only_internet_gateway.test" plResourceName := "aws_ec2_managed_prefix_list.test" @@ -2219,8 +2219,8 @@ func TestAccVPCRoute_prefixListToEgressOnlyInternetGateway(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, names.AttrNetworkInterfaceID, ""), - resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), - resource.TestCheckResourceAttr(resourceName, names.AttrState, ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "origin", string(awstypes.RouteOriginCreateRoute)), + resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.RouteStateActive)), resource.TestCheckResourceAttr(resourceName, names.AttrTransitGatewayID, ""), resource.TestCheckResourceAttr(resourceName, names.AttrVPCEndpointID, ""), resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), @@ -2255,7 +2255,7 @@ func TestAccVPCRoute_duplicate(t *testing.T) { }) } -func testAccCheckRouteExists(ctx context.Context, n string, v *ec2.Route) resource.TestCheckFunc { +func testAccCheckRouteExists(ctx context.Context, n string, v *awstypes.Route) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -2266,16 +2266,16 @@ func testAccCheckRouteExists(ctx context.Context, n string, v *ec2.Route) resour return fmt.Errorf("No ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - var route *ec2.Route + var route *awstypes.Route var err error if v := rs.Primary.Attributes["destination_cidr_block"]; v != "" { - route, err = tfec2.FindRouteByIPv4Destination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + route, err = tfec2.FindRouteByIPv4DestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } else if v := rs.Primary.Attributes["destination_ipv6_cidr_block"]; v != "" { - route, err = tfec2.FindRouteByIPv6Destination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + route, err = tfec2.FindRouteByIPv6DestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } else if v := rs.Primary.Attributes["destination_prefix_list_id"]; v != "" { - route, err = tfec2.FindRouteByPrefixListIDDestination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + route, err = tfec2.FindRouteByPrefixListIDDestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } if err != nil { @@ -2295,15 +2295,15 @@ func testAccCheckRouteDestroy(ctx context.Context) resource.TestCheckFunc { continue } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) var err error if v := rs.Primary.Attributes["destination_cidr_block"]; v != "" { - _, err = tfec2.FindRouteByIPv4Destination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + _, err = tfec2.FindRouteByIPv4DestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } else if v := rs.Primary.Attributes["destination_ipv6_cidr_block"]; v != "" { - _, err = tfec2.FindRouteByIPv6Destination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + _, err = tfec2.FindRouteByIPv6DestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } else if v := rs.Primary.Attributes["destination_prefix_list_id"]; v != "" { - _, err = tfec2.FindRouteByPrefixListIDDestination(ctx, conn, rs.Primary.Attributes["route_table_id"], v) + _, err = tfec2.FindRouteByPrefixListIDDestinationV2(ctx, conn, rs.Primary.Attributes["route_table_id"], v) } if tfresource.NotFound(err) { diff --git a/internal/service/ec2/vpnsite_gateway_route_propagation.go b/internal/service/ec2/vpnsite_gateway_route_propagation.go index 72eb40bd1805..801b8f69aebf 100644 --- a/internal/service/ec2/vpnsite_gateway_route_propagation.go +++ b/internal/service/ec2/vpnsite_gateway_route_propagation.go @@ -8,7 +8,7 @@ import ( "log" "time" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -45,7 +45,7 @@ func resourceVPNGatewayRoutePropagation() *schema.Resource { func resourceVPNGatewayRoutePropagationEnable(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) gatewayID := d.Get("vpn_gateway_id").(string) routeTableID := d.Get("route_table_id").(string) @@ -62,7 +62,7 @@ func resourceVPNGatewayRoutePropagationEnable(ctx context.Context, d *schema.Res func resourceVPNGatewayRoutePropagationDisable(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) routeTableID, gatewayID, err := VPNGatewayRoutePropagationParseID(d.Id()) @@ -81,7 +81,7 @@ func resourceVPNGatewayRoutePropagationDisable(ctx context.Context, d *schema.Re func resourceVPNGatewayRoutePropagationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).EC2Conn(ctx) + conn := meta.(*conns.AWSClient).EC2Client(ctx) routeTableID, gatewayID, err := VPNGatewayRoutePropagationParseID(d.Id()) @@ -89,7 +89,7 @@ func resourceVPNGatewayRoutePropagationRead(ctx context.Context, d *schema.Resou return sdkdiag.AppendFromErr(diags, err) } - err = FindVPNGatewayRoutePropagationExists(ctx, conn, routeTableID, gatewayID) + err = findVPNGatewayRoutePropagationExistsV2(ctx, conn, routeTableID, gatewayID) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Route Table (%s) VPN Gateway (%s) route propagation not found, removing from state", routeTableID, gatewayID) diff --git a/internal/service/ec2/vpnsite_gateway_route_propagation_test.go b/internal/service/ec2/vpnsite_gateway_route_propagation_test.go index 41b8c223525c..4f53e6fcab2d 100644 --- a/internal/service/ec2/vpnsite_gateway_route_propagation_test.go +++ b/internal/service/ec2/vpnsite_gateway_route_propagation_test.go @@ -79,9 +79,9 @@ func testAccCheckVPNGatewayRoutePropagationExists(ctx context.Context, n string) return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - return tfec2.FindVPNGatewayRoutePropagationExists(ctx, conn, routeTableID, gatewayID) + return tfec2.FindVPNGatewayRoutePropagationExistsV2(ctx, conn, routeTableID, gatewayID) } } @@ -98,9 +98,9 @@ func testAccCheckVPNGatewayRoutePropagationDestroy(ctx context.Context) resource return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - err = tfec2.FindVPNGatewayRoutePropagationExists(ctx, conn, routeTableID, gatewayID) + err = tfec2.FindVPNGatewayRoutePropagationExistsV2(ctx, conn, routeTableID, gatewayID) if tfresource.NotFound(err) { continue diff --git a/internal/service/ec2/wait.go b/internal/service/ec2/wait.go index 9be5287aeebc..29a40b864d2f 100644 --- a/internal/service/ec2/wait.go +++ b/internal/service/ec2/wait.go @@ -2739,25 +2739,6 @@ func WaitEBSSnapshotImportComplete(ctx context.Context, conn *ec2_sdkv2.Client, return nil, err } -func waitVPCEndpointConnectionAccepted(ctx context.Context, conn *ec2.EC2, serviceID, vpcEndpointID string, timeout time.Duration) (*ec2.VpcEndpointConnection, error) { - stateConf := &retry.StateChangeConf{ - Pending: []string{vpcEndpointStatePendingAcceptance, vpcEndpointStatePending}, - Target: []string{vpcEndpointStateAvailable}, - Refresh: statusVPCEndpointConnectionVPCEndpointState(ctx, conn, serviceID, vpcEndpointID), - Timeout: timeout, - Delay: 5 * time.Second, - MinTimeout: 5 * time.Second, - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if output, ok := outputRaw.(*ec2.VpcEndpointConnection); ok { - return output, err - } - - return nil, err -} - const ( ebsSnapshotArchivedTimeout = 60 * time.Minute ) diff --git a/internal/service/ec2/waitv2.go b/internal/service/ec2/waitv2.go index 36ed1c2f6105..ac1d8c73d741 100644 --- a/internal/service/ec2/waitv2.go +++ b/internal/service/ec2/waitv2.go @@ -6,6 +6,7 @@ package ec2 import ( "context" "errors" + "fmt" "strconv" "time" @@ -172,3 +173,291 @@ func waitNetworkInterfaceDetachedV2(ctx context.Context, conn *ec2.Client, id st return nil, err } + +func waitVPCEndpointAcceptedV2(ctx context.Context, conn *ec2.Client, vpcEndpointID string, timeout time.Duration) (*types.VpcEndpoint, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(vpcEndpointStatePendingAcceptance), + Target: enum.Slice(vpcEndpointStateAvailable), + Timeout: timeout, + Refresh: statusVPCEndpointStateV2(ctx, conn, vpcEndpointID), + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.VpcEndpoint); ok { + if state, lastError := output.State, output.LastError; state == types.StateFailed && lastError != nil { + tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.ToString(lastError.Code), aws.ToString(lastError.Message))) + } + + return output, err + } + + return nil, err +} + +func waitVPCEndpointAvailableV2(ctx context.Context, conn *ec2.Client, vpcEndpointID string, timeout time.Duration) (*types.VpcEndpoint, error) { //nolint:unparam + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(vpcEndpointStatePending), + Target: enum.Slice(vpcEndpointStateAvailable, vpcEndpointStatePendingAcceptance), + Timeout: timeout, + Refresh: statusVPCEndpointStateV2(ctx, conn, vpcEndpointID), + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.VpcEndpoint); ok { + if state, lastError := output.State, output.LastError; state == types.StateFailed && lastError != nil { + tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.ToString(lastError.Code), aws.ToString(lastError.Message))) + } + + return output, err + } + + return nil, err +} + +func waitVPCEndpointDeletedV2(ctx context.Context, conn *ec2.Client, vpcEndpointID string, timeout time.Duration) (*types.VpcEndpoint, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(vpcEndpointStateDeleting, vpcEndpointStateDeleted), + Target: []string{}, + Refresh: statusVPCEndpointStateV2(ctx, conn, vpcEndpointID), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.VpcEndpoint); ok { + return output, err + } + + return nil, err +} + +func waitRouteDeletedV2(ctx context.Context, conn *ec2.Client, routeFinder routeFinderV2, routeTableID, destination string, timeout time.Duration) (*types.Route, error) { //nolint:unparam + stateConf := &retry.StateChangeConf{ + Pending: []string{RouteStatusReady}, + Target: []string{}, + Refresh: statusRouteV2(ctx, conn, routeFinder, routeTableID, destination), + Timeout: timeout, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.Route); ok { + return output, err + } + + return nil, err +} + +func waitRouteReadyV2(ctx context.Context, conn *ec2.Client, routeFinder routeFinderV2, routeTableID, destination string, timeout time.Duration) (*types.Route, error) { //nolint:unparam + stateConf := &retry.StateChangeConf{ + Pending: []string{}, + Target: []string{RouteStatusReady}, + Refresh: statusRouteV2(ctx, conn, routeFinder, routeTableID, destination), + Timeout: timeout, + NotFoundChecks: RouteNotFoundChecks, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.Route); ok { + return output, err + } + + return nil, err +} + +func waitRouteTableReadyV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.RouteTable, error) { + stateConf := &retry.StateChangeConf{ + Pending: []string{}, + Target: []string{RouteTableStatusReady}, + Refresh: statusRouteTableV2(ctx, conn, id), + Timeout: timeout, + NotFoundChecks: RouteTableNotFoundChecks, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.RouteTable); ok { + return output, err + } + + return nil, err +} + +func waitRouteTableDeletedV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.RouteTable, error) { + stateConf := &retry.StateChangeConf{ + Pending: []string{RouteTableStatusReady}, + Target: []string{}, + Refresh: statusRouteTableV2(ctx, conn, id), + Timeout: timeout, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.RouteTable); ok { + return output, err + } + + return nil, err +} + +func waitRouteTableAssociationCreatedV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.RouteTableAssociationState, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(types.RouteTableAssociationStateCodeAssociating), + Target: enum.Slice(types.RouteTableAssociationStateCodeAssociated), + Refresh: statusRouteTableAssociationStateV2(ctx, conn, id), + Timeout: timeout, + NotFoundChecks: RouteTableAssociationCreatedNotFoundChecks, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.RouteTableAssociationState); ok { + if output.State == types.RouteTableAssociationStateCodeFailed { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) + } + + return output, err + } + + return nil, err +} + +func waitRouteTableAssociationDeletedV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.RouteTableAssociationState, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(types.RouteTableAssociationStateCodeDisassociating, types.RouteTableAssociationStateCodeAssociated), + Target: []string{}, + Refresh: statusRouteTableAssociationStateV2(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.RouteTableAssociationState); ok { + if output.State == types.RouteTableAssociationStateCodeFailed { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) + } + + return output, err + } + + return nil, err +} + +func waitRouteTableAssociationUpdatedV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.RouteTableAssociationState, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(types.RouteTableAssociationStateCodeAssociating), + Target: enum.Slice(types.RouteTableAssociationStateCodeAssociated), + Refresh: statusRouteTableAssociationStateV2(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.RouteTableAssociationState); ok { + if output.State == types.RouteTableAssociationStateCodeFailed { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) + } + + return output, err + } + + return nil, err +} + +func waitVPCEndpointServiceAvailableV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.ServiceConfiguration, error) { //nolint:unparam + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(types.ServiceStatePending), + Target: enum.Slice(types.ServiceStateAvailable), + Refresh: statusVPCEndpointServiceStateAvailableV2(ctx, conn, id), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.ServiceConfiguration); ok { + return output, err + } + + return nil, err +} + +func waitVPCEndpointServiceDeletedV2(ctx context.Context, conn *ec2.Client, id string, timeout time.Duration) (*types.ServiceConfiguration, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(types.ServiceStateAvailable, types.ServiceStateDeleting), + Target: []string{}, + Timeout: timeout, + Refresh: statusVPCEndpointServiceStateDeletedV2(ctx, conn, id), + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.ServiceConfiguration); ok { + return output, err + } + + return nil, err +} + +func waitVPCEndpointRouteTableAssociationReadyV2(ctx context.Context, conn *ec2.Client, vpcEndpointID, routeTableID string) error { + stateConf := &retry.StateChangeConf{ + Pending: []string{}, + Target: enum.Slice(VPCEndpointRouteTableAssociationStatusReady), + Refresh: statusVPCEndpointRouteTableAssociationV2(ctx, conn, vpcEndpointID, routeTableID), + Timeout: ec2PropagationTimeout, + ContinuousTargetOccurence: 2, + } + + _, err := stateConf.WaitForStateContext(ctx) + + return err +} + +func waitVPCEndpointRouteTableAssociationDeletedV2(ctx context.Context, conn *ec2.Client, vpcEndpointID, routeTableID string) error { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(VPCEndpointRouteTableAssociationStatusReady), + Target: []string{}, + Refresh: statusVPCEndpointRouteTableAssociationV2(ctx, conn, vpcEndpointID, routeTableID), + Timeout: ec2PropagationTimeout, + ContinuousTargetOccurence: 2, + } + + _, err := stateConf.WaitForStateContext(ctx) + + return err +} + +func waitVPCEndpointConnectionAcceptedV2(ctx context.Context, conn *ec2.Client, serviceID, vpcEndpointID string, timeout time.Duration) (*types.VpcEndpointConnection, error) { + stateConf := &retry.StateChangeConf{ + Pending: []string{vpcEndpointStatePendingAcceptance, vpcEndpointStatePending}, + Target: []string{vpcEndpointStateAvailable}, + Refresh: statusVPCEndpointConnectionVPCEndpointStateV2(ctx, conn, serviceID, vpcEndpointID), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 5 * time.Second, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*types.VpcEndpointConnection); ok { + return output, err + } + + return nil, err +}