Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

r/vpn_connection - modify from/to vgw/tgw #19311

Merged
merged 39 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
884bdc8
modify vpn gateway
DrFaust92 May 11, 2021
6b9f37f
modify transit gateway
DrFaust92 May 11, 2021
4d2e8cb
vgw to tgw to vgw
DrFaust92 May 11, 2021
68d6629
changelog
DrFaust92 May 11, 2021
de95efd
vgw to tgw to vgw
DrFaust92 May 11, 2021
89af712
To ensure PSK changes are in SYnc with the AWS API
meetreks Nov 16, 2021
164037a
r/aws_vpn_connection: Alphabetize attributes.
ewbankkit Jan 6, 2022
d9f1fb2
r/aws_vpn_connection: Tidy up resource Delete.
ewbankkit Jan 6, 2022
e3c444e
r/aws_vpn_connection: Tidy up resource Create and Update.
ewbankkit Jan 7, 2022
1381a43
r/aws_vpn_connection: Tidy up sweeper.
ewbankkit Jan 7, 2022
ef0503a
r/aws_vpn_connection: Tidy up resource READ.
ewbankkit Jan 7, 2022
9cbf3b5
r/aws_vpn_connection: Tidy up flatten and expand.
ewbankkit Jan 7, 2022
9638de4
r/aws_vpn_connection: Tidy up the XML unmarshal.
ewbankkit Jan 7, 2022
ca1bd6c
r/aws_vpn_connection: Corrections.
ewbankkit Jan 9, 2022
678f638
r/aws_vpn_connection: Verify all attributes in basic test.
ewbankkit Jan 9, 2022
881176c
r/aws_vpn_connection: Test calling 'ModifyVpnConnectionOptions'.
ewbankkit Jan 10, 2022
6355c1c
r/aws_vpn_connection: Test calling 'ModifyVpnTunnelOptions'.
ewbankkit Jan 10, 2022
5e803fb
r/aws_vpn_connection: Set attributes even if CustomerGatewayConfigura…
ewbankkit Jan 10, 2022
2b97676
r/aws_vpn_connection: Additional tests of 'ModifyVpnTunnelOptions'.
ewbankkit Jan 10, 2022
e5822d6
Revert "vgw to tgw to vgw"
ewbankkit Jan 10, 2022
b9f5205
Revert "changelog"
ewbankkit Jan 10, 2022
2826d00
Revert "vgw to tgw to vgw"
ewbankkit Jan 10, 2022
ce47308
Revert "modify transit gateway"
ewbankkit Jan 10, 2022
f793635
Revert "modify vpn gateway"
ewbankkit Jan 10, 2022
58af81f
Merge branch 'td-aws_vpn_connection-modernize' into HEAD
ewbankkit Jan 10, 2022
d6195c2
r/aws_vpn_connection: `transit_gateway_id` and `vpn_gateway_id` can b…
ewbankkit Jan 10, 2022
559322b
Merge branch 'main' into HEAD
ewbankkit Jan 10, 2022
9aa0938
r/aws_vpn_connection: Documentation clarifications.
ewbankkit Jan 10, 2022
bfc4104
r/aws_vpn_connection: `customer_gateway_id` can be updated without re…
ewbankkit Jan 10, 2022
1ef1cc8
Revert "To ensure PSK changes are in SYnc with the AWS API"
ewbankkit Jan 10, 2022
38c3da0
Merge branch 'tmp-meetreks/patch-1' into HEAD
ewbankkit Jan 10, 2022
5b18d9f
r/aws_vpn_connection: `tunnel1_preshared_key` and `tunnel2_preshared_…
ewbankkit Jan 10, 2022
9547274
Fix terrafmt errors.
ewbankkit Jan 10, 2022
daecee5
Suppress golangci-lint 'ineffectual assignment to ...' errors.
ewbankkit Jan 11, 2022
46713c2
r/aws_vpn_connection: Document 'routes' and 'vgw_telemetry' attributes.
ewbankkit Jan 11, 2022
02ffdfd
r/aws_vpn_connection: Add 'vgw_telemetry.certificate_arn' attribute.
ewbankkit Jan 11, 2022
82bec52
r/aws_vpn_connection_route: Tidy up resource Create and Delete.
ewbankkit Jan 11, 2022
117a62b
Really fix golangci-lint errors.
ewbankkit Jan 11, 2022
b0648aa
r/aws_vpn_connection_route: Tidy up resource Read.
ewbankkit Jan 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/19311.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_vpn_connection: `customer_gateway_id`, `transit_gateway_id` and `vpn_gateway_id` can be updated without recreating the resource
```

```release-note:enhancement
resource/aws_vpn_connection: `tunnel1_preshared_key` and `tunnel2_preshared_key` can be updated without recreating the resource
```

```release-note:enhancement
resource/aws_vpn_connection: Add `vgw_telemetry.certificate_arn` attribute
```
14 changes: 14 additions & 0 deletions internal/service/ec2/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const (
VpcEndpointStateRejected = "rejected"
)

const (
VpnStateModifying = "modifying"
)

// See https://docs.aws.amazon.com/vm-import/latest/userguide/vmimport-image-import.html#check-import-task-status
const (
EBSSnapshotImportStateActive = "active"
Expand Down Expand Up @@ -53,3 +57,13 @@ const (
CustomerGatewayStateDeleting = "deleting"
CustomerGatewayStatePending = "pending"
)

const (
VpnConnectionTypeIpsec1 = "ipsec.1"
)

func VpnConnectionType_Values() []string {
return []string{
VpnConnectionTypeIpsec1,
}
}
90 changes: 46 additions & 44 deletions internal/service/ec2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,52 @@ import (
)

const (
ErrCodeClientInvalidHostIDNotFound = "Client.InvalidHostID.NotFound"
ErrCodeClientVpnAssociationIdNotFound = "InvalidClientVpnAssociationId.NotFound"
ErrCodeClientVpnAuthorizationRuleNotFound = "InvalidClientVpnEndpointAuthorizationRuleNotFound"
ErrCodeClientVpnEndpointIdNotFound = "InvalidClientVpnEndpointId.NotFound"
ErrCodeClientVpnRouteNotFound = "InvalidClientVpnRouteNotFound"
ErrCodeDependencyViolation = "DependencyViolation"
ErrCodeGatewayNotAttached = "Gateway.NotAttached"
ErrCodeIncorrectState = "IncorrectState"
ErrCodeInvalidAssociationIDNotFound = "InvalidAssociationID.NotFound"
ErrCodeInvalidAttachmentIDNotFound = "InvalidAttachmentID.NotFound"
ErrCodeInvalidCarrierGatewayIDNotFound = "InvalidCarrierGatewayID.NotFound"
ErrCodeInvalidCustomerGatewayIDNotFound = "InvalidCustomerGatewayID.NotFound"
ErrCodeInvalidFlowLogIdNotFound = "InvalidFlowLogId.NotFound"
ErrCodeInvalidGroupNotFound = "InvalidGroup.NotFound"
ErrCodeInvalidHostIDNotFound = "InvalidHostID.NotFound"
ErrCodeInvalidInstanceIDNotFound = "InvalidInstanceID.NotFound"
ErrCodeInvalidInternetGatewayIDNotFound = "InvalidInternetGatewayID.NotFound"
ErrCodeInvalidKeyPairNotFound = "InvalidKeyPair.NotFound"
ErrCodeInvalidNetworkInterfaceIDNotFound = "InvalidNetworkInterfaceID.NotFound"
ErrCodeInvalidParameter = "InvalidParameter"
ErrCodeInvalidParameterException = "InvalidParameterException"
ErrCodeInvalidParameterValue = "InvalidParameterValue"
ErrCodeInvalidPermissionDuplicate = "InvalidPermission.Duplicate"
ErrCodeInvalidPermissionMalformed = "InvalidPermission.Malformed"
ErrCodeInvalidPermissionNotFound = "InvalidPermission.NotFound"
ErrCodeInvalidPlacementGroupUnknown = "InvalidPlacementGroup.Unknown"
ErrCodeInvalidPrefixListIDNotFound = "InvalidPrefixListID.NotFound"
ErrCodeInvalidRouteNotFound = "InvalidRoute.NotFound"
ErrCodeInvalidRouteTableIDNotFound = "InvalidRouteTableID.NotFound"
ErrCodeInvalidRouteTableIdNotFound = "InvalidRouteTableId.NotFound"
ErrCodeInvalidSecurityGroupIDNotFound = "InvalidSecurityGroupID.NotFound"
ErrCodeInvalidSpotInstanceRequestIDNotFound = "InvalidSpotInstanceRequestID.NotFound"
ErrCodeInvalidSubnetCidrReservationIDNotFound = "InvalidSubnetCidrReservationID.NotFound"
ErrCodeInvalidSubnetIDNotFound = "InvalidSubnetID.NotFound"
ErrCodeInvalidSubnetIdNotFound = "InvalidSubnetId.NotFound"
ErrCodeInvalidTransitGatewayIDNotFound = "InvalidTransitGatewayID.NotFound"
ErrCodeInvalidVpcEndpointIdNotFound = "InvalidVpcEndpointId.NotFound"
ErrCodeInvalidVpcEndpointNotFound = "InvalidVpcEndpoint.NotFound"
ErrCodeInvalidVpcEndpointServiceIdNotFound = "InvalidVpcEndpointServiceId.NotFound"
ErrCodeInvalidVpcIDNotFound = "InvalidVpcID.NotFound"
ErrCodeInvalidVpcPeeringConnectionIDNotFound = "InvalidVpcPeeringConnectionID.NotFound"
ErrCodeInvalidVpnGatewayAttachmentNotFound = "InvalidVpnGatewayAttachment.NotFound"
ErrCodeInvalidVpnGatewayIDNotFound = "InvalidVpnGatewayID.NotFound"
ErrCodeInvalidSnapshotNotFound = "InvalidSnapshot.NotFound"
ErrCodeClientInvalidHostIDNotFound = "Client.InvalidHostID.NotFound"
ErrCodeClientVpnAssociationIdNotFound = "InvalidClientVpnAssociationId.NotFound"
ErrCodeClientVpnAuthorizationRuleNotFound = "InvalidClientVpnEndpointAuthorizationRuleNotFound"
ErrCodeClientVpnEndpointIdNotFound = "InvalidClientVpnEndpointId.NotFound"
ErrCodeClientVpnRouteNotFound = "InvalidClientVpnRouteNotFound"
ErrCodeDependencyViolation = "DependencyViolation"
ErrCodeGatewayNotAttached = "Gateway.NotAttached"
ErrCodeIncorrectState = "IncorrectState"
ErrCodeInvalidAssociationIDNotFound = "InvalidAssociationID.NotFound"
ErrCodeInvalidAttachmentIDNotFound = "InvalidAttachmentID.NotFound"
ErrCodeInvalidCarrierGatewayIDNotFound = "InvalidCarrierGatewayID.NotFound"
ErrCodeInvalidCustomerGatewayIDNotFound = "InvalidCustomerGatewayID.NotFound"
ErrCodeInvalidFlowLogIdNotFound = "InvalidFlowLogId.NotFound"
ErrCodeInvalidGroupNotFound = "InvalidGroup.NotFound"
ErrCodeInvalidHostIDNotFound = "InvalidHostID.NotFound"
ErrCodeInvalidInstanceIDNotFound = "InvalidInstanceID.NotFound"
ErrCodeInvalidInternetGatewayIDNotFound = "InvalidInternetGatewayID.NotFound"
ErrCodeInvalidKeyPairNotFound = "InvalidKeyPair.NotFound"
ErrCodeInvalidNetworkInterfaceIDNotFound = "InvalidNetworkInterfaceID.NotFound"
ErrCodeInvalidParameter = "InvalidParameter"
ErrCodeInvalidParameterException = "InvalidParameterException"
ErrCodeInvalidParameterValue = "InvalidParameterValue"
ErrCodeInvalidPermissionDuplicate = "InvalidPermission.Duplicate"
ErrCodeInvalidPermissionMalformed = "InvalidPermission.Malformed"
ErrCodeInvalidPermissionNotFound = "InvalidPermission.NotFound"
ErrCodeInvalidPlacementGroupUnknown = "InvalidPlacementGroup.Unknown"
ErrCodeInvalidPrefixListIDNotFound = "InvalidPrefixListID.NotFound"
ErrCodeInvalidRouteNotFound = "InvalidRoute.NotFound"
ErrCodeInvalidRouteTableIDNotFound = "InvalidRouteTableID.NotFound"
ErrCodeInvalidRouteTableIdNotFound = "InvalidRouteTableId.NotFound"
ErrCodeInvalidSecurityGroupIDNotFound = "InvalidSecurityGroupID.NotFound"
ErrCodeInvalidSnapshotNotFound = "InvalidSnapshot.NotFound"
ErrCodeInvalidSpotInstanceRequestIDNotFound = "InvalidSpotInstanceRequestID.NotFound"
ErrCodeInvalidSubnetCidrReservationIDNotFound = "InvalidSubnetCidrReservationID.NotFound"
ErrCodeInvalidSubnetIDNotFound = "InvalidSubnetID.NotFound"
ErrCodeInvalidSubnetIdNotFound = "InvalidSubnetId.NotFound"
ErrCodeInvalidTransitGatewayAttachmentIDNotFound = "InvalidTransitGatewayAttachmentID.NotFound"
ErrCodeInvalidTransitGatewayIDNotFound = "InvalidTransitGatewayID.NotFound"
ErrCodeInvalidVpcEndpointIdNotFound = "InvalidVpcEndpointId.NotFound"
ErrCodeInvalidVpcEndpointNotFound = "InvalidVpcEndpoint.NotFound"
ErrCodeInvalidVpcEndpointServiceIdNotFound = "InvalidVpcEndpointServiceId.NotFound"
ErrCodeInvalidVpcIDNotFound = "InvalidVpcID.NotFound"
ErrCodeInvalidVpcPeeringConnectionIDNotFound = "InvalidVpcPeeringConnectionID.NotFound"
ErrCodeInvalidVpnConnectionIDNotFound = "InvalidVpnConnectionID.NotFound"
ErrCodeInvalidVpnGatewayAttachmentNotFound = "InvalidVpnGatewayAttachment.NotFound"
ErrCodeInvalidVpnGatewayIDNotFound = "InvalidVpnGatewayID.NotFound"
)

func UnsuccessfulItemError(apiObject *ec2.UnsuccessfulItemError) error {
Expand Down
148 changes: 148 additions & 0 deletions internal/service/ec2/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,154 @@ func FindCustomerGateway(conn *ec2.EC2, input *ec2.DescribeCustomerGatewaysInput
return output.CustomerGateways[0], nil
}

func FindVPNConnectionByID(conn *ec2.EC2, id string) (*ec2.VpnConnection, error) {
input := &ec2.DescribeVpnConnectionsInput{
VpnConnectionIds: aws.StringSlice([]string{id}),
}

output, err := FindVPNConnection(conn, input)

if err != nil {
return nil, err
}

if state := aws.StringValue(output.State); state == ec2.VpnStateDeleted {
return nil, &resource.NotFoundError{
Message: state,
LastRequest: input,
}
}

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

return output, nil
}

func FindVPNConnection(conn *ec2.EC2, input *ec2.DescribeVpnConnectionsInput) (*ec2.VpnConnection, error) {
output, err := conn.DescribeVpnConnections(input)

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

if err != nil {
return nil, err
}

if output == nil || len(output.VpnConnections) == 0 || output.VpnConnections[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(output.VpnConnections); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return output.VpnConnections[0], nil
}

func FindVPNConnectionRouteByVPNConnectionIDAndCIDR(conn *ec2.EC2, vpnConnectionID, cidrBlock string) (*ec2.VpnStaticRoute, error) {
input := &ec2.DescribeVpnConnectionsInput{
Filters: BuildAttributeFilterList(map[string]string{
"route.destination-cidr-block": cidrBlock,
"vpn-connection-id": vpnConnectionID,
}),
}

output, err := FindVPNConnection(conn, input)

if err != nil {
return nil, err
}

for _, v := range output.Routes {
if aws.StringValue(v.DestinationCidrBlock) == cidrBlock && aws.StringValue(v.State) != ec2.VpnStateDeleted {
return v, nil
}
}

return nil, &resource.NotFoundError{
LastError: fmt.Errorf("EC2 VPN Connection (%s) Route (%s) not found", vpnConnectionID, cidrBlock),
}
}

func FindTransitGatewayAttachment(conn *ec2.EC2, input *ec2.DescribeTransitGatewayAttachmentsInput) (*ec2.TransitGatewayAttachment, error) {
output, err := FindTransitGatewayAttachments(conn, input)

if err != nil {
return nil, err
}

if len(output) == 0 || output[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(output); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return output[0], nil
}

func FindTransitGatewayAttachments(conn *ec2.EC2, input *ec2.DescribeTransitGatewayAttachmentsInput) ([]*ec2.TransitGatewayAttachment, error) {
var output []*ec2.TransitGatewayAttachment

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

for _, v := range page.TransitGatewayAttachments {
if v != nil {
output = append(output, v)
}
}

return !lastPage
})

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

if err != nil {
return nil, err
}

return output, nil
}

func FindTransitGatewayAttachmentByID(conn *ec2.EC2, id string) (*ec2.TransitGatewayAttachment, error) {
input := &ec2.DescribeTransitGatewayAttachmentsInput{
TransitGatewayAttachmentIds: aws.StringSlice([]string{id}),
}

output, err := FindTransitGatewayAttachment(conn, input)

if err != nil {
return nil, err
}

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

return output, nil
}

func FindFlowLogByID(conn *ec2.EC2, id string) (*ec2.FlowLog, error) {
input := &ec2.DescribeFlowLogsInput{
FlowLogIds: aws.StringSlice([]string{id}),
Expand Down
32 changes: 32 additions & 0 deletions internal/service/ec2/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,38 @@ func StatusCustomerGatewayState(conn *ec2.EC2, id string) resource.StateRefreshF
}
}

func StatusVPNConnectionState(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindVPNConnectionByID(conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, aws.StringValue(output.State), nil
}
}

func StatusVPNConnectionRouteState(conn *ec2.EC2, vpnConnectionID, cidrBlock string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindVPNConnectionRouteByVPNConnectionIDAndCIDR(conn, vpnConnectionID, cidrBlock)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, aws.StringValue(output.State), nil
}
}

func StatusHostState(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindHostByID(conn, id)
Expand Down
33 changes: 12 additions & 21 deletions internal/service/ec2/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -2044,8 +2044,8 @@ func sweepVPNConnections(region string) error {
}
conn := client.(*conns.AWSClient).EC2Conn
input := &ec2.DescribeVpnConnectionsInput{}
sweepResources := make([]*sweep.SweepResource, 0)

// DescribeVpnConnections does not currently have any form of pagination
output, err := conn.DescribeVpnConnections(input)

if sweep.SkipSweepError(err) {
Expand All @@ -2054,34 +2054,25 @@ func sweepVPNConnections(region string) error {
}

if err != nil {
return fmt.Errorf("error retrieving EC2 VPN Connections: %s", err)
return fmt.Errorf("error listing EC2 VPN Connections (%s): %w", region, err)
}

for _, vpnConnection := range output.VpnConnections {
if aws.StringValue(vpnConnection.State) == ec2.VpnStateDeleted {
for _, v := range output.VpnConnections {
if aws.StringValue(v.State) == ec2.VpnStateDeleted {
continue
}

id := aws.StringValue(vpnConnection.VpnConnectionId)
input := &ec2.DeleteVpnConnectionInput{
VpnConnectionId: vpnConnection.VpnConnectionId,
}

log.Printf("[INFO] Deleting EC2 VPN Connection: %s", id)

_, err := conn.DeleteVpnConnection(input)
r := ResourceVPNConnection()
d := r.Data(nil)
d.SetId(aws.StringValue(v.VpnConnectionId))

if tfawserr.ErrMessageContains(err, "InvalidVpnConnectionID.NotFound", "") {
continue
}
sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}

if err != nil {
return fmt.Errorf("error deleting EC2 VPN Connection (%s): %s", id, err)
}
err = sweep.SweepOrchestrator(sweepResources)

if err := WaitForVPNConnectionDeletion(conn, id); err != nil {
return fmt.Errorf("error waiting for VPN connection (%s) to delete: %s", id, err)
}
if err != nil {
return fmt.Errorf("error sweeping EC2 VPN Connections (%s): %w", region, err)
}

return nil
Expand Down
Loading