Skip to content

Commit e0b70f0

Browse files
authored
Fix: Fixed Rule Base Resources (#416)
* Fix: Fixed Rule Base Resources * fix: Fixed rule reorder logic and error handling * fix: Fixed Integration Tests * fix: Fixed zia_firewall_filtering_rules reorder loigic
1 parent 43e6713 commit e0b70f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+730
-806
lines changed

CHANGELOG.md

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

3+
## 4.0.10 (April, 7 2025)
4+
5+
### Notes
6+
7+
- Release date: **(April, 7 2025)**
8+
- Supported Terraform version: **v1.x**
9+
10+
### Bug Fixes
11+
12+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fixed `zia_dlp_web_rules` sub rule reorder logic to ensure rules are ordered correctly.
13+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Replaced attribute `malicious_urls` with `bypass_urls` in the resource `zia_atp_security_exceptions` documentation.
14+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fixed the flattening function `flattenIDExtensionsListIDs` and schema function `setIDsSchemaTypeCustom`. This will ensure Terraform identifies plan changes when block lists are removed from the configuration.
15+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fix to attribute the `order` attribute in all rule based resources to ensure consistency on ordering logic.
16+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fix custom order logic on the resource `zia_firewall_filtering_rules` to ensure pre-defined rules are placed in the correct position to prevent drifts
17+
318
## 4.0.9 (March, 14 2025)
419

520
### Notes

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.0.9/$(GOOS)_$(GOARCH)
199+
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.0.10/$(GOOS)_$(GOARCH)
200200
else
201-
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.0.9/$(GOOS)_$(GOARCH)
201+
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/4.0.10/$(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.0.9
206+
go build -o $(DESTINATION)/terraform-provider-zia_v4.0.10
207207

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

docs/data-sources/zia_sandbox_rules.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ In addition to all arguments above, the following attributes are exported:
5151
* `url_categories` - (List of Strings) The list of URL categories to which the DLP policy rule must be applied.
5252
* `file_types` - (List of Strings) File type categories for which the policy is applied. If not set, the rule is applied across all file types.
5353

54-
`Devices`
55-
5654
`Who, Where and When` supports the following attributes:
5755

5856
* `locations` - (List of Objects) You can manually select up to `8` locations. When not used it implies `Any` to apply the rule to all groups.

docs/guides/release-notes.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@ 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.0.9``
15+
``Last updated: v4.0.10``
1616

1717
---
1818

19+
## 4.0.10 (April, 7 2025)
20+
21+
### Notes
22+
23+
- Release date: **(April, 7 2025)**
24+
- Supported Terraform version: **v1.x**
25+
26+
### Bug Fixes
27+
28+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fixed `zia_dlp_web_rules` sub rule reorder logic to ensure rules are ordered correctly.
29+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Replaced attribute `malicious_urls` with `bypass_urls` in the resource `zia_atp_security_exceptions` documentation.
30+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fixed the flattening function `flattenIDExtensionsListIDs` and schema function `setIDsSchemaTypeCustom`. This will ensure Terraform identifies plan changes when block lists are removed from the configuration.
31+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fix to attribute the `order` attribute in all rule based resources to ensure consistency on ordering logic.
32+
- [PR #416](https://github.com/zscaler/terraform-provider-zia/pull/416) - Fix custom order logic on the resource `zia_firewall_filtering_rules` to ensure pre-defined rules are placed in the correct position to prevent drifts
33+
1934
## 4.0.9 (March, 14 2025)
2035

2136
### Notes

docs/resources/zia_atp_security_exceptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The **zia_atp_security_exceptions** resource alows you to updates security excep
1414

1515
```hcl
1616
resource "zia_atp_security_exceptions" "this" {
17-
malicious_urls = [
17+
bypass_urls = [
1818
"site1.example.com",
1919
"site2.example.com",
2020
"site3.example.com",

docs/resources/zia_sandbox_rules.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ In addition to all arguments above, the following attributes are supported:
9393
* `url_categories` - (List of Strings) The list of URL categories to which the DLP policy rule must be applied.
9494
* `file_types` - (List of Strings) File type categories for which the policy is applied. If not set, the rule is applied across all file types.
9595

96-
`Devices`
97-
9896
`Who, Where and When` supports the following attributes:
9997

10098
* `locations` - (List of Objects) You can manually select up to `8` locations. When not used it implies `Any` to apply the rule to all groups.
@@ -113,3 +111,35 @@ In addition to all arguments above, the following attributes are supported:
113111

114112
* `zpa_app_segments` (List of Objects) The ZPA application segments to which the rule applies
115113
- `id` - (Integer) Identifier that uniquely identifies an entity
114+
115+
| **Supported File Types** |
116+
|:--------------------------------------------------------------------------------------------------------|
117+
|---------------------------------------------------------------------------------------|
118+
| `FTCATEGORY_BAT`, `FTCATEGORY_APK`, `FTCATEGORY_WINDOWS_SCRIPT_FILES`,|
119+
| `FTCATEGORY_JAVA_APPLET`, `FTCATEGORY_PDF_DOCUMENT`, `FTCATEGORY_MS_RTF`,|
120+
| `FTCATEGORY_FLASH`, `FTCATEGORY_POWERSHELL`, `FTCATEGORY_WINDOWS_LIBRARY`,|
121+
| `FTCATEGORY_MS_EXCEL`, `FTCATEGORY_HTA`, `FTCATEGORY_VISUAL_BASIC_SCRIPT`,|
122+
| `FTCATEGORY_MS_POWERPOINT`, `FTCATEGORY_TAR`, `FTCATEGORY_WINDOWS_EXECUTABLES`, |
123+
| `FTCATEGORY_SCZIP`, `FTCATEGORY_RAR`, `FTCATEGORY_ZIP`, `FTCATEGORY_P7Z`,|
124+
| `FTCATEGORY_MICROSOFT_INSTALLER`, `FTCATEGORY_BZIP2`, `FTCATEGORY_PYTHON`,|
125+
| `FTCATEGORY_MS_WORD`|
126+
|-------------------------------------------------------------------------------------------|
127+
128+
## Import
129+
130+
Zscaler offers a dedicated tool called Zscaler-Terraformer to allow the automated import of ZIA configurations into Terraform-compliant HashiCorp Configuration Language.
131+
[Visit](https://github.com/zscaler/zscaler-terraformer)
132+
133+
**zia_sandbox_rules** can be imported by using `<RULE ID>` or `<RULE NAME>` as the import ID.
134+
135+
For example:
136+
137+
```shell
138+
terraform import zia_sandbox_rules.example <rule_id>
139+
```
140+
141+
or
142+
143+
```shell
144+
terraform import zia_sandbox_rules.example <rule_name>
145+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-hclog v1.6.3
1010
github.com/hashicorp/terraform-plugin-sdk v1.17.2
1111
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1
12-
github.com/zscaler/zscaler-sdk-go/v3 v3.1.10
12+
github.com/zscaler/zscaler-sdk-go/v3 v3.1.13
1313
)
1414

1515
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK
401401
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
402402
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
403403
github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
404-
github.com/zscaler/zscaler-sdk-go/v3 v3.1.10 h1:umE4roT71TpzAr+bBYY8NwlHrkGa6juo6fvm34z9fig=
405-
github.com/zscaler/zscaler-sdk-go/v3 v3.1.10/go.mod h1:Iqwd9ZsD0SGNCkAejOP2dOMBgZh1PNFxiMXR2XMO6R4=
404+
github.com/zscaler/zscaler-sdk-go/v3 v3.1.13 h1:wqWLYFVL2HsPXLcX+Os709eY0Hv6ETnWfHGUGS2K8fo=
405+
github.com/zscaler/zscaler-sdk-go/v3 v3.1.13/go.mod h1:DEBcnZb0Yx1TYcR0kqhsFncIvjJ2+bo6UQl/qUUwTVo=
406406
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
407407
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
408408
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

zia/common.go

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ func listIDsSchemaType(desc string) *schema.Schema {
4242
}
4343

4444
func setIDsSchemaTypeCustom(maxItems *int, desc string) *schema.Schema {
45+
ids := &schema.Schema{
46+
Type: schema.TypeSet,
47+
Optional: true,
48+
Elem: &schema.Schema{
49+
Type: schema.TypeInt,
50+
},
51+
}
52+
if maxItems != nil && *maxItems > 0 {
53+
ids.MaxItems = *maxItems
54+
}
55+
return &schema.Schema{
56+
Type: schema.TypeSet,
57+
Optional: true,
58+
// Computed: true,
59+
MaxItems: 1,
60+
Description: desc,
61+
Elem: &schema.Resource{
62+
Schema: map[string]*schema.Schema{
63+
"id": ids,
64+
},
65+
},
66+
}
67+
}
68+
69+
// Used for Computed Attributes
70+
func setIDsSchemaTypeCustomSpecial(maxItems *int, desc string) *schema.Schema {
4571
ids := &schema.Schema{
4672
Type: schema.TypeSet,
4773
Optional: true,
@@ -65,7 +91,6 @@ func setIDsSchemaTypeCustom(maxItems *int, desc string) *schema.Schema {
6591
},
6692
}
6793
}
68-
6994
func setSingleIDSchemaTypeCustom(desc string) *schema.Schema {
7095
return &schema.Schema{
7196
Type: schema.TypeSet,
@@ -312,23 +337,49 @@ func flattenCustomIDSet(customID *common.IDCustom) []interface{} {
312337
}
313338

314339
func flattenIDExtensionsListIDs(list []common.IDNameExtensions) []interface{} {
315-
if list == nil {
340+
// Skip if the list is empty
341+
if len(list) == 0 {
316342
return nil
317343
}
344+
318345
ids := []int{}
319346
for _, item := range list {
320347
if item.ID == 0 && item.Name == "" {
321348
continue
322349
}
323350
ids = append(ids, item.ID)
324351
}
352+
353+
// Skip if no valid IDs
354+
if len(ids) == 0 {
355+
return nil
356+
}
357+
325358
return []interface{}{
326359
map[string]interface{}{
327360
"id": ids,
328361
},
329362
}
330363
}
331364

365+
// func flattenIDExtensionsListIDs(list []common.IDNameExtensions) []interface{} {
366+
// if len(list) == 0 {
367+
// return nil
368+
// }
369+
// ids := []int{}
370+
// for _, item := range list {
371+
// if item.ID == 0 && item.Name == "" {
372+
// continue
373+
// }
374+
// ids = append(ids, item.ID)
375+
// }
376+
// return []interface{}{
377+
// map[string]interface{}{
378+
// "id": ids,
379+
// },
380+
// }
381+
// }
382+
332383
// Flattening function used in the Forwarding Control Policy Resource
333384
func flattenIDNameSet(idName *common.IDName) []interface{} {
334385
idNameSet := make([]interface{}, 0)
@@ -740,7 +791,7 @@ func getSandboxFileTypes() *schema.Schema {
740791
Type: schema.TypeString,
741792
ValidateDiagFunc: validateSandboxRuleFileTypes(),
742793
},
743-
Optional: true,
794+
Required: true,
744795
}
745796
}
746797

@@ -822,9 +873,9 @@ func (p RuleIDOrderPairList) Less(i, j int) bool {
822873
}
823874
func (p RuleIDOrderPairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
824875

825-
func reorderAll(resourceType string, getCount func() (int, error), updateOrder func(id, order int) error) {
826-
ticker := time.NewTicker(time.Second * 5) // create a ticker that ticks every half minute
827-
defer ticker.Stop() // stop the ticker when the loop ends
876+
func reorderAll(resourceType string, getCount func() (int, error), updateOrder func(id, order int) error, beforeReorder func()) {
877+
ticker := time.NewTicker(time.Second * 10) // create a ticker that ticks every half minute
878+
defer ticker.Stop() // stop the ticker when the loop ends
828879
numResources := []int{0, 0, 0}
829880
for {
830881
select {
@@ -845,6 +896,9 @@ func reorderAll(resourceType string, getCount func() (int, error), updateOrder f
845896
// sort by order (ascending)
846897
sorted := sortOrders(rules.orders[resourceType])
847898
log.Printf("[INFO] sorting filtering rule after tick; sorted:%v", sorted)
899+
if beforeReorder != nil {
900+
beforeReorder()
901+
}
848902
for _, v := range sorted {
849903
if v.Order <= count {
850904
if err := updateOrder(v.ID, v.Order); err != nil {
@@ -870,7 +924,7 @@ func markOrderRuleAsDone(id int, resourceType string) {
870924
rules.Unlock()
871925
}
872926

873-
func reorder(order, id int, resourceType string, getCount func() (int, error), updateOrder func(id, order int) error) {
927+
func reorderWithBeforeReorder(order, id int, resourceType string, getCount func() (int, error), updateOrder func(id, order int) error, beforeReorder func()) {
874928
rules.Lock()
875929
shouldCallReorder := false
876930
if len(rules.orders) == 0 {
@@ -891,6 +945,10 @@ func reorder(order, id int, resourceType string, getCount func() (int, error), u
891945
if shouldCallReorder {
892946
log.Printf("[INFO] starting to reorder the rules, delegating to rule:%d, order:%d", id, order)
893947
// one resource will wait until all resources are done and reorder then return
894-
reorderAll(resourceType, getCount, updateOrder)
948+
reorderAll(resourceType, getCount, updateOrder, beforeReorder)
895949
}
896950
}
951+
952+
func reorder(order, id int, resourceType string, getCount func() (int, error), updateOrder func(id, order int) error) {
953+
reorderWithBeforeReorder(order, id, resourceType, getCount, updateOrder, nil)
954+
}

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.0.9"
3+
var version = "4.0.10"
44

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

0 commit comments

Comments
 (0)