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

browser_cache_ttl cannot initially be zero #344

Closed
jacobbednarz opened this issue May 10, 2019 · 1 comment
Closed

browser_cache_ttl cannot initially be zero #344

jacobbednarz opened this issue May 10, 2019 · 1 comment

Comments

@jacobbednarz
Copy link
Member

Terraform Version

$ terraform -v
Terraform v0.11.13
+ provider.cloudflare (unversioned) # currently master @ 14128d0

Affected Resource(s)

  • cloudflare_page_rule

Terraform Configuration Files

provider "cloudflare" {
  email  = "${var.cloudflare_email}"
  token  = "${var.cloudflare_token}"
}

resource "cloudflare_page_rule" "foobar" {
  zone     = "${var.cloudflare_zone}"
  target   = "${var.cloudflare_zone}/browser-cache-ttl-init-failure"
  priority = 1

  actions = {
    browser_cache_ttl = 0
  }
}

Expected Behavior

Page rule should be created with an action of browser_cache_ttl and a value of 0 (respect cache control headers for Enterprise users)

Actual Behavior

Page rule was not created and Terraform threw an error that actions cannot be empty which is enforced by the schema.

Steps to Reproduce

  1. Use a Clouflare Enterprise account
  2. terraform apply

Important Factoids

This is only an issue for Enterprise users who want to initially set the browser_cache_ttl to 0. It is not an issue if you initially set to 1 an then to 0 (this is also the workaround available if you're currently impacted).

Further information

From debugging this issue extensively in #338, the issue boils down to the fact that we are using a zero value for both the inactive state and an a desirable value. This causes an issue whereby the Terraform state ends up thinking that the configuration doesn't have any changes and it shouldn't include the action.browser_cache_ttl in the payload.

I tried a couple of methods to force this into working:

  • Swap to using TypeString as the schema type. This would address the issue because the default value would be "" instead of "0". The resource is then updated to cast it as an integer where needed. Some parts of page_rules: Make cache TTLs behave sensibly #334 show how this would work. I didn't end up going forward with this as there was a better way of solving the particular issue (not just this one).
  • Use HasChange to determine the old and new values. This didn't end up working because the old and new values were always the same and couldn't be differentiated. I tried combining it with GetOkExists however encountered the same problem where the default was always being set so it was always coming back as not changing.
@jacobbednarz jacobbednarz changed the title browser_cache_ttl canot initially be zero browser_cache_ttl cannot initially be zero May 12, 2019
@jacobbednarz
Copy link
Member Author

Fixed via #379

boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this issue Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant