cloudflare / terraform-provider-cloudflare

Cloudflare Terraform Provider
https://registry.terraform.io/providers/cloudflare/cloudflare
Mozilla Public License 2.0
755 stars 579 forks source link

Can't set default ttl using a variable #3736

Open sanketwadekar3 opened 3 weeks ago

sanketwadekar3 commented 3 weeks ago

Confirmation

Terraform and Cloudflare provider version

Terraform v1.4.2 on darwin_arm64 Cloudflare provider version 4.40.0

Affected resource(s)

cloudflare_ruleset

Terraform configuration files

resource "cloudflare_ruleset" "cache_example" {

  zone_id     = var.cloudflare_zone_id
  name        = "cache example"
  description = "Set cache settings for incoming requests"
  kind        = "zone"
  phase       = "http_request_cache_settings"

  rules {
    action = "set_cache_settings"
    action_parameters {
      edge_ttl {
        mode    = "override_origin"
        default = var.edge_ttl
      }
      browser_ttl {
        mode    = "override_origin"
        default = var.browser_ttl
      }
    }
    expression  = "(http.host eq \"example.host.com\")"
    description = "Set cache settings"
    enabled     = true
  }
}

variable "edge_ttl" {
  type        = number
  description = "cloudflare edge ttl"
  default     = 600
}

variable "browser_ttl" {
  type        = number
  description = "cloudflare browser ttl"
  default     = 300
}

Link to debug output

https://gist.github.com/sanketwadekar3/ab03cd9436085de788e75d65c4d6af6c

Panic output

No response

Expected output

The configuration is expected to be valid when we pass the ttl value from a variable.

Actual output

Error: invalid configuration

with cloudflare_ruleset.cache_rule, on main.tf line 37, in resource "cloudflare_ruleset" "cache_example": 37: edge_ttl { using mode 'override_origin' requires setting a default for ttl

Error: invalid configuration

with cloudflare_ruleset.cache_rule, on main.tf line 41, in resource "cloudflare_ruleset" "cache_example": 41: browser_ttl { using mode 'override_origin' requires setting a default for ttl

Steps to reproduce

  1. Create a cache rule that passes value to edge_ttl and browser_ttl using variables when mode is 'override_origin'.
  2. Run terraform plan
  3. You'll see an error indicating that 'override_origin' requires setting a default for ttl

Additional factoids

No response

References

No response

github-actions[bot] commented 3 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

Bass-03 commented 1 week ago

This started on 4.7 when you guys changed to terraform-plugin-framework here https://github.com/cloudflare/terraform-provider-cloudflare/pull/2170

Why does it matter? We can not use cloudflare_ruleset in a module and add the ttf defaults via locals or variables, it only accepts hardcoded values.

Hence, we are pinning the cloudflare provider to 4.6 for the time being