forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_zone_V0_to_V1.go
150 lines (129 loc) · 3.21 KB
/
dns_zone_V0_to_V1.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package migration
import (
"context"
"fmt"
"log"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/dns/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
)
var _ pluginsdk.StateUpgrade = DnsZoneV0ToV1{}
type DnsZoneV0ToV1 struct{}
func (DnsZoneV0ToV1) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"resource_group_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"number_of_record_sets": {
Type: pluginsdk.TypeInt,
Computed: true,
},
"max_number_of_record_sets": {
Type: pluginsdk.TypeInt,
Computed: true,
},
"name_servers": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Set: pluginsdk.HashString,
},
"soa_record": {
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
ForceNew: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"email": {
Type: pluginsdk.TypeString,
Required: true,
},
"host_name": {
Type: pluginsdk.TypeString,
Required: true,
},
"expire_time": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 2419200,
},
"minimum_ttl": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 300,
},
"refresh_time": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 3600,
},
"retry_time": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 300,
},
"serial_number": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 1,
},
"ttl": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 3600,
},
"tags": {
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
"tags": {
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
}
}
func (DnsZoneV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
groupsClient := meta.(*clients.Client).Resource.GroupsClient
oldId := rawState["id"].(string)
id, err := parse.DnsZoneID(oldId)
if err != nil {
return rawState, err
}
resGroup, err := groupsClient.Get(ctx, id.ResourceGroup)
if err != nil {
return rawState, err
}
if resGroup.Name == nil {
return rawState, fmt.Errorf("`name` was nil for Resource Group %q", id.ResourceGroup)
}
resourceGroup := *resGroup.Name
name := rawState["name"].(string)
newId := parse.NewDnsZoneID(id.SubscriptionId, resourceGroup, name).ID()
log.Printf("Updating `id` from %q to %q", oldId, newId)
rawState["id"] = newId
return rawState, nil
}
}