Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDI-466: add the ability to enable/disable Rules #56

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,6 +102,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 @@ -146,6 +153,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 @@ -172,6 +180,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.3
github.com/G-Core/gcorelabscloud-go v0.6.23
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 @@ -7,6 +7,8 @@ github.com/G-Core/gcore-storage-sdk-go v0.1.34 h1:0GPQfz1kA6mQi6fiisGsh0Um4H9PZe
github.com/G-Core/gcore-storage-sdk-go v0.1.34/go.mod h1:BUAEZZZJJt/+luRFunqziv3+JnbVMLbQXDWz9kV8Te8=
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.3 h1:fBIhDNLqfKVQV7ycqhgNeyg4Pzn5LIl5yah556lAlj4=
github.com/G-Core/gcorelabscdn-go v1.0.3/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.6.23 h1:2aN246lj7o4pS3P0D56v9ooecw2Apvikicli6RxGiUk=
github.com/G-Core/gcorelabscloud-go v0.6.23/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
Expand Down