-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Copy pathresource_aws_dx_gateway_association_migrate.go
101 lines (84 loc) · 2.88 KB
/
resource_aws_dx_gateway_association_migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/directconnect"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func resourceAwsDxGatewayAssociationResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"allowed_prefixes": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"associated_gateway_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_owner_account_id", "proposal_id", "vpn_gateway_id"},
},
"associated_gateway_owner_account_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateAwsAccountId,
ConflictsWith: []string{"associated_gateway_id", "vpn_gateway_id"},
},
"associated_gateway_type": {
Type: schema.TypeString,
Computed: true,
},
"dx_gateway_association_id": {
Type: schema.TypeString,
Computed: true,
},
"dx_gateway_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"dx_gateway_owner_account_id": {
Type: schema.TypeString,
Computed: true,
},
"proposal_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id", "vpn_gateway_id"},
},
"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id", "associated_gateway_owner_account_id", "proposal_id"},
Deprecated: "use 'associated_gateway_id' argument instead",
},
},
}
}
func resourceAwsDxGatewayAssociationStateUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
conn := meta.(*AWSClient).dxconn
log.Println("[INFO] Found Direct Connect gateway association state v0; migrating to v1")
// dx_gateway_association_id was introduced in v2.8.0. Handle the case where it's not yet present.
if v, ok := rawState["dx_gateway_association_id"]; !ok || v == nil {
resp, err := conn.DescribeDirectConnectGatewayAssociations(&directconnect.DescribeDirectConnectGatewayAssociationsInput{
DirectConnectGatewayId: aws.String(rawState["dx_gateway_id"].(string)),
VirtualGatewayId: aws.String(rawState["vpn_gateway_id"].(string)),
})
if err != nil {
return nil, err
}
if len(resp.DirectConnectGatewayAssociations) == 0 {
return nil, fmt.Errorf("Direct Connect gateway association not found, remove from state using 'terraform state rm'")
}
rawState["dx_gateway_association_id"] = aws.StringValue(resp.DirectConnectGatewayAssociations[0].AssociationId)
}
return rawState, nil
}