Can't set default ttl using a variable
Confirmation
- [X] This is a bug with an existing resource and is not a feature request or enhancement. Feature requests should be submitted with Cloudflare Support or your account team.
- [X] I have searched the issue tracker and my issue isn't already found.
- [X] I have replicated my issue using the latest version of the provider and it is still present.
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
- Create a cache rule that passes value to edge_ttl and browser_ttl using variables when mode is 'override_origin'.
- Run terraform plan
- You'll see an error indicating that 'override_origin' requires setting a default for ttl
Additional factoids
No response
References
No response
Community Note
Voting for Prioritization
- Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
- If you are interested in working on this issue, please leave a comment.
- If this would be your first contribution, please review the contribution guide.
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
Thank you for your bug report! We are not doing active development on the v4 Terraform providers at this time. If you can reproduce this on v5, please reopen your issue and we can have a look there. Thank you!
It Is reproducible on V5.
Mundo
miokimia.com Ideas, Blog and Studio
On Mon, Apr 14, 2025, 17:32 Justin Hutchings @.***> wrote:
Thank you for your bug report! We are not doing active development on the v4 Terraform providers at this time. If you can reproduce this on v5, please reopen your issue and we can have a look there. Thank you!
— Reply to this email directly, view it on GitHub https://github.com/cloudflare/terraform-provider-cloudflare/issues/3736#issuecomment-2803308618, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRUMN33BPTQ3CTGLZ522TD2ZRASTAVCNFSM6AAAAABM6A53Q2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBTGMYDQNRRHA . You are receiving this because you commented.Message ID: @.*** com> jhutchings1 left a comment (cloudflare/terraform-provider-cloudflare#3736) https://github.com/cloudflare/terraform-provider-cloudflare/issues/3736#issuecomment-2803308618
Thank you for your bug report! We are not doing active development on the v4 Terraform providers at this time. If you can reproduce this on v5, please reopen your issue and we can have a look there. Thank you!
— Reply to this email directly, view it on GitHub https://github.com/cloudflare/terraform-provider-cloudflare/issues/3736#issuecomment-2803308618, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRUMN33BPTQ3CTGLZ522TD2ZRASTAVCNFSM6AAAAABM6A53Q2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBTGMYDQNRRHA . You are receiving this because you commented.Message ID: @.*** com>