Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 4c5e329

Browse files
vvelikodnyVitaly Velikodny
andauthored
add static_request_headers & static_headers options (#85)
Co-authored-by: Vitaly Velikodny <[email protected]>
1 parent 7173748 commit 4c5e329

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

gcore/resource_gcore_cdn_resource.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,46 @@ var (
293293
},
294294
},
295295
},
296+
"static_request_headers": {
297+
Type: schema.TypeList,
298+
MaxItems: 1,
299+
Optional: true,
300+
Description: "",
301+
Elem: &schema.Resource{
302+
Schema: map[string]*schema.Schema{
303+
"enabled": {
304+
Type: schema.TypeBool,
305+
Optional: true,
306+
Default: true,
307+
},
308+
"value": {
309+
Type: schema.TypeMap,
310+
Elem: &schema.Schema{Type: schema.TypeString},
311+
Required: true,
312+
},
313+
},
314+
},
315+
},
316+
"static_headers": {
317+
Type: schema.TypeList,
318+
MaxItems: 1,
319+
Optional: true,
320+
Description: "",
321+
Elem: &schema.Resource{
322+
Schema: map[string]*schema.Schema{
323+
"enabled": {
324+
Type: schema.TypeBool,
325+
Optional: true,
326+
Default: true,
327+
},
328+
"value": {
329+
Type: schema.TypeMap,
330+
Elem: &schema.Schema{Type: schema.TypeString},
331+
Required: true,
332+
},
333+
},
334+
},
335+
},
296336
},
297337
},
298338
}
@@ -361,7 +401,6 @@ func resourceCDNResource() *schema.Resource {
361401
RequiredWith: []string{"ssl_enabled"},
362402
Description: "Specify the SSL Certificate ID which should be used for the CDN Resource.",
363403
},
364-
"options": optionsSchema,
365404
"active": {
366405
Type: schema.TypeBool,
367406
Optional: true,
@@ -373,6 +412,7 @@ func resourceCDNResource() *schema.Resource {
373412
Computed: true,
374413
Description: "Status of a CDN resource content availability. Possible values are: Active, Suspended, Processed.",
375414
},
415+
"options": optionsSchema,
376416
},
377417
CreateContext: resourceCDNResourceCreate,
378418
ReadContext: resourceCDNResourceRead,
@@ -637,6 +677,32 @@ func listToOptions(l []interface{}) *gcdn.Options {
637677
opts.QueryParamsBlacklist.Value = append(opts.QueryParamsBlacklist.Value, v.(string))
638678
}
639679
}
680+
if opt, ok := getOptByName(fields, "static_request_headers"); ok {
681+
enabled := true
682+
if _, ok := opt["enabled"]; ok {
683+
enabled = opt["enabled"].(bool)
684+
}
685+
opts.StaticRequestHeaders = &gcdn.StaticRequestHeaders{
686+
Enabled: enabled,
687+
Value: map[string]string{},
688+
}
689+
for k, v := range opt["value"].(map[string]interface{}) {
690+
opts.StaticRequestHeaders.Value[k] = v.(string)
691+
}
692+
}
693+
if opt, ok := getOptByName(fields, "static_headers"); ok {
694+
enabled := true
695+
if _, ok := opt["enabled"]; ok {
696+
enabled = opt["enabled"].(bool)
697+
}
698+
opts.StaticHeaders = &gcdn.StaticHeaders{
699+
Enabled: enabled,
700+
Value: map[string]string{},
701+
}
702+
for k, v := range opt["value"].(map[string]interface{}) {
703+
opts.StaticHeaders.Value[k] = v.(string)
704+
}
705+
}
640706
return &opts
641707
}
642708

@@ -712,6 +778,14 @@ func optionsToList(options *gcdn.Options) []interface{} {
712778
m := structToMap(options.QueryParamsBlacklist)
713779
result["query_params_blacklist"] = []interface{}{m}
714780
}
781+
if options.StaticRequestHeaders != nil {
782+
m := structToMap(options.StaticRequestHeaders)
783+
result["static_request_headers"] = []interface{}{m}
784+
}
785+
if options.StaticHeaders != nil {
786+
m := structToMap(options.StaticHeaders)
787+
result["static_headers"] = []interface{}{m}
788+
}
715789
return []interface{}{result}
716790
}
717791

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AlekSi/pointer v1.2.0
77
github.com/G-Core/g-dns-sdk-go v0.1.2
88
github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9
9-
github.com/G-Core/gcorelabscdn-go v0.1.16
9+
github.com/G-Core/gcorelabscdn-go v0.1.18
1010
github.com/G-Core/gcorelabscloud-go v0.4.43
1111
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ github.com/G-Core/gcorelabscdn-go v0.1.15 h1:3T8xbxKr3773RR7oE06W9T3BjEOw5Zekfls
5353
github.com/G-Core/gcorelabscdn-go v0.1.15/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
5454
github.com/G-Core/gcorelabscdn-go v0.1.16 h1:AwO7ixX9bEEFespAR4ZcCOSDBgylGRqhglzoYeuRJ6g=
5555
github.com/G-Core/gcorelabscdn-go v0.1.16/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
56+
github.com/G-Core/gcorelabscdn-go v0.1.17 h1:N/zud06Ixnr2a70dfAw7ixjPFnasQ0UlsyYMTdGmICg=
57+
github.com/G-Core/gcorelabscdn-go v0.1.17/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
58+
github.com/G-Core/gcorelabscdn-go v0.1.18 h1:ISDvMA0EFw6PJnQKTnJ5lAJ5mm1MVRbjMZoZkClA42I=
59+
github.com/G-Core/gcorelabscdn-go v0.1.18/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
5660
github.com/G-Core/gcorelabscloud-go v0.4.43 h1:e4D1iJSoPKye3YyOXS7vER2ZYitu51cpAK68n1c3sGM=
5761
github.com/G-Core/gcorelabscloud-go v0.4.43/go.mod h1:Z1MF80mWagEUrxygtYkvW/MJEYNmIUPsIEYBB3cKjOM=
5862
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=

0 commit comments

Comments
 (0)