Skip to content

Commit

Permalink
Merge pull request #1749 from cloudflare/fix-request-origin-test
Browse files Browse the repository at this point in the history
tests: fix ruleset request origin tests
  • Loading branch information
jacobbednarz authored Jul 4, 2022
2 parents b76342c + 80f328c commit b9dc7b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
26 changes: 14 additions & 12 deletions docs/resources/ruleset.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ resource "cloudflare_ruleset" "custom_fields_logging_example" {
}
}
# Custom cache keys + settings
resource "cloudflare_ruleset" "cache_settings_example" {
zone_id = "cb029e245cfdd66dc8d2e570d5dd3322"
name = "set cache settings"
Expand All @@ -277,16 +278,16 @@ resource "cloudflare_ruleset" "cache_settings_example" {
action = "set_cache_settings"
action_parameters {
edge_ttl {
mode = "override_origin"
mode = "override_origin"
default = 60
status_code_ttl {
status_code = 200
value = 50
value = 50
}
status_code_ttl {
status_code_range {
from = 201
to = 300
to = 300
}
value = 30
}
Expand All @@ -300,23 +301,23 @@ resource "cloudflare_ruleset" "cache_settings_example" {
respect_strong_etags = true
cache_key {
ignore_query_strings_order = false
cache_deception_armor = true
cache_deception_armor = true
custom_key {
query_string {
exclude = ["*"]
}
header {
include = ["habc", "hdef"]
include = ["habc", "hdef"]
check_presence = ["habc_t", "hdef_t"]
exclude_origin = true
}
cookie {
include = ["cabc", "cdef"]
include = ["cabc", "cdef"]
check_presence = ["cabc_t", "cdef_t"]
}
user {
device_type = true
geo = false
geo = false
}
host {
resolved = true
Expand All @@ -325,12 +326,13 @@ resource "cloudflare_ruleset" "cache_settings_example" {
}
origin_error_page_passthru = false
}
expression = "true"
expression = "true"
description = "set cache settings rule"
enabled = true
enabled = true
}
}
# Redirects based on a List resource
resource "cloudflare_ruleset" "redirect_from_list_example" {
account_id = "f037e56e89293a057740de681ac9abbe"
name = "redirects"
Expand All @@ -343,12 +345,12 @@ resource "cloudflare_ruleset" "redirect_from_list_example" {
action_parameters {
from_list {
name = "redirect_list"
key = "http.request.full_uri"
key = "http.request.full_uri"
}
}
expression = "http.request.full_uri in $redirect_list"
expression = "http.request.full_uri in $redirect_list"
description = "Apply redirects from redirect_list"
enabled = true
enabled = true
}
}
```
Expand Down
26 changes: 14 additions & 12 deletions examples/resources/cloudflare_ruleset/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ resource "cloudflare_ruleset" "custom_fields_logging_example" {
}
}

# Custom cache keys + settings
resource "cloudflare_ruleset" "cache_settings_example" {
zone_id = "cb029e245cfdd66dc8d2e570d5dd3322"
name = "set cache settings"
Expand All @@ -242,16 +243,16 @@ resource "cloudflare_ruleset" "cache_settings_example" {
action = "set_cache_settings"
action_parameters {
edge_ttl {
mode = "override_origin"
mode = "override_origin"
default = 60
status_code_ttl {
status_code = 200
value = 50
value = 50
}
status_code_ttl {
status_code_range {
from = 201
to = 300
to = 300
}
value = 30
}
Expand All @@ -265,23 +266,23 @@ resource "cloudflare_ruleset" "cache_settings_example" {
respect_strong_etags = true
cache_key {
ignore_query_strings_order = false
cache_deception_armor = true
cache_deception_armor = true
custom_key {
query_string {
exclude = ["*"]
}
header {
include = ["habc", "hdef"]
include = ["habc", "hdef"]
check_presence = ["habc_t", "hdef_t"]
exclude_origin = true
}
cookie {
include = ["cabc", "cdef"]
include = ["cabc", "cdef"]
check_presence = ["cabc_t", "cdef_t"]
}
user {
device_type = true
geo = false
geo = false
}
host {
resolved = true
Expand All @@ -290,12 +291,13 @@ resource "cloudflare_ruleset" "cache_settings_example" {
}
origin_error_page_passthru = false
}
expression = "true"
expression = "true"
description = "set cache settings rule"
enabled = true
enabled = true
}
}

# Redirects based on a List resource
resource "cloudflare_ruleset" "redirect_from_list_example" {
account_id = "f037e56e89293a057740de681ac9abbe"
name = "redirects"
Expand All @@ -308,11 +310,11 @@ resource "cloudflare_ruleset" "redirect_from_list_example" {
action_parameters {
from_list {
name = "redirect_list"
key = "http.request.full_uri"
key = "http.request.full_uri"
}
}
expression = "http.request.full_uri in $redirect_list"
expression = "http.request.full_uri in $redirect_list"
description = "Apply redirects from redirect_list"
enabled = true
enabled = true
}
}
8 changes: 4 additions & 4 deletions internal/provider/resource_cloudflare_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ func TestAccCloudflareRuleset_RequestOrigin(t *testing.T) {

resource.TestCheckResourceAttr(resourceName, "rules.#", "1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action", "route"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.host_header", "some.host"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.host_header", rnd+".terraform.cfapi.net"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin.#", "1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin.0.host", "some.host"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin.0.host", rnd+".terraform.cfapi.net"),
resource.TestCheckResourceAttr(resourceName, "rules.0.action_parameters.0.origin.0.port", "80"),
resource.TestCheckResourceAttr(resourceName, "rules.0.expression", "(http.request.uri.path matches \"^/api/\")"),
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "example http request origin"),
Expand Down Expand Up @@ -2352,9 +2352,9 @@ func testAccCheckCloudflareRulesetOrigin(rnd, name, zoneID, zoneName string) str
rules {
action = "route"
action_parameters {
host_header = "some.host"
host_header = "%[1]s.terraform.cfapi.net"
origin {
host = "some.host"
host = "%[1]s.terraform.cfapi.net"
port = 80
}
}
Expand Down

0 comments on commit b9dc7b5

Please sign in to comment.