Skip to content

Commit

Permalink
CDP-1182 add proxy_cache_key option (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
freenoth authored Sep 23, 2024
1 parent ba77568 commit 548af0d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 8 deletions.
13 changes: 13 additions & 0 deletions docs/resources/cdn_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Optional:
- `image_stack` (Block List, Max: 1) Image stack option allows transforming JPG and PNG images (such as resizing or cropping) and automatically converting them to WebP or AVIF format. It is a paid option. (see [below for nested schema](#nestedblock--options--image_stack))
- `ip_address_acl` (Block List, Max: 1) IP access policy option allows to control access to the CDN Resource content for specific IP addresses. (see [below for nested schema](#nestedblock--options--ip_address_acl))
- `limit_bandwidth` (Block List, Max: 1) The option allows to control the download speed per connection. (see [below for nested schema](#nestedblock--options--limit_bandwidth))
- `proxy_cache_key` (Block List, Max: 1) The option allows to modify the cache key. If omitted, the default value is $request_uri. Warning: Enabling and changing this option can invalidate your current cache and affect the cache hit ratio. Furthermore, the "Purge by pattern" option will not work. (see [below for nested schema](#nestedblock--options--proxy_cache_key))
- `proxy_cache_methods_set` (Block List, Max: 1) Allows caching for GET, HEAD and POST requests. (see [below for nested schema](#nestedblock--options--proxy_cache_methods_set))
- `proxy_connect_timeout` (Block List, Max: 1) The time limit for establishing a connection with the origin. (see [below for nested schema](#nestedblock--options--proxy_connect_timeout))
- `proxy_read_timeout` (Block List, Max: 1) The time limit for receiving a partial response from the origin. If no response is received within this time, the connection will be closed. (see [below for nested schema](#nestedblock--options--proxy_read_timeout))
Expand Down Expand Up @@ -438,6 +439,18 @@ Optional:
- `speed` (Number) Maximum download speed per connection. Must be greater than 0.


<a id="nestedblock--options--proxy_cache_key"></a>
### Nested Schema for `options.proxy_cache_key`

Required:

- `value` (String) Key for caching. Should be a combination of the specified variables: $http_host, $request_uri, $scheme, $uri.

Optional:

- `enabled` (Boolean)


<a id="nestedblock--options--proxy_cache_methods_set"></a>
### Nested Schema for `options.proxy_cache_methods_set`

Expand Down
13 changes: 13 additions & 0 deletions docs/resources/cdn_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Optional:
- `image_stack` (Block List, Max: 1) Image stack option allows transforming JPG and PNG images (such as resizing or cropping) and automatically converting them to WebP or AVIF format. It is a paid option. (see [below for nested schema](#nestedblock--options--image_stack))
- `ip_address_acl` (Block List, Max: 1) IP access policy option allows to control access to the CDN Resource content for specific IP addresses. (see [below for nested schema](#nestedblock--options--ip_address_acl))
- `limit_bandwidth` (Block List, Max: 1) The option allows to control the download speed per connection. (see [below for nested schema](#nestedblock--options--limit_bandwidth))
- `proxy_cache_key` (Block List, Max: 1) The option allows to modify the cache key. If omitted, the default value is $request_uri. Warning: Enabling and changing this option can invalidate your current cache and affect the cache hit ratio. Furthermore, the "Purge by pattern" option will not work. (see [below for nested schema](#nestedblock--options--proxy_cache_key))
- `proxy_cache_methods_set` (Block List, Max: 1) Allows caching for GET, HEAD and POST requests. (see [below for nested schema](#nestedblock--options--proxy_cache_methods_set))
- `proxy_connect_timeout` (Block List, Max: 1) The time limit for establishing a connection with the origin. (see [below for nested schema](#nestedblock--options--proxy_connect_timeout))
- `proxy_read_timeout` (Block List, Max: 1) The time limit for receiving a partial response from the origin. If no response is received within this time, the connection will be closed. (see [below for nested schema](#nestedblock--options--proxy_read_timeout))
Expand Down Expand Up @@ -461,6 +462,18 @@ Optional:
- `speed` (Number) Maximum download speed per connection. Must be greater than 0.


<a id="nestedblock--options--proxy_cache_key"></a>
### Nested Schema for `options.proxy_cache_key`

Required:

- `value` (String) Key for caching. Should be a combination of the specified variables: $http_host, $request_uri, $scheme, $uri.

Optional:

- `enabled` (Boolean)


<a id="nestedblock--options--proxy_cache_methods_set"></a>
### Nested Schema for `options.proxy_cache_methods_set`

Expand Down
3 changes: 3 additions & 0 deletions examples/resources/gcore_cdn_resource/example_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ resource "gcore_cdn_resource" "cdn_example_com" {
speed = 100
buffer = 200
}
proxy_cache_key {
value = "$scheme$uri"
}
proxy_cache_methods_set {
value = false
}
Expand Down
3 changes: 3 additions & 0 deletions examples/resources/gcore_cdn_rule/example_2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ resource "gcore_cdn_rule" "cdn_example_com_rule_1" {
speed = 100
buffer = 200
}
proxy_cache_key {
value = "$scheme$request_uri"
}
proxy_cache_methods_set {
value = false
}
Expand Down
23 changes: 22 additions & 1 deletion gcore/resource_gcore_cdn_options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gcore

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"maps"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var (
Expand Down Expand Up @@ -521,6 +522,26 @@ var (
},
},
},
"proxy_cache_key": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "The option allows to modify the cache key. If omitted, the default value is $request_uri. Warning: Enabling and changing this option can invalidate your current cache and affect the cache hit ratio. Furthermore, the \"Purge by pattern\" option will not work.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"value": {
Type: schema.TypeString,
Required: true,
Description: "Key for caching. Should be a combination of the specified variables: $http_host, $request_uri, $scheme, $uri.",
},
},
},
},
"proxy_cache_methods_set": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down
10 changes: 10 additions & 0 deletions gcore/resource_gcore_cdn_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ func listToOptions(l []interface{}) *gcdn.Options {
opts.LimitBandwidth.Buffer = opt["buffer"].(int)
}
}
if opt, ok := getOptByName(fields, "proxy_cache_key"); ok {
opts.ProxyCacheKey = &gcdn.ProxyCacheKey{
Enabled: opt["enabled"].(bool),
Value: opt["value"].(string),
}
}
if opt, ok := getOptByName(fields, "proxy_cache_methods_set"); ok {
opts.ProxyCacheMethodsSet = &gcdn.ProxyCacheMethodsSet{
Enabled: opt["enabled"].(bool),
Expand Down Expand Up @@ -707,6 +713,10 @@ func optionsToList(options *gcdn.Options) []interface{} {
m := structToMap(options.LimitBandwidth)
result["limit_bandwidth"] = []interface{}{m}
}
if options.ProxyCacheKey != nil {
m := structToMap(options.ProxyCacheKey)
result["proxy_cache_key"] = []interface{}{m}
}
if options.ProxyCacheMethodsSet != nil {
m := structToMap(options.ProxyCacheMethodsSet)
result["proxy_cache_methods_set"] = []interface{}{m}
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.9
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.16
github.com/G-Core/gcorelabscdn-go v1.0.17
github.com/G-Core/gcorelabscloud-go v0.8.6
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ github.com/G-Core/gcore-dns-sdk-go v0.2.9 h1:LMMZIRX8y3aJJuAviNSpFmLbovZUw+6Om+8
github.com/G-Core/gcore-dns-sdk-go v0.2.9/go.mod h1:35t795gOfzfVanhzkFyUXEzaBuMXwETmJldPpP28MN4=
github.com/G-Core/gcore-storage-sdk-go v0.1.34 h1:0GPQfz1kA6mQi6fiisGsh0Um4H9PZeHWIPsc825cDrY=
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.14 h1:s34XWrMeuR/TvmnN0jrb6vsC9IzQFGFhb+qlxTbOfq8=
github.com/G-Core/gcorelabscdn-go v1.0.14/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.15 h1:KIsZk2gadIlX3kSQJNRHS+HMtabHsdw0f0ARJSYlcxI=
github.com/G-Core/gcorelabscdn-go v1.0.15/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.16 h1:Sxr/8krN/dMikoFd4lYQjJKGbK9LlsnKnkTpLKmSsCo=
github.com/G-Core/gcorelabscdn-go v1.0.16/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.17 h1:g5i53mzPpg513qcXzxuEdL1v/rK3yiAd8LOVjMh/noM=
github.com/G-Core/gcorelabscdn-go v1.0.17/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.8.0 h1:6w+Mikiz+GbHJs1PD+tPD1gIR88Xl3UPkJuvQVuG7bs=
github.com/G-Core/gcorelabscloud-go v0.8.0/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.8.4 h1:Yf0c0ZFOTxu0VjMgMVooHp2k2fYYKLLU5jqFRuEVEcg=
Expand Down

0 comments on commit 548af0d

Please sign in to comment.