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

Fix browser_cache_ttl page rule action bugs #379

Merged
merged 15 commits into from
Jun 20, 2019

Conversation

stevehodgkiss
Copy link
Contributor

Addresses 2 issues with browser_cache_ttl due to 0 being the default value and also a valid & desirable value to define it with.

  • Deleting: After a browser_cache_ttl page rule action has been applied, it can't be deleted because its value is the default of 0 when it's removed, so it ends up in the update PUT request as being set to 0.
  • Setting to 0 initially: Defining browser_cache_ttl = 0 initially doesn't work because it's not seen as a change (current workaround is to set to something else first, then 0).

Using an integer for this value in the schema makes that quite challenging. Another option might be to make -1 a special and default value used to mean "not set". The approach in this PR is to use a string instead.

I'd like to take a closer look at some of the test cases before this merged (hence WIP in the title).

@ghost ghost added the size/M label Jun 13, 2019
@jacobbednarz jacobbednarz self-assigned this Jun 13, 2019
})
}

func buildPageRule(actions string) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's swap this one for a specific configuration setup (like we do for testAccCheckCloudflarePageRuleConfigMinify). It's probably a bit more verbose but it will be explicit about what is getting setup.

@jacobbednarz
Copy link
Member

Thanks for getting this up @stevehodgkiss! 🍰 I like the additional tests we've added here however a couple things we should update to align with the other tests.

  1. The integration tests you've added here should be named TestAccCloudflarePageRule_*. The TestAcc is important as that is what the CI runner looks for when it's searching for tests to run. See https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html#test-files for more details. Right now, these new tests aren't being automatically run.
  2. We should structure the tests similar to the ones we already have where each uses an explicit resource definition and the test setup just relies on that. An example:

}

//#################################################################

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@patryk
Copy link
Contributor

patryk commented Jun 13, 2019

Yes, I think changing the field to string is a good compromise, and in the end should not deal any major damage, provided Terraform uses strings implicitly everywhere in .tf files anyway.

@jacobbednarz
Copy link
Member

I think this is all the scenarios.

scenario state expected outcome remote expected outcome
page rule with browser_cache_ttl = 0 can be imported browser_cache_ttl = 0 page rule exists with browser_cache_ttl value of 0
page rule with browser_cache_ttl = 10 can be imported browser_cache_ttl = 10 page rule exists with browser_cache_ttl value of 10
page rule with browser_cache_ttl absent can be imported browser_cache_ttl should not be present page rule without browser_cache_ttl should exist
create a new rule browser_cache_ttl = 0 browser_cache_ttl = 0 page rule exists with browser_cache_ttl value of 0
create a new rule browser_cache_ttl = 10 browser_cache_ttl = 10 page rule exists with browser_cache_ttl value of 10
create a new rule browser_cache_ttl absent browser_cache_ttl should not be present page rule doesn't get created with browser_cache_ttl attribute
delete an existing page rule where browser_cache_ttl was set to 0 browser_cache_ttl should not be present page rule isn't present with browser_cache_ttl value
delete an existing page rule where browser_cache_ttl was set to 10 browser_cache_ttl should not be present page rule isn't present with browser_cache_ttl value
delete an existing page rule where browser_cache_ttl is absent browser_cache_ttl should not be present page rule isn't present with browser_cache_ttl value
update an existing page rule from not having browser_cache_ttl present to browser_cache_ttl value of 0 browser_cache_ttl = 0 page rule is updated with browser_cache_ttl value of 0
update an existing page rule from browser_cache_ttl = 0 to be 10 browser_cache_ttl = 10 page rule is updated with browser_cache_ttl value of 10
update an existing page rule from browser_cache_ttl = 10 to be 0 browser_cache_ttl = 0 page rule is updated with browser_cache_ttl value of 0

@jacobbednarz
Copy link
Member

jacobbednarz commented Jun 18, 2019

Looking great @stevehodgkiss! The only three test cases I think we're missing here is the ones for importing resources (one with a value of 0, one with a value of > 0 and one without the attribute entirely). Here is an example of another resource testing the import.

https://github.com/terraform-providers/terraform-provider-cloudflare/blob/5d7a3d1b81a79f6489691f3d74330a841fe2e55e/cloudflare/resource_cloudflare_zone_lockdown_test.go#L36-L57

Looking at the code, this should Just Work™ once the tests are added.

I've run the integration tests on CI and in another couple of accounts and so far, 💚 all the way.

…nally

This warning was being emitted, and the main import test would fail if
`browser_cache_ttl = 0` (or any value) was added.

Error setting actions in page rule "8f8d71918b97a24ed742e037596b5e1c": actions.0.browser_cache_ttl: '' expected type 'string', got unconvertible type 'float64
@ghost ghost added size/L and removed size/M labels Jun 19, 2019
@stevehodgkiss stevehodgkiss changed the title WIP Fix browser_cache_ttl page rule action bugs Fix browser_cache_ttl page rule action bugs Jun 20, 2019
Copy link
Member

@jacobbednarz jacobbednarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome work! thanks @stevehodgkiss 🍭

@jacobbednarz jacobbednarz merged commit 2e301de into cloudflare:master Jun 20, 2019
@patryk
Copy link
Contributor

patryk commented Jun 20, 2019

Big thanks @stevehodgkiss for helping out with this issue! Appreciated.

boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this pull request Feb 28, 2022
* gofmt flarectl.go

a no-op, which my editor picke up on.

* pass cli context to writeTable

... so that ultimately writeTable, an internal function, will be able to
support a different output type depending on the client options given.

* support json output via --json

... for all outputs which were previously using writeTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants