@@ -10,6 +10,20 @@ import (
10
10
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11
11
)
12
12
13
+ const (
14
+ planIDFree = "free"
15
+ planIDLite = "lite"
16
+ planIDPro = "pro"
17
+ planIDProPlus = "pro_plus"
18
+ planIDBusiness = "business"
19
+ planIDEnterprise = "enterprise"
20
+
21
+ planIDPartnerFree = "partners_free"
22
+ planIDPartnerPro = "partners_pro"
23
+ planIDPartnerBusiness = "partners_business"
24
+ planIDPartnerEnterprise = "partners_enterprise"
25
+ )
26
+
13
27
func TestAccCloudflareZone_Basic (t * testing.T ) {
14
28
rnd := utils .GenerateRandomResourceName ()
15
29
name := "cloudflare_zone." + rnd
@@ -20,30 +34,19 @@ func TestAccCloudflareZone_Basic(t *testing.T) {
20
34
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
21
35
Steps : []resource.TestStep {
22
36
{
23
- Config : testZoneConfig (rnd , fmt .Sprintf ("%s.cfapi.net" , rnd ), accountID ),
37
+ Config : testZoneConfig (rnd , fmt .Sprintf ("%s.cfapi.net" , rnd ), "true" , "false" , accountID ),
24
38
Check : resource .ComposeTestCheckFunc (
25
39
resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
26
40
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
27
41
resource .TestCheckResourceAttr (name , "type" , "full" ),
28
- // Check development_mode
29
- resource .TestCheckResourceAttr (name , "development_mode" , "0" ),
30
- // Spot-check zone metadata
31
- resource .TestCheckResourceAttr (name , "meta.phishing_detected" , "false" ),
32
- // Check owner information
33
- resource .TestCheckResourceAttr (name , "owner.id" , accountID ), resource .TestCheckResourceAttrSet (name , "owner.name" ),
34
- resource .TestCheckResourceAttr (name , "owner.type" , "organization" ),
35
42
),
36
43
},
37
- {
38
- ResourceName : name ,
39
- ImportState : true ,
40
- ImportStateVerify : true ,
41
- },
42
44
},
43
45
})
44
46
}
45
47
46
- func TestAccCloudflareZone_PartialSetup (t * testing.T ) {
48
+ func TestAccCloudflareZone_WithPlan (t * testing.T ) {
49
+ t .Skip (`FIXME: {"success":false,"errors":[{"code":10000,"message":"Authentication error"}]}` )
47
50
rnd := utils .GenerateRandomResourceName ()
48
51
name := "cloudflare_zone." + rnd
49
52
accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
@@ -53,23 +56,18 @@ func TestAccCloudflareZone_PartialSetup(t *testing.T) {
53
56
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
54
57
Steps : []resource.TestStep {
55
58
{
56
- Config : testZoneConfigWithTypeSetup (rnd , accountID , fmt .Sprintf ("%s.net" , rnd ), "partial" ),
59
+ Config : testZoneConfigWithPlan (rnd , fmt .Sprintf ("%s.cfapi. net" , rnd ), "true" , "false" , "free" , accountID ),
57
60
Check : resource .ComposeTestCheckFunc (
58
- resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.net" , rnd )),
59
- resource .TestCheckResourceAttr (name , "type" , "partial" ),
60
- resource .TestCheckResourceAttrSet (name , "verification_key" ),
61
- resource .TestCheckResourceAttr (name , "name_servers.#" , "0" ),
61
+ resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
62
+ resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
63
+ resource .TestCheckResourceAttr (name , "type" , "full" ),
62
64
),
63
65
},
64
- {
65
- ResourceName : name ,
66
- ImportState : true ,
67
- ImportStateVerify : true ,
68
- },
69
- }})
66
+ },
67
+ })
70
68
}
71
69
72
- func TestAccCloudflareZone_FullSetup (t * testing.T ) {
70
+ func TestAccCloudflareZone_PartialSetup (t * testing.T ) {
73
71
rnd := utils .GenerateRandomResourceName ()
74
72
name := "cloudflare_zone." + rnd
75
73
accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
@@ -79,23 +77,17 @@ func TestAccCloudflareZone_FullSetup(t *testing.T) {
79
77
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
80
78
Steps : []resource.TestStep {
81
79
{
82
- Config : testZoneConfigWithTypeSetup (rnd , accountID , fmt . Sprintf ( "%s.cfapi. net" , rnd ) , "full " ),
80
+ Config : testZoneConfigWithTypeSetup (rnd , "foo. net" , "true" , "false" , "free" , accountID , "partial " ),
83
81
Check : resource .ComposeTestCheckFunc (
84
- resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
85
- resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
86
- resource .TestCheckResourceAttr (name , "type" , "full" ),
82
+ resource .TestCheckResourceAttr (name , "name" , "foo.net" ),
83
+ resource .TestCheckResourceAttr (name , "type" , "partial" ),
87
84
),
88
85
},
89
- {
90
- ResourceName : name ,
91
- ImportState : true ,
92
- ImportStateVerify : true ,
93
- },
94
86
},
95
87
})
96
88
}
97
89
98
- func TestAccZoneWithUnicodeIsStoredAsUnicode (t * testing.T ) {
90
+ func TestAccCloudflareZone_FullSetup (t * testing.T ) {
99
91
rnd := utils .GenerateRandomResourceName ()
100
92
name := "cloudflare_zone." + rnd
101
93
accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
@@ -105,23 +97,18 @@ func TestAccZoneWithUnicodeIsStoredAsUnicode(t *testing.T) {
105
97
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
106
98
Steps : []resource.TestStep {
107
99
{
108
- Config : testZoneConfig (rnd , "żółw .cfapi.net" , accountID ),
100
+ Config : testZoneConfigWithTypeSetup (rnd , fmt . Sprintf ( "%s .cfapi.net" , rnd ), "true" , "false" , "free" , accountID , "full" ),
109
101
Check : resource .ComposeTestCheckFunc (
110
- resource .TestCheckResourceAttr (name , "name" , "żółw .cfapi.net" ),
102
+ resource .TestCheckResourceAttr (name , "name" , fmt . Sprintf ( "%s .cfapi.net", rnd ) ),
111
103
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
112
104
resource .TestCheckResourceAttr (name , "type" , "full" ),
113
105
),
114
106
},
115
- {
116
- ResourceName : name ,
117
- ImportState : true ,
118
- ImportStateVerify : true ,
119
- },
120
107
},
121
108
})
122
109
}
123
110
124
- func TestAccZoneWithoutUnicodeIsStoredAsUnicode (t * testing.T ) {
111
+ func TestAccZoneWithUnicodeIsStoredAsUnicode (t * testing.T ) {
125
112
rnd := utils .GenerateRandomResourceName ()
126
113
name := "cloudflare_zone." + rnd
127
114
accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
@@ -131,23 +118,18 @@ func TestAccZoneWithoutUnicodeIsStoredAsUnicode(t *testing.T) {
131
118
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
132
119
Steps : []resource.TestStep {
133
120
{
134
- Config : testZoneConfig (rnd , "xn--w-uga1v8h .cfapi.net" , accountID ),
121
+ Config : testZoneConfig (rnd , "żółw .cfapi.net" , "true" , "false " , accountID ),
135
122
Check : resource .ComposeTestCheckFunc (
136
123
resource .TestCheckResourceAttr (name , "name" , "żółw.cfapi.net" ),
137
124
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
138
125
resource .TestCheckResourceAttr (name , "type" , "full" ),
139
126
),
140
127
},
141
- {
142
- ResourceName : name ,
143
- ImportState : true ,
144
- ImportStateVerify : true ,
145
- },
146
128
},
147
129
})
148
130
}
149
131
150
- func TestAccZonePerformsUnicodeComparison (t * testing.T ) {
132
+ func TestAccCloudflareZone_WithEnterprisePlan (t * testing.T ) {
151
133
rnd := utils .GenerateRandomResourceName ()
152
134
name := "cloudflare_zone." + rnd
153
135
accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
@@ -157,33 +139,20 @@ func TestAccZonePerformsUnicodeComparison(t *testing.T) {
157
139
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
158
140
Steps : []resource.TestStep {
159
141
{
160
- Config : testZoneConfig (rnd , "żółw.cfapi.net" , accountID ),
161
- Check : resource .ComposeTestCheckFunc (
162
- resource .TestCheckResourceAttr (name , "name" , "żółw.cfapi.net" ),
163
- resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
164
- resource .TestCheckResourceAttr (name , "type" , "full" ),
165
- ),
166
- },
167
- {
168
- Config : testZoneConfig (rnd , "xn--w-uga1v8h.cfapi.net" , accountID ),
169
- PlanOnly : true ,
142
+ Config : testZoneConfigWithTypeSetup (rnd , fmt .Sprintf ("%s.cfapi.net" , rnd ), "false" , "false" , "enterprise" , accountID , "full" ),
170
143
Check : resource .ComposeTestCheckFunc (
171
- resource .TestCheckResourceAttr (name , "name" , "żółw.cfapi.net" ),
144
+ resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
145
+ resource .TestCheckResourceAttr (name , "paused" , "false" ),
172
146
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
173
147
resource .TestCheckResourceAttr (name , "type" , "full" ),
174
148
),
175
149
},
176
- {
177
- ResourceName : name ,
178
- ImportState : true ,
179
- ImportStateVerify : true ,
180
- },
181
150
},
182
151
})
183
152
}
184
153
185
154
func TestAccCloudflareZone_WithEnterprisePlanVanityNameServers (t * testing.T ) {
186
- acctest .TestAccSkipForDefaultAccount (t , "Need working zone_subscription to create enterprise plan before setting vanity name servers " )
155
+ acctest .TestAccSkipForDefaultAccount (t , "Pending investigation into vanity nameserver mismatches. " )
187
156
188
157
rnd := utils .GenerateRandomResourceName ()
189
158
name := "cloudflare_zone." + rnd
@@ -195,7 +164,7 @@ func TestAccCloudflareZone_WithEnterprisePlanVanityNameServers(t *testing.T) {
195
164
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
196
165
Steps : []resource.TestStep {
197
166
{
198
- Config : testZoneConfigWithTypeVanityNameServersSetup (rnd , accountID , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "full" ),
167
+ Config : testZoneConfigWithTypeVanityNameServersSetup (rnd , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "false" , "false" , "enterprise" , accountID , "full" ),
199
168
Check : resource .ComposeTestCheckFunc (
200
169
resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.%s" , rnd , zoneName )),
201
170
resource .TestCheckResourceAttr (name , "paused" , "false" ),
@@ -204,11 +173,6 @@ func TestAccCloudflareZone_WithEnterprisePlanVanityNameServers(t *testing.T) {
204
173
resource .TestCheckResourceAttr (name , "vanity_name_servers.#" , "2" ),
205
174
),
206
175
},
207
- {
208
- ResourceName : name ,
209
- ImportState : true ,
210
- ImportStateVerify : true ,
211
- },
212
176
},
213
177
})
214
178
}
@@ -224,24 +188,19 @@ func TestAccCloudflareZone_Secondary(t *testing.T) {
224
188
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
225
189
Steps : []resource.TestStep {
226
190
{
227
- Config : testZoneConfigWithTypeSetup (rnd , accountID , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "secondary" ),
191
+ Config : testZoneConfigWithTypeSetup (rnd , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "true" , "false" , "enterprise" , accountID , "secondary" ),
228
192
Check : resource .ComposeTestCheckFunc (
229
193
resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.%s" , rnd , zoneName )),
230
194
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
231
195
resource .TestCheckResourceAttr (name , "type" , "secondary" ),
232
196
),
233
197
},
234
- {
235
- ResourceName : name ,
236
- ImportState : true ,
237
- ImportStateVerify : true ,
238
- },
239
198
},
240
199
})
241
200
}
242
201
243
202
func TestAccCloudflareZone_SecondaryWithVanityNameServers (t * testing.T ) {
244
- acctest .TestAccSkipForDefaultAccount (t , "Need working zone_subscription to create enterprise plan before setting vanity name servers " )
203
+ acctest .TestAccSkipForDefaultAccount (t , "Pending investigation into vanity nameserver mismatches. " )
245
204
246
205
rnd := utils .GenerateRandomResourceName ()
247
206
name := "cloudflare_zone." + rnd
@@ -253,66 +212,24 @@ func TestAccCloudflareZone_SecondaryWithVanityNameServers(t *testing.T) {
253
212
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
254
213
Steps : []resource.TestStep {
255
214
{
256
- Config : testZoneConfigWithTypeVanityNameServersSetup (rnd , accountID , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "secondary" ),
215
+ Config : testZoneConfigWithTypeVanityNameServersSetup (rnd , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "true" , "false" , "enterprise" , accountID , "secondary" ),
257
216
Check : resource .ComposeTestCheckFunc (
258
217
resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.%s" , rnd , zoneName )),
259
218
resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
260
219
resource .TestCheckResourceAttr (name , "type" , "secondary" ),
261
220
resource .TestCheckResourceAttr (name , "vanity_name_servers.#" , "2" ),
262
221
),
263
222
},
264
- {
265
- ResourceName : name ,
266
- ImportState : true ,
267
- ImportStateVerify : true ,
268
- },
269
223
},
270
224
})
271
225
}
272
226
273
- func TestAccCloudflareZone_TogglePaused (t * testing.T ) {
274
- rnd := utils .GenerateRandomResourceName ()
275
- name := "cloudflare_zone." + rnd
276
- accountID := os .Getenv ("CLOUDFLARE_ACCOUNT_ID" )
227
+ func testZoneConfig (resourceID , zoneName , paused , jumpStart , accountID string ) string {
228
+ return acctest .LoadTestCase ("zoneconfig.tf" , resourceID , zoneName , paused , jumpStart , accountID )
229
+ }
277
230
278
- resource .Test (t , resource.TestCase {
279
- PreCheck : func () { acctest .TestAccPreCheck (t ) },
280
- ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
281
- Steps : []resource.TestStep {
282
- {
283
- Config : testZoneConfigWithPaused (rnd , accountID , fmt .Sprintf ("%s.cfapi.net" , rnd ), false ),
284
- Check : resource .ComposeTestCheckFunc (
285
- resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
286
- resource .TestCheckResourceAttr (name , "paused" , "false" ),
287
- resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
288
- resource .TestCheckResourceAttr (name , "type" , "full" ),
289
- ),
290
- },
291
- {
292
- Config : testZoneConfigWithPaused (rnd , accountID , fmt .Sprintf ("%s.cfapi.net" , rnd ), true ),
293
- Check : resource .ComposeTestCheckFunc (
294
- resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
295
- resource .TestCheckResourceAttr (name , "paused" , "true" ),
296
- resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
297
- resource .TestCheckResourceAttr (name , "type" , "full" ),
298
- ),
299
- },
300
- {
301
- Config : testZoneConfigWithPaused (rnd , accountID , fmt .Sprintf ("%s.cfapi.net" , rnd ), false ),
302
- Check : resource .ComposeTestCheckFunc (
303
- resource .TestCheckResourceAttr (name , "name" , fmt .Sprintf ("%s.cfapi.net" , rnd )),
304
- resource .TestCheckResourceAttr (name , "paused" , "false" ),
305
- resource .TestCheckResourceAttr (name , "name_servers.#" , "2" ),
306
- resource .TestCheckResourceAttr (name , "type" , "full" ),
307
- ),
308
- },
309
- {
310
- ResourceName : name ,
311
- ImportState : true ,
312
- ImportStateVerify : true ,
313
- },
314
- },
315
- })
231
+ func testZoneConfigWithPlan (resourceID , zoneName , paused , jumpStart , plan , accountID string ) string {
232
+ return acctest .LoadTestCase ("zoneconfigwithplan.tf" , resourceID , zoneName , paused , jumpStart , plan , accountID )
316
233
}
317
234
318
235
func TestAccCloudflareZone_SetType (t * testing.T ) {
@@ -325,35 +242,22 @@ func TestAccCloudflareZone_SetType(t *testing.T) {
325
242
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
326
243
Steps : []resource.TestStep {
327
244
{
328
- Config : testZoneConfigWithTypeSetup (rnd , accountID , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "full" ),
245
+ Config : testZoneConfigWithTypeSetup (rnd , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "true" , "false" , "enterprise" , accountID , "full" ),
329
246
},
330
247
{
331
- Config : testZoneConfigWithTypeSetup (rnd , accountID , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "partial" ),
248
+ Config : testZoneConfigWithTypeSetup (rnd , fmt .Sprintf ("%s.%s" , rnd , zoneName ), "true" , "false" , "enterprise" , accountID , "partial" ),
332
249
Check : resource .ComposeTestCheckFunc (
333
250
resource .TestCheckResourceAttr (name , "type" , "partial" ),
334
251
),
335
252
},
336
- {
337
- ResourceName : name ,
338
- ImportState : true ,
339
- ImportStateVerify : true ,
340
- },
341
253
},
342
254
})
343
255
}
344
256
345
- func testZoneConfig (resourceID , zoneName , accountID string ) string {
346
- return acctest .LoadTestCase ("zoneconfig.tf" , resourceID , zoneName , accountID )
347
- }
348
-
349
- func testZoneConfigWithTypeSetup (resourceID , accountID , zoneName , zoneType string ) string {
350
- return acctest .LoadTestCase ("zoneconfigwithtypesetup.tf" , resourceID , accountID , zoneName , zoneType )
351
- }
352
-
353
- func testZoneConfigWithTypeVanityNameServersSetup (resourceID , accountID , zoneName , zoneType string ) string {
354
- return acctest .LoadTestCase ("zoneconfigwithtypevanitynameserverssetup.tf" , resourceID , accountID , zoneName , zoneType )
257
+ func testZoneConfigWithTypeSetup (resourceID , zoneName , paused , jumpStart , plan , accountID , zoneType string ) string {
258
+ return acctest .LoadTestCase ("zoneconfigwithtypesetup.tf" , resourceID , zoneName , paused , jumpStart , plan , accountID , zoneType )
355
259
}
356
260
357
- func testZoneConfigWithPaused (resourceID , accountID , zoneName string , paused bool ) string {
358
- return acctest .LoadTestCase ("zoneconfigwithpaused .tf" , resourceID , accountID , zoneName , paused )
261
+ func testZoneConfigWithTypeVanityNameServersSetup (resourceID , zoneName , paused , jumpStart , plan , accountID , zoneType string ) string {
262
+ return acctest .LoadTestCase ("zoneconfigwithtypevanitynameserverssetup .tf" , resourceID , zoneName , paused , jumpStart , plan , accountID , zoneType )
359
263
}
0 commit comments