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

resource/rulesets: add cache_reserve terraform support and fix typo #3923

Merged

Conversation

anthocf
Copy link
Contributor

@anthocf anthocf commented Sep 9, 2024

Cache Reserve support is missing from the ruleset terraform provider. Per #3244, Cache Reserve is already supported in cloudflare-go.

Separately, there is a small typo in the example I added in a previous commit. I was able to verify that the terraform provider created a resource in my personal account. Here is the terraform config:

terraform {
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
    }
  }
}

variable "cloudflare_api_token" {
  sensitive = true
}

provider "cloudflare" {
  api_token = var.cloudflare_api_token
}

resource "cloudflare_ruleset" "contains_ruleset" {
    zone_id     = "<snip>"
    name        = "My Custom Ruleset"
    description = "set cache settings for the request"
    kind        = "zone"
    phase       = "http_request_cache_settings"
    rules {
        action      = "set_cache_settings"
        description = "example"
        enabled     = true
        expression  = "(http.host eq \"example.com\" and starts_with(http.request.uri.path, \"/example\"))"
        action_parameters {
            cache = true
            edge_ttl {
                mode    = "override_origin"
                default = 7200
            }
            cache_key {
                custom_key {
                    header {
                        check_presence = ["x-forwarded-for"]
                        include        = ["x-test", "x-test2"]
                        exclude_origin = false
                        contains       = {
                            "accept"         = ["image/web", "image/png"]
                            "accept-encoding" = ["br", "zstd"]
                            "some-header"    = ["some-value", "some-other-value"]
                        }
                    }
                }
            }
            cache_reserve {
              eligible = true
              minimum_file_size = 100000
            }
        }
    }
}

In the CF dashboard, I opened the network trace and found the corresponding result here:

Screenshot 2024-09-09 at 12 31 48 PM

resolves #3244

Copy link
Contributor

github-actions bot commented Sep 9, 2024

changelog detected ✅

@anthocf anthocf force-pushed the anthocf/add-cache-reserve-to-ruleset branch 2 times, most recently from 1785cd1 to 7525021 Compare September 9, 2024 17:56
@anthocf
Copy link
Contributor Author

anthocf commented Sep 9, 2024

If everything looks okay, please hold off on merging. I would like to get sign off on the wording that will go into public docs.

@anthocf anthocf force-pushed the anthocf/add-cache-reserve-to-ruleset branch from 7525021 to ab7d585 Compare September 10, 2024 21:15
@anthocf
Copy link
Contributor Author

anthocf commented Sep 10, 2024

If everything looks okay, please hold off on merging. I would like to get sign off on the wording that will go into public docs.

@jacobbednarz No concerns on merging now. The doc changes look good now.

@jacobbednarz
Copy link
Member

acceptance tests all passing

TF_ACC=1 go test ./internal/framework/service/rulesets -v -run "^TestAccCloudflareRuleset_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareRuleset_WAFBasic
--- PASS: TestAccCloudflareRuleset_WAFBasic (4.91s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRuleset
--- PASS: TestAccCloudflareRuleset_WAFManagedRuleset (3.21s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetWithoutDescription
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetWithoutDescription (3.15s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetOWASP
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetOWASP (6.09s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetOWASPBlockXSSWithAnomalyOver60
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetOWASPBlockXSSWithAnomalyOver60 (5.90s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetOWASPOnlyPL1
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetOWASPOnlyPL1 (3.91s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetDeployMultiple
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetDeployMultiple (4.28s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetDeployMultipleWithSkip
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetDeployMultipleWithSkip (4.52s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetDeployMultipleWithTopSkipAndLastSkip
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetDeployMultipleWithTopSkipAndLastSkip (5.63s)
=== RUN   TestAccCloudflareRuleset_SkipPhaseAndProducts
--- PASS: TestAccCloudflareRuleset_SkipPhaseAndProducts (4.92s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetWithCategoryAndRuleBasedOverrides
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetWithCategoryAndRuleBasedOverrides (4.36s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetWithIDBasedOverrides
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetWithIDBasedOverrides (3.88s)
=== RUN   TestAccCloudflareRuleset_MagicTransitUpdateWithHigherPriority
    acctest.go:112: Skipping acceptance test for default account (f037e56e89293a057740de681ac9abbe). Default account is not configured for Magic Transit.
--- SKIP: TestAccCloudflareRuleset_MagicTransitUpdateWithHigherPriority (0.00s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetWithPayloadLogging
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetWithPayloadLogging (3.26s)
=== RUN   TestAccCloudflareRuleset_RateLimit
--- PASS: TestAccCloudflareRuleset_RateLimit (3.78s)
=== RUN   TestAccCloudflareRuleset_RateLimitScorePerPeriod
--- PASS: TestAccCloudflareRuleset_RateLimitScorePerPeriod (4.56s)
=== RUN   TestAccCloudflareRuleset_RateLimitMitigationTimeoutOfZero
=== PAUSE TestAccCloudflareRuleset_RateLimitMitigationTimeoutOfZero
=== RUN   TestAccCloudflareRuleset_PreserveRuleRefs
--- PASS: TestAccCloudflareRuleset_PreserveRuleRefs (33.79s)
=== RUN   TestAccCloudflareRuleset_CustomErrors
--- PASS: TestAccCloudflareRuleset_CustomErrors (4.52s)
=== RUN   TestAccCloudflareRuleset_RequestOrigin
--- PASS: TestAccCloudflareRuleset_RequestOrigin (4.37s)
=== RUN   TestAccCloudflareRuleset_RequestOriginPortWithoutHost
--- PASS: TestAccCloudflareRuleset_RequestOriginPortWithoutHost (3.72s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleURIPath
--- PASS: TestAccCloudflareRuleset_TransformationRuleURIPath (5.05s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleURIQuery
--- PASS: TestAccCloudflareRuleset_TransformationRuleURIQuery (2.98s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleURIPathAndQueryCombination
--- PASS: TestAccCloudflareRuleset_TransformationRuleURIPathAndQueryCombination (4.16s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleRequestHeaders
--- PASS: TestAccCloudflareRuleset_TransformationRuleRequestHeaders (3.05s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleResponseHeaders
--- PASS: TestAccCloudflareRuleset_TransformationRuleResponseHeaders (3.69s)
=== RUN   TestAccCloudflareRuleset_ResponseCompression
--- PASS: TestAccCloudflareRuleset_ResponseCompression (2.64s)
=== RUN   TestAccCloudflareRuleset_ActionParametersMultipleSkips
--- PASS: TestAccCloudflareRuleset_ActionParametersMultipleSkips (7.43s)
=== RUN   TestAccCloudflareRuleset_ActionParametersOverridesAction
--- PASS: TestAccCloudflareRuleset_ActionParametersOverridesAction (3.95s)
=== RUN   TestAccCloudflareRuleset_ActionParametersHTTPDDoSOverride
--- PASS: TestAccCloudflareRuleset_ActionParametersHTTPDDoSOverride (3.92s)
=== RUN   TestAccCloudflareRuleset_ActionParametersOverrideAllRulesetRules
--- PASS: TestAccCloudflareRuleset_ActionParametersOverrideAllRulesetRules (4.58s)
=== RUN   TestAccCloudflareRuleset_AccountLevelCustomWAFRule
--- PASS: TestAccCloudflareRuleset_AccountLevelCustomWAFRule (4.67s)
=== RUN   TestAccCloudflareRuleset_ExposedCredentialCheck
--- PASS: TestAccCloudflareRuleset_ExposedCredentialCheck (3.50s)
=== RUN   TestAccCloudflareRuleset_Logging
--- PASS: TestAccCloudflareRuleset_Logging (4.05s)
=== RUN   TestAccCloudflareRuleset_ConditionallySetActionParameterVersion
--- PASS: TestAccCloudflareRuleset_ConditionallySetActionParameterVersion (8.07s)
=== RUN   TestAccCloudflareRuleset_WAFManagedRulesetWithActionManagedChallenge
--- PASS: TestAccCloudflareRuleset_WAFManagedRulesetWithActionManagedChallenge (7.57s)
=== RUN   TestAccCloudflareRuleset_LogCustomField
--- PASS: TestAccCloudflareRuleset_LogCustomField (2.62s)
=== RUN   TestAccCloudflareRuleset_ActionParametersOverridesThrashingStatus
--- PASS: TestAccCloudflareRuleset_ActionParametersOverridesThrashingStatus (19.12s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsAllEnabled
--- PASS: TestAccCloudflareRuleset_CacheSettingsAllEnabled (4.49s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsOptionalsEmpty
--- PASS: TestAccCloudflareRuleset_CacheSettingsOptionalsEmpty (6.98s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsCacheReserveFalse
--- PASS: TestAccCloudflareRuleset_CacheSettingsCacheReserveFalse (4.55s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsOnlyExludeOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsOnlyExludeOrigin (4.47s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsEdgeTTLRespectOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsEdgeTTLRespectOrigin (10.60s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsNoCacheForStatus
--- PASS: TestAccCloudflareRuleset_CacheSettingsNoCacheForStatus (3.62s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsStatusRangeGreaterThan
--- PASS: TestAccCloudflareRuleset_CacheSettingsStatusRangeGreaterThan (3.78s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsStatusRangeLessThan
--- PASS: TestAccCloudflareRuleset_CacheSettingsStatusRangeLessThan (4.29s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsFalse
--- PASS: TestAccCloudflareRuleset_CacheSettingsFalse (2.97s)
=== RUN   TestAccCloudflareRuleset_Config
--- PASS: TestAccCloudflareRuleset_Config (4.21s)
=== RUN   TestAccCloudflareRuleset_Redirect
--- PASS: TestAccCloudflareRuleset_Redirect (5.98s)
=== RUN   TestAccCloudflareRuleset_DynamicRedirect
--- PASS: TestAccCloudflareRuleset_DynamicRedirect (3.92s)
=== RUN   TestAccCloudflareRuleset_DynamicRedirectWithoutPreservingQueryString
--- PASS: TestAccCloudflareRuleset_DynamicRedirectWithoutPreservingQueryString (5.74s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleURIStripOffQueryString
--- PASS: TestAccCloudflareRuleset_TransformationRuleURIStripOffQueryString (3.88s)
=== RUN   TestAccCloudflareRuleset_TransformationRuleURIStripOffPath
--- PASS: TestAccCloudflareRuleset_TransformationRuleURIStripOffPath (4.32s)
=== RUN   TestAccCloudflareRuleset_ConfigSingleFalseyValue
--- PASS: TestAccCloudflareRuleset_ConfigSingleFalseyValue (4.63s)
=== RUN   TestAccCloudflareRuleset_ConfigConflictingCacheByDevice
--- PASS: TestAccCloudflareRuleset_ConfigConflictingCacheByDevice (0.25s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsMissingEdgeTTLWithOverrideOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsMissingEdgeTTLWithOverrideOrigin (0.15s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsMissingBrowserTTLWithOverrideOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsMissingBrowserTTLWithOverrideOrigin (0.16s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsInvalidEdgeTTLWithOverrideOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsInvalidEdgeTTLWithOverrideOrigin (0.17s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsEdgeTTLWithBypassByDefault
--- PASS: TestAccCloudflareRuleset_CacheSettingsEdgeTTLWithBypassByDefault (4.22s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsInvalidEdgeTTLWithBypassByDefault
--- PASS: TestAccCloudflareRuleset_CacheSettingsInvalidEdgeTTLWithBypassByDefault (0.23s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsBrowserTTLWithBypass
--- PASS: TestAccCloudflareRuleset_CacheSettingsBrowserTTLWithBypass (4.66s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsInvalidBrowserTTLWithBypass
--- PASS: TestAccCloudflareRuleset_CacheSettingsInvalidBrowserTTLWithBypass (0.23s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsInvalidBrowserTTLWithOverrideOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsInvalidBrowserTTLWithOverrideOrigin (0.16s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsDefinedQueryStringExcludeKeys
--- PASS: TestAccCloudflareRuleset_CacheSettingsDefinedQueryStringExcludeKeys (3.24s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsDefinedQueryStringIncludeKeys
--- PASS: TestAccCloudflareRuleset_CacheSettingsDefinedQueryStringIncludeKeys (3.83s)
=== RUN   TestAccCloudflareRuleset_CacheSettingsHandleDefaultHeaderExcludeOrigin
--- PASS: TestAccCloudflareRuleset_CacheSettingsHandleDefaultHeaderExcludeOrigin (7.63s)
=== RUN   TestAccCloudflareRuleset_ImportHandlesMissingValues
--- PASS: TestAccCloudflareRuleset_ImportHandlesMissingValues (0.29s)
=== CONT  TestAccCloudflareRuleset_RateLimitMitigationTimeoutOfZero
--- PASS: TestAccCloudflareRuleset_RateLimitMitigationTimeoutOfZero (3.60s)
PASS
PASS	github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/rulesets	311.788s
PASS

@jacobbednarz jacobbednarz merged commit 2aa80c2 into cloudflare:master Sep 17, 2024
9 checks passed
@github-actions github-actions bot added this to the v4.42.0 milestone Sep 17, 2024
Copy link
Contributor

This functionality has been released in v4.42.0 of the Terraform Cloudflare Provider.

Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloudflare_ruleset resource does not support Cache Reserve Eligibility parameter for Cache Rules
2 participants