Skip to content

Commit 2b0f052

Browse files
authored
Merge pull request #8970 from ewbankkit/issue-8956
Fix importing of DX Gateway associations via DX Gateway import
2 parents 95ca4a1 + 80fd014 commit 2b0f052

File tree

2 files changed

+22
-48
lines changed

2 files changed

+22
-48
lines changed

aws/import_aws_dx_gateway.go

-48
This file was deleted.

aws/resource_aws_dx_gateway.go

+22
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ func resourceAwsDxGatewayDelete(d *schema.ResourceData, meta interface{}) error
125125
return nil
126126
}
127127

128+
func resourceAwsDxGatewayImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
129+
conn := meta.(*AWSClient).dxconn
130+
131+
resp, err := conn.DescribeDirectConnectGatewayAssociations(&directconnect.DescribeDirectConnectGatewayAssociationsInput{
132+
DirectConnectGatewayId: aws.String(d.Id()),
133+
})
134+
if err != nil {
135+
return nil, fmt.Errorf("error reading Direct Connect gateway association: %s", err)
136+
}
137+
138+
results := []*schema.ResourceData{d}
139+
for _, assoc := range resp.DirectConnectGatewayAssociations {
140+
d := resourceAwsDxGatewayAssociation().Data(nil)
141+
d.SetType("aws_dx_gateway_association")
142+
d.SetId(dxGatewayAssociationId(aws.StringValue(assoc.DirectConnectGatewayId), aws.StringValue(assoc.AssociatedGateway.Id)))
143+
d.Set("dx_gateway_association_id", assoc.AssociationId)
144+
results = append(results, d)
145+
}
146+
147+
return results, nil
148+
}
149+
128150
func dxGatewayStateRefresh(conn *directconnect.DirectConnect, dxgwId string) resource.StateRefreshFunc {
129151
return func() (interface{}, string, error) {
130152
resp, err := conn.DescribeDirectConnectGateways(&directconnect.DescribeDirectConnectGatewaysInput{

0 commit comments

Comments
 (0)