Skip to content

Commit

Permalink
CDI-466: add the ability to enable/disable Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-lukyanchyk committed Dec 22, 2023
1 parent 1aec39b commit 46f2dfa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/resources/cdn_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ resource "gcore_cdn_resource" "cdn_example_com" {

### Optional

- `active` (Boolean) The setting allows to enable or disable a Rule. If not specified, it will be enabled.
- `options` (Block List, Max: 1) Each option in CDN resource settings. Each option added to CDN resource settings should have the following mandatory request fields: enabled, value. (see [below for nested schema](#nestedblock--options))
- `origin_group` (Number) ID of the Origins Group. Use one of your Origins Group or create a new one. You can use either 'origin' parameter or 'originGroup' in the resource definition.
- `origin_protocol` (String) This option defines the protocol that will be used by CDN servers to request content from an origin source. If not specified, it will be inherit from resource. Possible values are: HTTPS, HTTP, MATCH.
- `origin_protocol` (String) This option defines the protocol that will be used by CDN servers to request content from an origin source. If not specified, it will be inherited from resource. Possible values are: HTTPS, HTTP, MATCH.
- `weight` (Number) Rule weight that determines rule execution order: from the smallest (0) to the highest.

### Read-Only
Expand Down
9 changes: 9 additions & 0 deletions gcore/resource_gcore_cdn_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func resourceCDNRule() *schema.Resource {
Required: true,
Description: "Rule name",
},
"active": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "The setting allows to enable or disable a Rule. If not specified, it will be enabled.",
},
"rule": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -97,6 +103,7 @@ func resourceCDNRuleCreate(ctx context.Context, d *schema.ResourceData, m interf

var req rules.CreateRequest
req.Name = d.Get("name").(string)
req.Active = d.Get("active").(bool)
req.Rule = d.Get("rule").(string)
req.RuleType = d.Get("rule_type").(int)

Expand Down Expand Up @@ -147,6 +154,7 @@ func resourceCDNRuleRead(ctx context.Context, d *schema.ResourceData, m interfac
}

d.Set("name", result.Name)
d.Set("active", result.Active)
d.Set("rule", result.Pattern)
d.Set("rule_type", result.Type)
d.Set("origin_group", result.OriginGroup)
Expand All @@ -173,6 +181,7 @@ func resourceCDNRuleUpdate(ctx context.Context, d *schema.ResourceData, m interf

var req rules.UpdateRequest
req.Name = d.Get("name").(string)
req.Active = d.Get("active").(bool)
req.Rule = d.Get("rule").(string)
req.RuleType = d.Get("rule_type").(int)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlekSi/pointer v1.2.0
github.com/G-Core/gcore-dns-sdk-go v0.2.7-0.20230801110428-99ef24b50d4d
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.1
github.com/G-Core/gcorelabscdn-go v1.0.2
github.com/G-Core/gcorelabscloud-go v0.6.15
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/G-Core/gcorelabscdn-go v1.0.0 h1:aPjwy6UWAmi8p+Vi8OEfmDM4bOq5r+rkOi9S
github.com/G-Core/gcorelabscdn-go v1.0.0/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.1 h1:BsGnLIiH7nhvSwDLgnsaXIPIJZG6hpTsqeYPr+W6/qM=
github.com/G-Core/gcorelabscdn-go v1.0.1/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.2 h1:PLUUGal7GftuQxP+VyEwMYZ47e4S/jvYZKRnDezcpMY=
github.com/G-Core/gcorelabscdn-go v1.0.2/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.6.2 h1:oCo3yurVnGKZLkRuQ7GVQK1LuLFEjq3mFWiX/PUI69M=
github.com/G-Core/gcorelabscloud-go v0.6.2/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.6.15 h1:lyzUPvQy7/KM0n4ErKpM4BpJA0iKrv82pHAimWfxNwA=
Expand Down

0 comments on commit 46f2dfa

Please sign in to comment.