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

Commit 0fc1e4c

Browse files
vvelikodnyVitaly Velikodny
andauthored
Add new res options (#68)
* add CDN resource description * add 'redirect_http_to_https' resource option Co-authored-by: Vitaly Velikodny <[email protected]>
1 parent deee04f commit 0fc1e4c

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

gcore/resource_gcore_cdn_resource.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func resourceCDNResource() *schema.Resource {
2121
Required: true,
2222
Description: "A CNAME that will be used to deliver content though a CDN",
2323
},
24+
"description": {
25+
Type: schema.TypeString,
26+
Optional: true,
27+
Description: "Custom client description of the resource.",
28+
},
2429
"origin_group": {
2530
Type: schema.TypeInt,
2631
Optional: true,
@@ -121,6 +126,24 @@ func resourceCDNResource() *schema.Resource {
121126
},
122127
},
123128
},
129+
"redirect_http_to_https": {
130+
Type: schema.TypeList,
131+
MaxItems: 1,
132+
Optional: true,
133+
Description: "Sets redirect from HTTP protocol to HTTPS for all resource requests.",
134+
Elem: &schema.Resource{
135+
Schema: map[string]*schema.Schema{
136+
"enabled": {
137+
Type: schema.TypeBool,
138+
Required: true,
139+
},
140+
"value": {
141+
Type: schema.TypeBool,
142+
Required: true,
143+
},
144+
},
145+
},
146+
},
124147
},
125148
},
126149
},
@@ -151,6 +174,7 @@ func resourceCDNResourceCreate(ctx context.Context, d *schema.ResourceData, m in
151174

152175
var req resources.CreateRequest
153176
req.Cname = d.Get("cname").(string)
177+
req.Description = d.Get("description").(string)
154178
req.Origin = d.Get("origin").(string)
155179
req.OriginGroup = d.Get("origin_group").(int)
156180

@@ -187,6 +211,7 @@ func resourceCDNResourceRead(ctx context.Context, d *schema.ResourceData, m inte
187211
}
188212

189213
d.Set("cname", result.Cname)
214+
d.Set("description", result.Description)
190215
d.Set("origin_group", result.OriginGroup)
191216
d.Set("origin_protocol", result.OriginProtocol)
192217
d.Set("secondary_hostnames", result.SecondaryHostnames)
@@ -215,6 +240,7 @@ func resourceCDNResourceUpdate(ctx context.Context, d *schema.ResourceData, m in
215240

216241
var req resources.UpdateRequest
217242
req.Active = d.Get("active").(bool)
243+
req.Description = d.Get("description").(string)
218244
req.SSlEnabled = d.Get("ssl_enabled").(bool)
219245
req.SSLData = d.Get("ssl_data").(int)
220246
req.OriginGroup = d.Get("origin_group").(int)
@@ -283,7 +309,12 @@ func listToOptions(l []interface{}) *gcdn.Options {
283309
Value: opt["value"].(string),
284310
}
285311
}
286-
312+
if opt, ok := getOptByName(fields, "redirect_http_to_https"); ok {
313+
opts.RedirectHttpToHttps = &gcdn.RedirectHttpToHttps{
314+
Enabled: opt["enabled"].(bool),
315+
Value: opt["value"].(bool),
316+
}
317+
}
287318
return &opts
288319
}
289320

@@ -319,6 +350,10 @@ func optionsToList(options *gcdn.Options) []interface{} {
319350
m := structToMap(options.HostHeader)
320351
result["host_header"] = []interface{}{m}
321352
}
353+
if options.RedirectHttpToHttps != nil {
354+
m := structToMap(options.RedirectHttpToHttps)
355+
result["redirect_http_to_https"] = []interface{}{m}
356+
}
322357
return []interface{}{result}
323358
}
324359

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.16
55
require (
66
github.com/G-Core/g-dns-sdk-go v0.1.2
77
github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9
8-
github.com/G-Core/gcorelabscdn-go v0.1.2
8+
github.com/G-Core/gcorelabscdn-go v0.1.4
99
github.com/G-Core/gcorelabscloud-go v0.4.42
1010
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1111
github.com/hashicorp/terraform-exec v0.15.0 // indirect

0 commit comments

Comments
 (0)