-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19741 from dkujawski/dk-FCC-175-fix-aws_dx_gatewa…
…y_association_proposal-2 Fix aws dx gateway association proposal
- Loading branch information
Showing
15 changed files
with
1,104 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:note | ||
resource/aws_dx_gateway_association_proposal: If an accepted Proposal reaches end-of-life and is removed by AWS do not recreate the resource, instead refreshing Terraform state from the resource's Direct Connect Gateway ID and Associated Gateway ID. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package finder | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/directconnect" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func GatewayByID(conn *directconnect.DirectConnect, id string) (*directconnect.Gateway, error) { | ||
input := &directconnect.DescribeDirectConnectGatewaysInput{ | ||
DirectConnectGatewayId: aws.String(id), | ||
} | ||
|
||
output, err := conn.DescribeDirectConnectGateways(input) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil || len(output.DirectConnectGateways) == 0 || output.DirectConnectGateways[0] == nil { | ||
return nil, &resource.NotFoundError{ | ||
Message: "Empty result", | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
// TODO Check for multiple results. | ||
// TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613. | ||
|
||
gateway := output.DirectConnectGateways[0] | ||
|
||
if state := aws.StringValue(gateway.DirectConnectGatewayState); state == directconnect.GatewayStateDeleted { | ||
return nil, &resource.NotFoundError{ | ||
Message: state, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
return gateway, nil | ||
} | ||
|
||
func GatewayAssociationByID(conn *directconnect.DirectConnect, id string) (*directconnect.GatewayAssociation, error) { | ||
input := &directconnect.DescribeDirectConnectGatewayAssociationsInput{ | ||
AssociationId: aws.String(id), | ||
} | ||
|
||
return GatewayAssociation(conn, input) | ||
} | ||
|
||
func GatewayAssociationByDirectConnectGatewayIDAndAssociatedGatewayID(conn *directconnect.DirectConnect, directConnectGatewayID, associatedGatewayID string) (*directconnect.GatewayAssociation, error) { | ||
input := &directconnect.DescribeDirectConnectGatewayAssociationsInput{ | ||
AssociatedGatewayId: aws.String(associatedGatewayID), | ||
DirectConnectGatewayId: aws.String(directConnectGatewayID), | ||
} | ||
|
||
return GatewayAssociation(conn, input) | ||
} | ||
|
||
func GatewayAssociationByDirectConnectGatewayIDAndVirtualGatewayID(conn *directconnect.DirectConnect, directConnectGatewayID, virtualGatewayID string) (*directconnect.GatewayAssociation, error) { | ||
input := &directconnect.DescribeDirectConnectGatewayAssociationsInput{ | ||
DirectConnectGatewayId: aws.String(directConnectGatewayID), | ||
VirtualGatewayId: aws.String(virtualGatewayID), | ||
} | ||
|
||
return GatewayAssociation(conn, input) | ||
} | ||
|
||
func GatewayAssociation(conn *directconnect.DirectConnect, input *directconnect.DescribeDirectConnectGatewayAssociationsInput) (*directconnect.GatewayAssociation, error) { | ||
output, err := conn.DescribeDirectConnectGatewayAssociations(input) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil || len(output.DirectConnectGatewayAssociations) == 0 || output.DirectConnectGatewayAssociations[0] == nil { | ||
return nil, &resource.NotFoundError{ | ||
Message: "Empty result", | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
// TODO Check for multiple results. | ||
// TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613. | ||
|
||
association := output.DirectConnectGatewayAssociations[0] | ||
|
||
if state := aws.StringValue(association.AssociationState); state == directconnect.GatewayAssociationStateDisassociated { | ||
return nil, &resource.NotFoundError{ | ||
Message: state, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
if association.AssociatedGateway == nil { | ||
return nil, &resource.NotFoundError{ | ||
Message: "Empty AssociatedGateway", | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
return association, nil | ||
} | ||
|
||
func GatewayAssociationProposalByID(conn *directconnect.DirectConnect, id string) (*directconnect.GatewayAssociationProposal, error) { | ||
input := &directconnect.DescribeDirectConnectGatewayAssociationProposalsInput{ | ||
ProposalId: aws.String(id), | ||
} | ||
|
||
output, err := conn.DescribeDirectConnectGatewayAssociationProposals(input) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil || len(output.DirectConnectGatewayAssociationProposals) == 0 || output.DirectConnectGatewayAssociationProposals[0] == nil { | ||
return nil, &resource.NotFoundError{ | ||
Message: "Empty result", | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
// TODO Check for multiple results. | ||
// TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613. | ||
|
||
proposal := output.DirectConnectGatewayAssociationProposals[0] | ||
|
||
if state := aws.StringValue(proposal.ProposalState); state == directconnect.GatewayAssociationProposalStateDeleted { | ||
return nil, &resource.NotFoundError{ | ||
Message: state, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
if proposal.AssociatedGateway == nil { | ||
return nil, &resource.NotFoundError{ | ||
Message: "Empty AssociatedGateway", | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
return proposal, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package directconnect | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func GatewayAssociationCreateResourceID(directConnectGatewayID, associatedGatewayID string) string { | ||
return fmt.Sprintf("ga-%s%s", directConnectGatewayID, associatedGatewayID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//go:generate go run ../../../generators/listpages/main.go -function=DescribeDirectConnectGateways,DescribeDirectConnectGatewayAssociations,DescribeDirectConnectGatewayAssociationProposals -paginator=NextToken github.com/aws/aws-sdk-go/service/directconnect | ||
|
||
package lister |
73 changes: 73 additions & 0 deletions
73
aws/internal/service/directconnect/lister/list_pages_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package waiter | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/directconnect" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/directconnect/finder" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" | ||
) | ||
|
||
func GatewayState(conn *directconnect.DirectConnect, id string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
output, err := finder.GatewayByID(conn, id) | ||
|
||
if tfresource.NotFound(err) { | ||
return nil, "", nil | ||
} | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return output, aws.StringValue(output.DirectConnectGatewayState), nil | ||
} | ||
} | ||
|
||
func GatewayAssociationState(conn *directconnect.DirectConnect, id string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
output, err := finder.GatewayAssociationByID(conn, id) | ||
|
||
if tfresource.NotFound(err) { | ||
return nil, "", nil | ||
} | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return output, aws.StringValue(output.AssociationState), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package waiter | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/directconnect" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" | ||
) | ||
|
||
func GatewayCreated(conn *directconnect.DirectConnect, id string, timeout time.Duration) (*directconnect.Gateway, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{directconnect.GatewayStatePending}, | ||
Target: []string{directconnect.GatewayStateAvailable}, | ||
Refresh: GatewayState(conn, id), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*directconnect.Gateway); ok { | ||
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StateChangeError))) | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func GatewayDeleted(conn *directconnect.DirectConnect, id string, timeout time.Duration) (*directconnect.Gateway, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{directconnect.GatewayStatePending, directconnect.GatewayStateAvailable, directconnect.GatewayStateDeleting}, | ||
Target: []string{}, | ||
Refresh: GatewayState(conn, id), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*directconnect.Gateway); ok { | ||
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StateChangeError))) | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func GatewayAssociationCreated(conn *directconnect.DirectConnect, id string, timeout time.Duration) (*directconnect.GatewayAssociation, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{directconnect.GatewayAssociationStateAssociating}, | ||
Target: []string{directconnect.GatewayAssociationStateAssociated}, | ||
Refresh: GatewayAssociationState(conn, id), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*directconnect.GatewayAssociation); ok { | ||
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StateChangeError))) | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func GatewayAssociationUpdated(conn *directconnect.DirectConnect, id string, timeout time.Duration) (*directconnect.GatewayAssociation, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{directconnect.GatewayAssociationStateUpdating}, | ||
Target: []string{directconnect.GatewayAssociationStateAssociated}, | ||
Refresh: GatewayAssociationState(conn, id), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*directconnect.GatewayAssociation); ok { | ||
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StateChangeError))) | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
func GatewayAssociationDeleted(conn *directconnect.DirectConnect, id string, timeout time.Duration) (*directconnect.GatewayAssociation, error) { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{directconnect.GatewayAssociationStateDisassociating}, | ||
Target: []string{}, | ||
Refresh: GatewayAssociationState(conn, id), | ||
Timeout: timeout, | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForState() | ||
|
||
if output, ok := outputRaw.(*directconnect.GatewayAssociation); ok { | ||
tfresource.SetLastError(err, errors.New(aws.StringValue(output.StateChangeError))) | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
Oops, something went wrong.