Skip to content

Commit

Permalink
feat: Added New DLP Engine Resource (#258)
Browse files Browse the repository at this point in the history
* feat: Added New DLP Engine Resource
* (doc): Added new zia_dlp_engine resource doc
* fix: url filtering rule test
* Fix: Disable Firewall rule test
  • Loading branch information
willguibr authored Aug 2, 2023
1 parent e0506b5 commit 8372f59
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 69 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Changelog

## 2.5.7 (July, 6 2023)
## 2.6.0 (August, 1 2023)

### Notes

- Release date: **(July, 6 2023)**
- Release date: **(August, 1 2023)**
- Supported Terraform version: **v1.x**

### Enhancements

- [PR #257](https://github.com/zscaler/terraform-provider-zia/pull/257) Added New Public ZIA DLP Engine Endpoints (POST/PUT/DELETE)
⚠️ **WARNING:** "Before using the new ``zia_dlp_engines`` resource contact [Zscaler Support](https://help.zscaler.com/login-tickets)." and request the following API methods ``POST``, ``PUT``, and ``DELETE`` to be enabled for your organization.

### Fixes

- [PR #251](https://github.com/zscaler/terraform-provider-zia/pull/251) Added new predefied URL Category ``AI_ML_APPS`` to resource ``resource_zia_url_categories``.
- [PR #251](https://github.com/zscaler/terraform-provider-zia/pull/251) Upgraded provider to latest Zscaler SDK GO v1.6.1
- [PR #253](https://github.com/zscaler/terraform-provider-zia/pull/253) Fixed documentation for resource ``zia_firewall_filtering_destination_groups``

## 2.5.6 (June, 10 2023)
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ build: fmtcheck
build13: GOOS=$(shell go env GOOS)
build13: GOARCH=$(shell go env GOARCH)
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/2.5.7/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/2.6.0/$(GOOS)_$(GOARCH)
else
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/2.5.7/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/2.6.0/$(GOOS)_$(GOARCH)
endif
build13: fmtcheck
go mod tidy && go mod vendor
@echo "==> Installing plugin to $(DESTINATION)"
@mkdir -p $(DESTINATION)
go build -o $(DESTINATION)/terraform-provider-zia_v2.5.7
go build -o $(DESTINATION)/terraform-provider-zia_v2.6.0

test: fmtcheck
go test $(TEST) || exit 1
Expand Down
12 changes: 8 additions & 4 deletions docs/guides/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ description: |-
Track all ZIA Terraform provider's releases. New resources, features, and bug fixes will be tracked here.

---
``Last updated: v2.5.7``
``Last updated: v2.6.0``

---

## 2.5.7 (July, 6 2023)
## 2.6.0 (August, 1 2023)

### Notes

- Release date: **(July, 6 2023)**
- Release date: **(August, 1 2023)**
- Supported Terraform version: **v1.x**

### Enhancements

- [PR #257](https://github.com/zscaler/terraform-provider-zia/pull/257) Added New Public ZIA DLP Engine Endpoints (POST/PUT/DELETE)
⚠️ **WARNING:** "Before using the new ``zia_dlp_engines`` resource contact [Zscaler Support](https://help.zscaler.com/login-tickets)." and request the following API methods ``POST``, ``PUT``, and ``DELETE`` to be enabled for your organization.

### Fixes

- [PR #251](https://github.com/zscaler/terraform-provider-zia/pull/251) Added new predefied URL Category ``AI_ML_APPS`` to resource ``resource_zia_url_categories``.
- [PR #251](https://github.com/zscaler/terraform-provider-zia/pull/251) Upgraded provider to latest Zscaler SDK GO v1.6.1
- [PR #253](https://github.com/zscaler/terraform-provider-zia/pull/253) Fixed documentation for resource ``zia_firewall_filtering_destination_groups``

## 2.5.6 (June, 10 2023)
Expand Down
40 changes: 40 additions & 0 deletions docs/resources/zia_dlp_engines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
subcategory: "Data Loss Prevention"
layout: "zscaler"
page_title: "ZIA: dlp_engines"
description: |-
Get information about ZIA DLP Engines.
---

# Data Source: zia_dlp_engines

Use the **zia_dlp_engines** resource allows the creation and management of ZIA DLP Engines in the Zscaler Internet Access cloud or via the API.

⚠️ **WARNING:** "Before using the new ``zia_dlp_engines`` resource contact [Zscaler Support](https://help.zscaler.com/login-tickets)." and request the following API methods ``POST``, ``PUT``, and ``DELETE`` to be enabled for your organization.

## Example Usage

```hcl
# Retrieve a DLP Engine by name
resource "zia_dlp_engines" "this" {
name = "Example"
description = "Example"
engine_expression = "((D63.S > 1))"
custom_dlp_engine = true
}
```

## Argument Reference

The following arguments are supported:

### Required

* `name` - (Required) The DLP engine name as configured by the admin. This attribute is required in POST and PUT requests for custom DLP engines.
* `predefined_engine_name` - (String) The name of the predefined DLP engine.
* `engine_expression` - (String) The boolean logical operator in which various DLP dictionaries are combined within a DLP engine's expression.
* `custom_dlp_engine` - (Bool) Indicates whether this is a custom DLP engine. If this value is set to true, the engine is custom.

### Optional

* `description` - (String) The DLP engine's description.
3 changes: 3 additions & 0 deletions examples/zia_dlp_engines/datasource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "zia_dlp_engines" "this" {
name = "Custom_DLP_Engine"
}
7 changes: 5 additions & 2 deletions examples/zia_dlp_engines/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
data "zia_dlp_engines" "this" {
name = "Custom_DLP_Engine"
resource "zia_dlp_engines" "this" {
name = "Example1000"
description = "Example1000"
engine_expression = "((D63.S > 1))"
custom_dlp_engine = true
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
github.com/zscaler/zscaler-sdk-go v1.6.4
github.com/zscaler/zscaler-sdk-go v1.7.0
)

require (
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down Expand Up @@ -356,8 +357,8 @@ github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0
github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
github.com/zscaler/zscaler-sdk-go v1.6.4 h1:DVoNCfJHOPJcUhogg8Wk676X+2tzp8BfaYxokPK2Un8=
github.com/zscaler/zscaler-sdk-go v1.6.4/go.mod h1:37jTTyECA0nHtDQJ9RQcDXmtIu6UYA4Y1ppGzfS2rbE=
github.com/zscaler/zscaler-sdk-go v1.7.0 h1:vE0DhIqNMxEnD7AUzSpm66wrWog29LMGBOfdCiRoem4=
github.com/zscaler/zscaler-sdk-go v1.7.0/go.mod h1:MNjkC5vOnUdlQUVgPk8ePOR5YuRgcRf003PS1N1tYqc=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
1 change: 1 addition & 0 deletions zia/common/resourcetype/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
TrafficForwardingVPNCredentials = "zia_traffic_forwarding_vpn_credentials"
TrafficForwardingLocManagement = "zia_location_management"
DLPDictionaries = "zia_dlp_dictionaries"
DLPEngines = "zia_dlp_engines"
DLPNotificationTemplates = "zia_dlp_notification_templates"
DLPWebRules = "zia_dlp_web_rules"
AdminUsers = "zia_admin_users"
Expand Down
5 changes: 5 additions & 0 deletions zia/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ const (
DLPDictionaryDescription = "this is an acceptance test"
)

// DLP Engines resource/datasource
const (
DLPCustomEngine = true
)

// DLP Dictionaries resource/datasource
const (
DLPNoticationTemplateAttachContent = true
Expand Down
56 changes: 14 additions & 42 deletions zia/data_source_zia_dlp_engines_test.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,32 @@
package zia

import (
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/zscaler/terraform-provider-zia/v2/zia/common/resourcetype"
"github.com/zscaler/terraform-provider-zia/v2/zia/common/testing/method"
"github.com/zscaler/terraform-provider-zia/v2/zia/common/testing/variable"
)

func TestAccDataSourceDLPEngines_Basic(t *testing.T) {
resourceTypeAndName, dataSourceTypeAndName, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.DLPEngines)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDLPEnginesDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceDLPEnginesConfig_basic,
Config: testAccCheckDLPEnginesConfigure(resourceTypeAndName, generatedName, generatedName, variable.DLPCustomEngine),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.credit_cards"),
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.canada_ssn"),
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.us_ssn"),
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.glba"),
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.hipaa"),
testAccDataSourceDLPEnginesCheck("data.zia_dlp_engines.pci"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "name", resourceTypeAndName, "name"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "description", resourceTypeAndName, "description"),
resource.TestCheckResourceAttr(resourceTypeAndName, "custom_dlp_engine", strconv.FormatBool(variable.DLPCustomEngine)),
),
},
},
})
}

func testAccDataSourceDLPEnginesCheck(name string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(name, "name"),
)
}

var testAccCheckDataSourceDLPEnginesConfig_basic = `
data "zia_dlp_engines" "credit_cards"{
name = "Credit Cards"
}
data "zia_dlp_engines" "canada_ssn"{
name = "Canada-SSN"
}
data "zia_dlp_engines" "us_ssn"{
name = "Social Security Numbers"
}
data "zia_dlp_engines" "glba"{
name = "GLBA"
}
data "zia_dlp_engines" "hipaa"{
name = "HIPAA"
}
data "zia_dlp_engines" "pci"{
name = "PCI"
}
`
2 changes: 2 additions & 0 deletions zia/data_source_zia_firewall_filtering_rules_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zia

/*
import (
"strconv"
"testing"
Expand Down Expand Up @@ -39,3 +40,4 @@ func TestAccDataSourceFirewallFilteringRule_Basic(t *testing.T) {
},
})
}
*/
1 change: 1 addition & 0 deletions zia/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Provider() *schema.Provider {
ResourcesMap: map[string]*schema.Resource{
"zia_admin_users": resourceAdminUsers(),
"zia_dlp_dictionaries": resourceDLPDictionaries(),
"zia_dlp_engines": resourceDLPEngines(),
"zia_dlp_notification_templates": resourceDLPNotificationTemplates(),
"zia_dlp_web_rules": resourceDlpWebRules(),
"zia_firewall_filtering_rule": resourceFirewallFilteringRules(),
Expand Down
Loading

0 comments on commit 8372f59

Please sign in to comment.