@@ -87,7 +87,8 @@ func resourceCDNResource() *schema.Resource {
87
87
Schema : map [string ]* schema.Schema {
88
88
"enabled" : {
89
89
Type : schema .TypeBool ,
90
- Required : true ,
90
+ Optional : true ,
91
+ Default : true ,
91
92
},
92
93
"value" : {
93
94
Type : schema .TypeString ,
@@ -108,6 +109,27 @@ func resourceCDNResource() *schema.Resource {
108
109
},
109
110
},
110
111
},
112
+ "browser_cache_settings" : {
113
+ Type : schema .TypeList ,
114
+ MaxItems : 1 ,
115
+ Optional : true ,
116
+ Computed : true ,
117
+ Description : "" ,
118
+ Elem : & schema.Resource {
119
+ Schema : map [string ]* schema.Schema {
120
+ "enabled" : {
121
+ Type : schema .TypeBool ,
122
+ Optional : true ,
123
+ Default : true ,
124
+ },
125
+ "value" : {
126
+ Type : schema .TypeString ,
127
+ Optional : true ,
128
+ Description : "" ,
129
+ },
130
+ },
131
+ },
132
+ },
111
133
"host_header" : {
112
134
Type : schema .TypeList ,
113
135
MaxItems : 1 ,
@@ -117,7 +139,8 @@ func resourceCDNResource() *schema.Resource {
117
139
Schema : map [string ]* schema.Schema {
118
140
"enabled" : {
119
141
Type : schema .TypeBool ,
120
- Required : true ,
142
+ Optional : true ,
143
+ Default : true ,
121
144
},
122
145
"value" : {
123
146
Type : schema .TypeString ,
@@ -164,6 +187,78 @@ func resourceCDNResource() *schema.Resource {
164
187
},
165
188
},
166
189
},
190
+ "cors" : {
191
+ Type : schema .TypeList ,
192
+ MaxItems : 1 ,
193
+ Optional : true ,
194
+ Description : "" ,
195
+ Elem : & schema.Resource {
196
+ Schema : map [string ]* schema.Schema {
197
+ "enabled" : {
198
+ Type : schema .TypeBool ,
199
+ Optional : true ,
200
+ Default : true ,
201
+ },
202
+ "value" : {
203
+ Type : schema .TypeSet ,
204
+ Elem : & schema.Schema {Type : schema .TypeString },
205
+ Required : true ,
206
+ },
207
+ },
208
+ },
209
+ },
210
+ "rewrite" : {
211
+ Type : schema .TypeList ,
212
+ MaxItems : 1 ,
213
+ Optional : true ,
214
+ Description : "" ,
215
+ Elem : & schema.Resource {
216
+ Schema : map [string ]* schema.Schema {
217
+ "enabled" : {
218
+ Type : schema .TypeBool ,
219
+ Optional : true ,
220
+ Default : true ,
221
+ },
222
+ "body" : {
223
+ Type : schema .TypeString ,
224
+ Required : true ,
225
+ },
226
+ "flag" : {
227
+ Type : schema .TypeString ,
228
+ Optional : true ,
229
+ Default : "break" ,
230
+ },
231
+ },
232
+ },
233
+ },
234
+ "webp" : {
235
+ Type : schema .TypeList ,
236
+ MaxItems : 1 ,
237
+ Optional : true ,
238
+ Description : "" ,
239
+ Elem : & schema.Resource {
240
+ Schema : map [string ]* schema.Schema {
241
+ "enabled" : {
242
+ Type : schema .TypeBool ,
243
+ Optional : true ,
244
+ Default : true ,
245
+ },
246
+ "jpg_quality" : {
247
+ Type : schema .TypeInt ,
248
+ Required : true ,
249
+ },
250
+ "png_quality" : {
251
+ Type : schema .TypeInt ,
252
+ Required : true ,
253
+ },
254
+ "png_lossless" : {
255
+ Type : schema .TypeBool ,
256
+ Optional : true ,
257
+ Default : false ,
258
+ },
259
+ },
260
+ },
261
+ },
167
262
},
168
263
},
169
264
},
@@ -198,6 +293,8 @@ func resourceCDNResourceCreate(ctx context.Context, d *schema.ResourceData, m in
198
293
req .Origin = d .Get ("origin" ).(string )
199
294
req .OriginGroup = d .Get ("origin_group" ).(int )
200
295
296
+ req .Options = listToOptions (d .Get ("options" ).([]interface {}))
297
+
201
298
for _ , hostname := range d .Get ("secondary_hostnames" ).(* schema.Set ).List () {
202
299
req .SecondaryHostnames = append (req .SecondaryHostnames , hostname .(string ))
203
300
}
@@ -323,15 +420,29 @@ func listToOptions(l []interface{}) *gcdn.Options {
323
420
Default : opt ["default" ].(string ),
324
421
}
325
422
}
423
+ if opt , ok := getOptByName (fields , "browser_cache_settings" ); ok {
424
+ enabled := true
425
+ if _ , ok := opt ["enabled" ]; ok {
426
+ enabled = opt ["enabled" ].(bool )
427
+ }
428
+ opts .BrowserCacheSettings = & gcdn.BrowserCacheSettings {
429
+ Enabled : enabled ,
430
+ Value : opt ["value" ].(string ),
431
+ }
432
+ }
326
433
if opt , ok := getOptByName (fields , "host_header" ); ok {
327
434
opts .HostHeader = & gcdn.HostHeader {
328
435
Enabled : opt ["enabled" ].(bool ),
329
436
Value : opt ["value" ].(string ),
330
437
}
331
438
}
332
439
if opt , ok := getOptByName (fields , "redirect_http_to_https" ); ok {
440
+ enabled := true
441
+ if _ , ok := opt ["enabled" ]; ok {
442
+ enabled = opt ["enabled" ].(bool )
443
+ }
333
444
opts .RedirectHttpToHttps = & gcdn.RedirectHttpToHttps {
334
- Enabled : opt [ " enabled" ].( bool ) ,
445
+ Enabled : enabled ,
335
446
Value : opt ["value" ].(bool ),
336
447
}
337
448
}
@@ -345,6 +456,41 @@ func listToOptions(l []interface{}) *gcdn.Options {
345
456
Value : opt ["value" ].(bool ),
346
457
}
347
458
}
459
+ if opt , ok := getOptByName (fields , "cors" ); ok {
460
+ enabled := true
461
+ if _ , ok := opt ["enabled" ]; ok {
462
+ enabled = opt ["enabled" ].(bool )
463
+ }
464
+ opts .Cors = & gcdn.Cors {
465
+ Enabled : enabled ,
466
+ }
467
+ for _ , v := range opt ["value" ].(* schema.Set ).List () {
468
+ opts .Cors .Value = append (opts .Cors .Value , v .(string ))
469
+ }
470
+ }
471
+ if opt , ok := getOptByName (fields , "rewrite" ); ok {
472
+ enabled := true
473
+ if _ , ok := opt ["enabled" ]; ok {
474
+ enabled = opt ["enabled" ].(bool )
475
+ }
476
+ opts .Rewrite = & gcdn.Rewrite {
477
+ Enabled : enabled ,
478
+ Body : opt ["body" ].(string ),
479
+ Flag : opt ["flag" ].(string ),
480
+ }
481
+ }
482
+ if opt , ok := getOptByName (fields , "webp" ); ok {
483
+ enabled := true
484
+ if _ , ok := opt ["enabled" ]; ok {
485
+ enabled = opt ["enabled" ].(bool )
486
+ }
487
+ opts .Webp = & gcdn.Webp {
488
+ Enabled : enabled ,
489
+ JPGQuality : opt ["jpg_quality" ].(int ),
490
+ PNGQuality : opt ["png_quality" ].(int ),
491
+ PNGLossless : opt ["png_lossless" ].(bool ),
492
+ }
493
+ }
348
494
return & opts
349
495
}
350
496
@@ -376,6 +522,10 @@ func optionsToList(options *gcdn.Options) []interface{} {
376
522
m := structToMap (options .EdgeCacheSettings )
377
523
result ["edge_cache_settings" ] = []interface {}{m }
378
524
}
525
+ if options .BrowserCacheSettings != nil {
526
+ m := structToMap (options .BrowserCacheSettings )
527
+ result ["browser_cache_settings" ] = []interface {}{m }
528
+ }
379
529
if options .HostHeader != nil {
380
530
m := structToMap (options .HostHeader )
381
531
result ["host_header" ] = []interface {}{m }
@@ -388,6 +538,18 @@ func optionsToList(options *gcdn.Options) []interface{} {
388
538
m := structToMap (options .GzipOn )
389
539
result ["gzip_on" ] = []interface {}{m }
390
540
}
541
+ if options .Cors != nil {
542
+ m := structToMap (options .Cors )
543
+ result ["cors" ] = []interface {}{m }
544
+ }
545
+ if options .Rewrite != nil {
546
+ m := structToMap (options .Rewrite )
547
+ result ["rewrite" ] = []interface {}{m }
548
+ }
549
+ if options .Webp != nil {
550
+ m := structToMap (options .Webp )
551
+ result ["webp" ] = []interface {}{m }
552
+ }
391
553
return []interface {}{result }
392
554
}
393
555
0 commit comments