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

datasource/cloudflare_zones: support filtering by account_id #1401

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1401.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
datasource/cloudflare_zones: allow filtering by account_id
```
12 changes: 11 additions & 1 deletion cloudflare/data_source_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func dataSourceCloudflareZones() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -83,7 +87,7 @@ func dataSourceCloudflareZonesRead(d *schema.ResourceData, meta interface{}) err

zoneFilter := cloudflare.WithZoneFilters(
zoneLookupValue,
"",
filter.accountID,
filter.status,
)

Expand Down Expand Up @@ -156,10 +160,16 @@ func expandFilter(d interface{}) (*searchFilter, error) {
filter.status = status.(string)
}

accountID, ok := m["account_id"]
if ok {
filter.accountID = accountID.(string)
}

return filter, nil
}

type searchFilter struct {
accountID string
name string
regexValue *regexp.Regexp
lookupType string
Expand Down
11 changes: 11 additions & 0 deletions website/docs/d/zones.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ data "cloudflare_zones" "example" {
}
```

```hcl
# Look for all active zones in an account
data "cloudflare_zones" "example" {
filter {
account_id = "1d5fdc9e88c8a8c4518b068cd94331fe"
status = "active"
}
}
```

### Example usage with other resources

The example below matches all zones which have "example" in their value, end
Expand Down Expand Up @@ -99,6 +109,7 @@ values must match in order to be included, see below for full list.

**filter**

- `account_id` - (Optional) Only search for zones in this account.
- `name` - (Optional) A string value to search for.
- `lookup_type` - (Optional) The type of search to perform for the `name` value
when querying the zone API. Valid values: `"exact"` and `"contains"`. Defaults
Expand Down