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

Commit 51e8387

Browse files
vvelikodnyVitaly Velikodny
andauthored
fix override origin protocol for rule create/update (#79)
Co-authored-by: Vitaly Velikodny <[email protected]>
1 parent 638496c commit 51e8387

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

gcore/resource_gcore_cdn_rule.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"strconv"
88

9+
"github.com/AlekSi/pointer"
910
"github.com/G-Core/gcorelabscdn-go/rules"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -36,10 +37,9 @@ func resourceCDNRule() *schema.Resource {
3637
Required: true,
3738
Description: "Type of rule. The rule is applied if the requested URI matches the rule pattern. It has two possible values: Type 0 — RegEx. Must start with '^/' or '/'. Type 1 — RegEx. Legacy type. Note that for this rule type we automatically add / to each rule pattern before your regular expression. Please use Type 0.",
3839
},
39-
"origin_protocol": {
40+
"override_origin_protocol": {
4041
Type: schema.TypeString,
4142
Optional: true,
42-
Computed: true,
4343
Description: "This option defines the protocol that will be used by CDN servers to request content from an origin source. If not specified, we will use HTTP to connect to an origin server. Possible values are: HTTPS, HTTP, MATCH.",
4444
},
4545
"options": optionsSchema,
@@ -61,7 +61,10 @@ func resourceCDNRuleCreate(ctx context.Context, d *schema.ResourceData, m interf
6161
req.Name = d.Get("name").(string)
6262
req.Rule = d.Get("rule").(string)
6363
req.RuleType = d.Get("rule_type").(int)
64-
req.OverrideOriginProtocol = d.Get("origin_protocol").(string)
64+
65+
if d.Get("override_origin_protocol") != nil && d.Get("override_origin_protocol") != "" {
66+
req.OverrideOriginProtocol = pointer.ToString(d.Get("override_origin_protocol").(string))
67+
}
6568

6669
resourceID := d.Get("resource_id").(int)
6770

@@ -100,7 +103,7 @@ func resourceCDNRuleRead(ctx context.Context, d *schema.ResourceData, m interfac
100103
d.Set("name", result.Name)
101104
d.Set("rule", result.Pattern)
102105
d.Set("rule_type", result.Type)
103-
d.Set("origin_protocol", result.OriginProtocol)
106+
d.Set("override_origin_protocol", result.OverrideOriginProtocol)
104107
if err := d.Set("options", optionsToList(result.Options)); err != nil {
105108
return diag.FromErr(err)
106109
}
@@ -124,7 +127,10 @@ func resourceCDNRuleUpdate(ctx context.Context, d *schema.ResourceData, m interf
124127
req.Name = d.Get("name").(string)
125128
req.Rule = d.Get("rule").(string)
126129
req.RuleType = d.Get("rule_type").(int)
127-
req.OverrideOriginProtocol = d.Get("origin_protocol").(string)
130+
131+
if d.Get("override_origin_protocol") != nil && d.Get("override_origin_protocol") != "" {
132+
req.OverrideOriginProtocol = pointer.ToString(d.Get("override_origin_protocol").(string))
133+
}
128134

129135
req.Options = listToOptions(d.Get("options").([]interface{}))
130136

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/terraform-providers/terraform-provider-gcorelabs
33
go 1.16
44

55
require (
6+
github.com/AlekSi/pointer v1.2.0
67
github.com/G-Core/g-dns-sdk-go v0.1.2
78
github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9
8-
github.com/G-Core/gcorelabscdn-go v0.1.9
9+
github.com/G-Core/gcorelabscdn-go v0.1.12
910
github.com/G-Core/gcorelabscloud-go v0.4.42
1011
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1112
github.com/hashicorp/terraform-exec v0.15.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
3232
cloud.google.com/go/storage v1.10.0 h1:STgFzyU5/8miMl0//zKh2aQeTyeaUH3WN9bSUiJ09bA=
3333
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3434
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
35+
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
36+
github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0=
3537
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
3638
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
3739
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
@@ -47,6 +49,12 @@ github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9 h1:6uyKbknI8Q2pIJApPBf6JA0CN5O
4749
github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9/go.mod h1:BZef79y4G28n8ic3x6iQWbW+mtpHPSUyJRfIRSkeAJw=
4850
github.com/G-Core/gcorelabscdn-go v0.1.9 h1:ysx/MPSVlfsPvWMorxVxZW7Ow7uM6WNkA3voHw5Sd54=
4951
github.com/G-Core/gcorelabscdn-go v0.1.9/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
52+
github.com/G-Core/gcorelabscdn-go v0.1.10 h1:FEl6mQK++P8fr17hmVg0fSMOfR67f9g/gP4ptxeBzZY=
53+
github.com/G-Core/gcorelabscdn-go v0.1.10/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
54+
github.com/G-Core/gcorelabscdn-go v0.1.11 h1:xta0D7QYBvo9PzZiHbn0n33rxIghs56UkWByi+Rf/3M=
55+
github.com/G-Core/gcorelabscdn-go v0.1.11/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
56+
github.com/G-Core/gcorelabscdn-go v0.1.12 h1:+iDaJfhbZAX/OnveTqtFlcE3gbt5CftgDl8sxjxxh2E=
57+
github.com/G-Core/gcorelabscdn-go v0.1.12/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
5058
github.com/G-Core/gcorelabscloud-go v0.4.42 h1:LBH4GnH82eQ5L/Lfnzm8KJovbIHPzt2KMitVN1V9kDQ=
5159
github.com/G-Core/gcorelabscloud-go v0.4.42/go.mod h1:Z1MF80mWagEUrxygtYkvW/MJEYNmIUPsIEYBB3cKjOM=
5260
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=

0 commit comments

Comments
 (0)