-
Notifications
You must be signed in to change notification settings - Fork 630
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
datasource/zones: Perform filtering on server side #708
datasource/zones: Perform filtering on server side #708
Conversation
The initial implementation of the datasource had the provider request all the available zones and then we would perform some logic within the provider to filter down to the match the attributes. This is slightly inefficient for a couple of reasons: - We are requesting *all* zones (even if we only want a small subset of them); and - We are duplicating the zone filtering logic in the provider that is already available in the API This change replaces that functionality by pushing the responsibility of filtering back to the API. It maintains a reasonable amount of backwards compatibility outlined in the initial PR (cloudflare#168) where the "name" had to accept wildcards but under the hood accepted a full regex. Instead, we use the `contains:` modifier on the name search parameter which will instead fuzzy match. The rest remains the same but is performed via the API. Fixes cloudflare#707
Changes the `cloudflare_zone_sweeper` to be restricted to an account ID provided. This prevents using API keys with global access from sweeping the wrong zones/accounts. Fixes cloudflare#648
We advertise in documentation that the name parameter accepts regular expression. Would be great to keep that functionality (regexp detection?). |
The Terraform documentation will be updated to whatever we decide on (purposefully left to last to save commits changing based on the implementation) but I’m not sure where you would really need a full regex here. The use cases I’ve come across have all been fuzzy matching ( |
@ewilde would enjoy your thoughts here as the original implementer. @XaF and @inge4pres for good measure as I think I recall seeing issues/comments but my memory may be failing on that. |
@jacobbednarz for our usage of the data source this would be a minor breaking change, not an issue 👍 for us. |
I love this! Our use case is aimed primarily at similar TLD so having a regex would be ideal. Thanks for putting this together |
So you’d prefer if we kept the regex? This PR would remove it in order to move where the filtering would be occurring. Would you be able to provide a few examples of what you’d be looking to do and I’ll see if it matches the proposals here? |
I don't see any problem on my side. |
This might be a better way forward. Offer both and toggle the functionality based on another directive or value but opt to the simplest and most common use case. Some examples I’m thinking of: # get a specific domain which calls the list zones endpoint with ?zone=example.com (detects a full domain being passed in)
resource “...” “...” {
name = “example.com”
} # get a series of domains (example.com, example.net) which calls the list zones endpoint with ?zone=contains:example
resource “...” “...” {
name = “example”
} # get a series of domains (example.com, example.net) which calls the list zones endpoint with ?zone=contains:example but also filters in the provider for only the .com
resource “...” “...” {
name = “example”
match = “.com$”
} What do you think? |
I like the approach! |
Potentially problematic as I don't have exact usage statistics on the values being plugged in. Perhaps a |
I’ll take a pass at this and update the PR soon. |
Leverage the abilities of the zone filtering on the server side more by providing available options within Terraform to control how the API request is made.
I really like the details in the documentation.
Feels to me that when using regex I might still want to select multiple zones, even more for something called |
Thanks for your patience here. I think I've finally got something workable. I've updated the description to keep up with the new changes so I do recommend checking that out but the summary is:
I think I've marked off all of the feedback but would appreciate you folks making another pass over this one for me |
Ah, that comment maybe be slightly confusing. This specific example is tied to the scenario where you have three domains:
And you're searching for "example" via the API but you're only targetting a single domain (the one starting with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a last pass at the code and except for that one comment below, everything looks good to me
Since we updated the `cloudflare_zone` datasource cloudflare#708 to perform different types of matching, this test has been failing due to not having the ability to list all zones. This isn't really a problem but it did identify we could be lazier with the resource definition and pass in a static zone ID instead of relying on an extra zone listing call to fetch all the information.
Hey @jacobbednarz, With that said, we recently started consuming the provider at version >=
After a bit of investigation, we managed to narrow it down to the replacement of For us, this is causing the data resource to only return a subset of all If you don't mind, could you please take a look to confirm whether or not this is a regression? Thank you 😄 ! |
It was unfortunately but sit tight! cloudflare/cloudflare-go#534 has the fix but I've dropped the ball on following up on the PR comments. This fix will be in the next release of cloudflare-go (with or without that comment fix) |
Thanks for the clarification. We weren't sure whether this was already a know regression or not. It is good to know that it is and that there is work in the pipeline to fix it 🚀 !! We will rollback and pause the version bump until the changes happen upstream then 👍 |
…rsion ruleset: add version to action parameters struct
The initial implementation of the datasource had the provider request all
the available zones and then we would perform some logic within the
provider to filter down to the match the attributes. This is slightly
inefficient for a couple of reasons:
them); and
already available in the API
This change replaces that functionality by pushing the responsibility of
filtering back to the API using inbuilt functionality. It maintains a reasonable
amount of backwards compatibility outlined in the initial PR (#168) where the
"name" had to accept wildcards but under the hood accepted a full regex.
Instead, we will be making:
name
value a string of the broad lookup termmatch
an optional refined regex which to further filter the result bylookup_type
whether you're wanting to perform an exact or fuzzy lookup onthe value
Examples (also in the website documentation)
Given you have the following domains in Cloudflare.
A side effect of this change is that we can also update the
cloudflare_zone_sweeper
to be restricted to an account ID provided.This prevents using API keys with global access from sweeping the wrong
zones/accounts.
Fixes #707
Fixes #648
Depends on cloudflare/cloudflare-go#478