Skip to content

Commit

Permalink
Merge pull request #37390 from DanielRieske/f/migrate-vpn-client-sdkv2
Browse files Browse the repository at this point in the history
 Migrate `vpnclient` resources to AWS Go SDKv2
  • Loading branch information
ewbankkit authored May 20, 2024
2 parents ba40b93 + ba8f433 commit cfd77cd
Show file tree
Hide file tree
Showing 18 changed files with 710 additions and 756 deletions.
8 changes: 8 additions & 0 deletions internal/service/ec2/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ package ec2

// Exports for use in tests only.
var (
ResourceClientVPNAuthorizationRule = resourceClientVPNAuthorizationRule
ResourceClientVPNEndpoint = resourceClientVPNEndpoint
ResourceClientVPNNetworkAssociation = resourceClientVPNNetworkAssociation
ResourceClientVPNRoute = resourceClientVPNRoute
ResourceCustomerGateway = resourceCustomerGateway
ResourceDefaultNetworkACL = resourceDefaultNetworkACL
ResourceDefaultRouteTable = resourceDefaultRouteTable
Expand Down Expand Up @@ -32,6 +36,10 @@ var (
ResourceVPNGatewayRoutePropagation = resourceVPNGatewayRoutePropagation

CustomFiltersSchema = customFiltersSchema
FindClientVPNAuthorizationRuleByThreePartKey = findClientVPNAuthorizationRuleByThreePartKey
FindClientVPNEndpointByID = findClientVPNEndpointByID
FindClientVPNNetworkAssociationByTwoPartKey = findClientVPNNetworkAssociationByTwoPartKey
FindClientVPNRouteByThreePartKey = findClientVPNRouteByThreePartKey
FindEBSVolumeAttachment = findVolumeAttachment
FindEIPByAllocationID = findEIPByAllocationID
FindEIPByAssociationID = findEIPByAssociationID
Expand Down
270 changes: 0 additions & 270 deletions internal/service/ec2/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,276 +216,6 @@ func FindCarrierGatewayByID(ctx context.Context, conn *ec2.EC2, id string) (*ec2
return output, nil
}

func FindClientVPNEndpoint(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnEndpointsInput) (*ec2.ClientVpnEndpoint, error) {
output, err := FindClientVPNEndpoints(ctx, conn, input)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output, func(v *ec2.ClientVpnEndpoint) bool { return v.Status != nil })
}

func FindClientVPNEndpoints(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnEndpointsInput) ([]*ec2.ClientVpnEndpoint, error) {
var output []*ec2.ClientVpnEndpoint

err := conn.DescribeClientVpnEndpointsPagesWithContext(ctx, input, func(page *ec2.DescribeClientVpnEndpointsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.ClientVpnEndpoints {
if v == nil {
continue
}

output = append(output, v)
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, errCodeInvalidClientVPNEndpointIdNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
}

func FindClientVPNEndpointByID(ctx context.Context, conn *ec2.EC2, id string) (*ec2.ClientVpnEndpoint, error) {
input := &ec2.DescribeClientVpnEndpointsInput{
ClientVpnEndpointIds: aws.StringSlice([]string{id}),
}

output, err := FindClientVPNEndpoint(ctx, conn, input)

if err != nil {
return nil, err
}

if state := aws.StringValue(output.Status.Code); state == ec2.ClientVpnEndpointStatusCodeDeleted {
return nil, &retry.NotFoundError{
Message: state,
LastRequest: input,
}
}

// Eventual consistency check.
if aws.StringValue(output.ClientVpnEndpointId) != id {
return nil, &retry.NotFoundError{
LastRequest: input,
}
}

return output, nil
}

func FindClientVPNEndpointClientConnectResponseOptionsByID(ctx context.Context, conn *ec2.EC2, id string) (*ec2.ClientConnectResponseOptions, error) {
output, err := FindClientVPNEndpointByID(ctx, conn, id)

if err != nil {
return nil, err
}

if output.ClientConnectOptions == nil || output.ClientConnectOptions.Status == nil {
return nil, tfresource.NewEmptyResultError(id)
}

return output.ClientConnectOptions, nil
}

func FindClientVPNAuthorizationRule(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnAuthorizationRulesInput) (*ec2.AuthorizationRule, error) {
output, err := FindClientVPNAuthorizationRules(ctx, conn, input)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output, func(v *ec2.AuthorizationRule) bool { return v.Status != nil })
}

func FindClientVPNAuthorizationRules(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnAuthorizationRulesInput) ([]*ec2.AuthorizationRule, error) {
var output []*ec2.AuthorizationRule

err := conn.DescribeClientVpnAuthorizationRulesPagesWithContext(ctx, input, func(page *ec2.DescribeClientVpnAuthorizationRulesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.AuthorizationRules {
if v == nil {
continue
}

output = append(output, v)
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, errCodeInvalidClientVPNEndpointIdNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
}

func FindClientVPNAuthorizationRuleByThreePartKey(ctx context.Context, conn *ec2.EC2, endpointID, targetNetworkCIDR, accessGroupID string) (*ec2.AuthorizationRule, error) {
filters := map[string]string{
"destination-cidr": targetNetworkCIDR,
}
if accessGroupID != "" {
filters["group-id"] = accessGroupID
}
input := &ec2.DescribeClientVpnAuthorizationRulesInput{
ClientVpnEndpointId: aws.String(endpointID),
Filters: newAttributeFilterList(filters),
}

return FindClientVPNAuthorizationRule(ctx, conn, input)
}

func FindClientVPNNetworkAssociation(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnTargetNetworksInput) (*ec2.TargetNetwork, error) {
output, err := FindClientVPNNetworkAssociations(ctx, conn, input)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output, func(v *ec2.TargetNetwork) bool { return v.Status != nil })
}

func FindClientVPNNetworkAssociations(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnTargetNetworksInput) ([]*ec2.TargetNetwork, error) {
var output []*ec2.TargetNetwork

err := conn.DescribeClientVpnTargetNetworksPagesWithContext(ctx, input, func(page *ec2.DescribeClientVpnTargetNetworksOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.ClientVpnTargetNetworks {
if v == nil {
continue
}

output = append(output, v)
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, errCodeInvalidClientVPNEndpointIdNotFound, errCodeInvalidClientVPNAssociationIdNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
}

func FindClientVPNNetworkAssociationByIDs(ctx context.Context, conn *ec2.EC2, associationID, endpointID string) (*ec2.TargetNetwork, error) {
input := &ec2.DescribeClientVpnTargetNetworksInput{
AssociationIds: aws.StringSlice([]string{associationID}),
ClientVpnEndpointId: aws.String(endpointID),
}

output, err := FindClientVPNNetworkAssociation(ctx, conn, input)

if err != nil {
return nil, err
}

if state := aws.StringValue(output.Status.Code); state == ec2.AssociationStatusCodeDisassociated {
return nil, &retry.NotFoundError{
Message: state,
LastRequest: input,
}
}

// Eventual consistency check.
if aws.StringValue(output.ClientVpnEndpointId) != endpointID || aws.StringValue(output.AssociationId) != associationID {
return nil, &retry.NotFoundError{
LastRequest: input,
}
}

return output, nil
}

func FindClientVPNRoute(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnRoutesInput) (*ec2.ClientVpnRoute, error) {
output, err := FindClientVPNRoutes(ctx, conn, input)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output, func(v *ec2.ClientVpnRoute) bool { return v.Status != nil })
}

func FindClientVPNRoutes(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeClientVpnRoutesInput) ([]*ec2.ClientVpnRoute, error) {
var output []*ec2.ClientVpnRoute

err := conn.DescribeClientVpnRoutesPagesWithContext(ctx, input, func(page *ec2.DescribeClientVpnRoutesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.Routes {
if v == nil {
continue
}

output = append(output, v)
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, errCodeInvalidClientVPNEndpointIdNotFound) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
}

func FindClientVPNRouteByThreePartKey(ctx context.Context, conn *ec2.EC2, endpointID, targetSubnetID, destinationCIDR string) (*ec2.ClientVpnRoute, error) {
input := &ec2.DescribeClientVpnRoutesInput{
ClientVpnEndpointId: aws.String(endpointID),
Filters: newAttributeFilterList(map[string]string{
"destination-cidr": destinationCIDR,
"target-subnet": targetSubnetID,
}),
}

return FindClientVPNRoute(ctx, conn, input)
}

func FindCOIPPools(ctx context.Context, conn *ec2.EC2, input *ec2.DescribeCoipPoolsInput) ([]*ec2.CoipPool, error) {
var output []*ec2.CoipPool

Expand Down
Loading

0 comments on commit cfd77cd

Please sign in to comment.