@@ -105,6 +105,49 @@ func resourceComputeBackendService() *schema.Resource {
105
105
},
106
106
},
107
107
108
+ "cdn_policy" : & schema.Schema {
109
+ Type : schema .TypeList ,
110
+ Optional : true ,
111
+ MaxItems : 1 ,
112
+ Elem : & schema.Resource {
113
+ Schema : map [string ]* schema.Schema {
114
+ "cache_key_policy" : & schema.Schema {
115
+ Type : schema .TypeList ,
116
+ Optional : true ,
117
+ MaxItems : 1 ,
118
+ Elem : & schema.Resource {
119
+ Schema : map [string ]* schema.Schema {
120
+ "include_host" : & schema.Schema {
121
+ Type : schema .TypeBool ,
122
+ Optional : true ,
123
+ },
124
+ "include_protocol" : & schema.Schema {
125
+ Type : schema .TypeBool ,
126
+ Optional : true ,
127
+ },
128
+ "include_query_string" : & schema.Schema {
129
+ Type : schema .TypeBool ,
130
+ Optional : true ,
131
+ },
132
+ "query_string_blacklist" : & schema.Schema {
133
+ Type : schema .TypeSet ,
134
+ Optional : true ,
135
+ Elem : & schema.Schema {Type : schema .TypeString },
136
+ ConflictsWith : []string {"cdn_policy.0.cache_key_policy.query_string_whitelist" },
137
+ },
138
+ "query_string_whitelist" : & schema.Schema {
139
+ Type : schema .TypeSet ,
140
+ Optional : true ,
141
+ Elem : & schema.Schema {Type : schema .TypeString },
142
+ ConflictsWith : []string {"cdn_policy.0.cache_key_policy.query_string_blacklist" },
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ },
150
+
108
151
"description" : & schema.Schema {
109
152
Type : schema .TypeString ,
110
153
Optional : true ,
@@ -237,6 +280,9 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
237
280
d .Set ("iap" , flattenIap (service .Iap ))
238
281
d .Set ("project" , project )
239
282
d .Set ("health_checks" , service .HealthChecks )
283
+ if err := d .Set ("cdn_policy" , flattenCdnPolicy (service .CdnPolicy )); err != nil {
284
+ return err
285
+ }
240
286
241
287
return nil
242
288
}
@@ -409,6 +455,11 @@ func expandBackendService(d *schema.ResourceData) (*compute.BackendService, erro
409
455
Iap : & compute.BackendServiceIAP {
410
456
ForceSendFields : []string {"Enabled" , "Oauth2ClientId" , "Oauth2ClientSecret" },
411
457
},
458
+ CdnPolicy : & compute.BackendServiceCdnPolicy {
459
+ CacheKeyPolicy : & compute.CacheKeyPolicy {
460
+ ForceSendFields : []string {"IncludeProtocol" , "IncludeHost" , "IncludeQueryString" , "QueryStringWhitelist" , "QueryStringBlacklist" },
461
+ },
462
+ },
412
463
}
413
464
414
465
if v , ok := d .GetOk ("iap" ); ok {
@@ -454,5 +505,55 @@ func expandBackendService(d *schema.ResourceData) (*compute.BackendService, erro
454
505
455
506
service .ConnectionDraining = connectionDraining
456
507
508
+ if v , ok := d .GetOk ("cdn_policy" ); ok {
509
+ c := expandCdnPolicy (v .([]interface {}))
510
+ if c != nil {
511
+ service .CdnPolicy = c
512
+ }
513
+ }
514
+
457
515
return service , nil
458
516
}
517
+
518
+ func expandCdnPolicy (configured []interface {}) * compute.BackendServiceCdnPolicy {
519
+ if len (configured ) == 0 {
520
+ return nil
521
+ }
522
+ data := configured [0 ].(map [string ]interface {})
523
+
524
+ ckp := data ["cache_key_policy" ].([]interface {})
525
+ if len (ckp ) == 0 {
526
+ return nil
527
+ }
528
+ ckpData := ckp [0 ].(map [string ]interface {})
529
+
530
+ return & compute.BackendServiceCdnPolicy {
531
+ CacheKeyPolicy : & compute.CacheKeyPolicy {
532
+ IncludeHost : ckpData ["include_host" ].(bool ),
533
+ IncludeProtocol : ckpData ["include_protocol" ].(bool ),
534
+ IncludeQueryString : ckpData ["include_query_string" ].(bool ),
535
+ QueryStringBlacklist : convertStringSet (ckpData ["query_string_blacklist" ].(* schema.Set )),
536
+ QueryStringWhitelist : convertStringSet (ckpData ["query_string_whitelist" ].(* schema.Set )),
537
+ ForceSendFields : []string {"IncludeProtocol" , "IncludeHost" , "IncludeQueryString" , "QueryStringWhitelist" , "QueryStringBlacklist" },
538
+ },
539
+ }
540
+ }
541
+
542
+ func flattenCdnPolicy (pol * compute.BackendServiceCdnPolicy ) []map [string ]interface {} {
543
+ result := []map [string ]interface {}{}
544
+ if pol == nil || pol .CacheKeyPolicy == nil {
545
+ return result
546
+ }
547
+
548
+ return append (result , map [string ]interface {}{
549
+ "cache_key_policy" : []map [string ]interface {}{
550
+ {
551
+ "include_host" : pol .CacheKeyPolicy .IncludeHost ,
552
+ "include_protocol" : pol .CacheKeyPolicy .IncludeProtocol ,
553
+ "include_query_string" : pol .CacheKeyPolicy .IncludeQueryString ,
554
+ "query_string_blacklist" : schema .NewSet (schema .HashString , convertStringArrToInterface (pol .CacheKeyPolicy .QueryStringBlacklist )),
555
+ "query_string_whitelist" : schema .NewSet (schema .HashString , convertStringArrToInterface (pol .CacheKeyPolicy .QueryStringWhitelist )),
556
+ },
557
+ },
558
+ })
559
+ }
0 commit comments