Skip to content

Commit 64eae7e

Browse files
authored
fix: Fixed URL Category resource READ function (#498)
1 parent 1e7dffa commit 64eae7e

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

CHANGELOG.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 4.6.1 (November, 20 2025)
4+
5+
### Notes
6+
7+
- Release date: **(November, 20 2025)**
8+
- Supported Terraform version: **v1.x**
9+
10+
### Bug Fixes
11+
12+
- [PR #498](https://github.com/zscaler/terraform-provider-zia/pull/498) - Fixed `zia_url_categories` resource READ function for better state refresh and rate limiting conservation. Also fixed issue with category_type `TLD_CATEGORY` not being set correctly in the state during creation.
13+
314
## 4.6.0 (November, 19 2025)
415

516
### Notes
@@ -9,14 +20,14 @@
920

1021
### Enhancements
1122

12-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Added new data source `zia_file_type_categories`. This datasource can be referenced within the `zia_dlp_web_rules` in the attribute `file_type_categories`
13-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Added new data source and resource `zia_custom_file_types`
14-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Improved `zia_url_categories` resource READ function for better state refresh and rate limiting conservation.
23+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Added new data source `zia_file_type_categories`. This datasource can be referenced within the `zia_dlp_web_rules` in the attribute `file_type_categories`
24+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Added new data source and resource `zia_custom_file_types`
25+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Improved `zia_url_categories` resource READ function for better state refresh and rate limiting conservation.
1526

1627
### Bug Fixes
1728

18-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Upgraded to [Zscaler SDK GO v3.8.6](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v3.8.6) to fix pagination in some resources.
19-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Fixed drift with attribute `static_location_groups` in the resource `zia_location_management`
29+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Upgraded to [Zscaler SDK GO v3.8.6](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v3.8.6) to fix pagination in some resources.
30+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Fixed drift with attribute `static_location_groups` in the resource `zia_location_management`
2031

2132
## 4.5.3 (October, 17 2025)
2233

GNUmakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ test\:integration\:zscalertwo:
196196
build13: GOOS=$(shell go env GOOS)
197197
build13: GOARCH=$(shell go env GOARCH)
198198
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
199-
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.6.0/$(GOOS)_$(GOARCH)
199+
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.6.1/$(GOOS)_$(GOARCH)
200200
else
201-
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.6.0/$(GOOS)_$(GOARCH)
201+
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.6.1/$(GOOS)_$(GOARCH)
202202
endif
203203
build13: fmtcheck
204204
@echo "==> Installing plugin to $(DESTINATION)"
205205
@mkdir -p $(DESTINATION)
206-
go build -o $(DESTINATION)/terraform-provider-zia_v4.6.0
206+
go build -o $(DESTINATION)/terraform-provider-zia_v4.6.1
207207

208208
coverage: test
209209
@echo "✓ Opening coverage for unit tests ..."

docs/guides/release-notes.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ description: |-
1212
Track all ZIA Terraform provider's releases. New resources, features, and bug fixes will be tracked here.
1313

1414
---
15-
``Last updated: v4.6.0``
15+
``Last updated: v4.6.1``
1616

1717
---
1818

19+
## 4.6.1 (November, 20 2025)
20+
21+
### Notes
22+
23+
- Release date: **(November, 20 2025)**
24+
- Supported Terraform version: **v1.x**
25+
26+
### Bug Fixes
27+
28+
- [PR #498](https://github.com/zscaler/terraform-provider-zia/pull/498) - Fixed `zia_url_categories` resource READ function for better state refresh and rate limiting conservation. Also fixed issue with category_type `TLD_CATEGORY` not being set correctly in the state during creation.
29+
1930
## 4.6.0 (November, 19 2025)
2031

2132
### Notes
@@ -25,14 +36,14 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi
2536

2637
### Enhancements
2738

28-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Added new data source `zia_file_type_categories`. This datasource can be referenced within the `zia_dlp_web_rules` in the attribute `file_type_categories`
29-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Added new data source and resource `zia_custom_file_types`
30-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Improved `zia_url_categories` resource READ function for better state refresh and rate limiting conservation.
39+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Added new data source `zia_file_type_categories`. This datasource can be referenced within the `zia_dlp_web_rules` in the attribute `file_type_categories`
40+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Added new data source and resource `zia_custom_file_types`
41+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Improved `zia_url_categories` resource READ function for better state refresh and rate limiting conservation.
3142

3243
### Bug Fixes
3344

34-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Upgraded to [Zscaler SDK GO v3.8.6](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v3.8.6) to fix pagination in some resources.
35-
- [PR #495](https://github.com/zscaler/terraform-provider-zia/pull/495) - Fixed drift with attribute `static_location_groups` in the resource `zia_location_management`
45+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Upgraded to [Zscaler SDK GO v3.8.6](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v3.8.6) to fix pagination in some resources.
46+
- [PR #496](https://github.com/zscaler/terraform-provider-zia/pull/496) - Fixed drift with attribute `static_location_groups` in the resource `zia_location_management`
3647

3748
## 4.5.3 (October, 17 2025)
3849

zia/common/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package common
22

3-
var version = "4.6.0"
3+
var version = "4.6.1"
44

55
// Version returns version of provider
66
func Version() string {

zia/resource_zia_url_categories.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ func resourceURLCategoriesRead(ctx context.Context, d *schema.ResourceData, meta
263263
}
264264

265265
// Use GetAll() instead of Get() to reduce API calls during terraform refresh
266-
// This fetches all custom URL categories in a single API call instead of one per category
267-
allCategories, err := urlcategories.GetAll(ctx, service, true, false) // customOnly=true, includeOnlyUrlKeywordCounts=false
266+
// customOnly=true to only retrieve custom categories (which are the ones managed by Terraform)
267+
// includeOnlyUrlKeywordCounts=false to get full category details
268+
allCategories, err := urlcategories.GetAll(ctx, service, true, false)
268269
if err != nil {
269270
return diag.FromErr(err)
270271
}
@@ -278,11 +279,20 @@ func resourceURLCategoriesRead(ctx context.Context, d *schema.ResourceData, meta
278279
}
279280
}
280281

281-
// Category not found
282+
// If not found in GetAll(), fall back to individual Get() call
283+
// This handles newly created categories that may not be in the cached list yet
282284
if resp == nil {
283-
log.Printf("[WARN] Removing zia url category %s from state because it no longer exists in ZIA", d.Id())
284-
d.SetId("")
285-
return nil
285+
log.Printf("[DEBUG] Category %s not found in GetAll() response, falling back to individual Get() call", id)
286+
individualResp, err := urlcategories.Get(ctx, service, id)
287+
if err != nil {
288+
if respErr, ok := err.(*errorx.ErrorResponse); ok && respErr.IsObjectNotFound() {
289+
log.Printf("[WARN] Removing url category %s from state because it no longer exists in ZIA", d.Id())
290+
d.SetId("")
291+
return nil
292+
}
293+
return diag.FromErr(err)
294+
}
295+
resp = individualResp
286296
}
287297

288298
log.Printf("[INFO] Getting url category :\n%+v\n", resp)

0 commit comments

Comments
 (0)