diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90105595..af24fcb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_advanced_malware_protection` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_decryption` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_profile` to `20.15.0`
+- Add `sdwan_policy_object_security_zone` resource and data source
## 0.9.0
diff --git a/docs/data-sources/policy_object_security_zone.md b/docs/data-sources/policy_object_security_zone.md
new file mode 100644
index 00000000..06345f9a
--- /dev/null
+++ b/docs/data-sources/policy_object_security_zone.md
@@ -0,0 +1,43 @@
+---
+# generated by https://github.com/hashicorp/terraform-plugin-docs
+page_title: "sdwan_policy_object_security_zone Data Source - terraform-provider-sdwan"
+subcategory: "Policy Objects"
+description: |-
+ This data source can read the Policy Object Security Zone Policy_object.
+---
+
+# sdwan_policy_object_security_zone (Data Source)
+
+This data source can read the Policy Object Security Zone Policy_object.
+
+## Example Usage
+
+```terraform
+data "sdwan_policy_object_security_zone" "example" {
+ id = "f6b2c44c-693c-4763-b010-895aa3d236bd"
+ feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
+}
+```
+
+
+## Schema
+
+### Required
+
+- `feature_profile_id` (String) Feature Profile ID
+- `id` (String) The id of the Policy_object
+
+### Read-Only
+
+- `description` (String) The description of the Policy_object
+- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries))
+- `name` (String) The name of the Policy_object
+- `version` (Number) The version of the Policy_object
+
+
+### Nested Schema for `entries`
+
+Read-Only:
+
+- `interface` (String)
+- `vpn` (String)
diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md
index ac95ce5d..bc246044 100644
--- a/docs/guides/changelog.md
+++ b/docs/guides/changelog.md
@@ -36,6 +36,7 @@ description: |-
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_advanced_malware_protection` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_decryption` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_profile` to `20.15.0`
+- Add `sdwan_policy_object_security_zone` resource and data source
## 0.9.0
diff --git a/docs/resources/policy_object_security_zone.md b/docs/resources/policy_object_security_zone.md
new file mode 100644
index 00000000..b4b3e37d
--- /dev/null
+++ b/docs/resources/policy_object_security_zone.md
@@ -0,0 +1,65 @@
+---
+# generated by https://github.com/hashicorp/terraform-plugin-docs
+page_title: "sdwan_policy_object_security_zone Resource - terraform-provider-sdwan"
+subcategory: "Policy Objects"
+description: |-
+ This resource can manage a Policy Object Security Zone Policy_object.
+ Minimum SD-WAN Manager version: 20.15.0
+---
+
+# sdwan_policy_object_security_zone (Resource)
+
+This resource can manage a Policy Object Security Zone Policy_object.
+ - Minimum SD-WAN Manager version: `20.15.0`
+
+## Example Usage
+
+```terraform
+resource "sdwan_policy_object_security_zone" "example" {
+ name = "Example"
+ description = "My Example"
+ feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
+ entries = [
+ {
+ vpn = "Guest"
+ }
+ ]
+}
+```
+
+
+## Schema
+
+### Required
+
+- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries))
+- `feature_profile_id` (String) Feature Profile ID
+- `name` (String) The name of the Policy_object
+
+### Optional
+
+- `description` (String) The description of the Policy_object
+
+### Read-Only
+
+- `id` (String) The id of the Policy_object
+- `version` (Number) The version of the Policy_object
+
+
+### Nested Schema for `entries`
+
+Optional:
+
+- `interface` (String)
+- `vpn` (String)
+
+## Import
+
+Import is supported using the following syntax:
+
+The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
+
+```shell
+# Expected import identifier with the format: "policy_object_security_zone_id,feature_profile_id"
+terraform import sdwan_policy_object_security_zone.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
+```
diff --git a/examples/data-sources/sdwan_policy_object_security_zone/data-source.tf b/examples/data-sources/sdwan_policy_object_security_zone/data-source.tf
new file mode 100644
index 00000000..bbec1be9
--- /dev/null
+++ b/examples/data-sources/sdwan_policy_object_security_zone/data-source.tf
@@ -0,0 +1,4 @@
+data "sdwan_policy_object_security_zone" "example" {
+ id = "f6b2c44c-693c-4763-b010-895aa3d236bd"
+ feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
+}
diff --git a/examples/resources/sdwan_policy_object_security_zone/import.sh b/examples/resources/sdwan_policy_object_security_zone/import.sh
new file mode 100644
index 00000000..de802139
--- /dev/null
+++ b/examples/resources/sdwan_policy_object_security_zone/import.sh
@@ -0,0 +1,2 @@
+# Expected import identifier with the format: "policy_object_security_zone_id,feature_profile_id"
+terraform import sdwan_policy_object_security_zone.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
diff --git a/examples/resources/sdwan_policy_object_security_zone/resource.tf b/examples/resources/sdwan_policy_object_security_zone/resource.tf
new file mode 100644
index 00000000..d01cb1eb
--- /dev/null
+++ b/examples/resources/sdwan_policy_object_security_zone/resource.tf
@@ -0,0 +1,10 @@
+resource "sdwan_policy_object_security_zone" "example" {
+ name = "Example"
+ description = "My Example"
+ feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac"
+ entries = [
+ {
+ vpn = "Guest"
+ }
+ ]
+}
diff --git a/gen/definitions/profile_parcels/policy_object_security_zone.yaml b/gen/definitions/profile_parcels/policy_object_security_zone.yaml
new file mode 100644
index 00000000..75f163c1
--- /dev/null
+++ b/gen/definitions/profile_parcels/policy_object_security_zone.yaml
@@ -0,0 +1,37 @@
+---
+name: Policy Object Security Zone
+rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-zone
+minimum_version: 20.15.0
+test_tags: [SDWAN_2015]
+skip_minimum_test: true
+parcel_type: policy_object
+full_update: true
+attributes:
+ - tf_name: feature_profile_id
+ reference: true
+ type: String
+ mandatory: true
+ description: Feature Profile ID
+ example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac
+ test_value: sdwan_policy_object_feature_profile.test.id
+ - model_name: entries
+ mandatory: true
+ type: List
+ min_list: 1
+ description: List of entries
+ attributes:
+ - model_name: vpn
+ type: String
+ tf_name: vpn
+ example: Guest
+ - model_name: interface
+ exclude_test: true
+ type: String
+ tf_name: interface
+ example: GigabitEthernet1
+
+test_prerequisites: |
+ resource "sdwan_policy_object_feature_profile" "test" {
+ name = "POLICY_OBJECT_FP_1"
+ description = "My policy object feature profile 1"
+ }
\ No newline at end of file
diff --git a/gen/models/profile_parcels/policy_object_security_zone.json b/gen/models/profile_parcels/policy_object_security_zone.json
index 5e10984b..a215391f 100644
--- a/gen/models/profile_parcels/policy_object_security_zone.json
+++ b/gen/models/profile_parcels/policy_object_security_zone.json
@@ -1,145 +1,152 @@
{
"request": {
- "$schema": "http://json-schema.org/draft/2019-09/schema",
- "$id": "https://cisco.com/schema/profileparcel/sdwan/policy-object/security-zone/post/request_schema.json",
- "title": "security-zone Parcel Schema",
- "description": "security-zone profile parcel schema for POST request",
- "type": "object",
- "properties": {
- "name": {
- "type": "string",
- "minLength": 1,
- "maxLength": 32,
- "pattern": "(?i)^(?:(?!\\b(untrusted|self|default|service)\\b).)*$"
- },
- "description": {
- "type": "string"
- },
- "data": {
- "type": "object",
- "properties": {
- "entries": {
- "minItems": 1,
- "oneOf": [
- {
- "type": "array",
- "minItems": 1,
- "uniqueItems": true,
- "items": {
- "type": "object",
- "properties": {
- "vpn": {
- "type": "object",
- "properties": {
- "optionType": {
- "type": "string",
- "enum": [
- "global"
- ]
- },
- "value": {
- "type": "string"
- }
- },
- "required": [
- "optionType",
- "value"
- ],
- "additionalProperties": false
- }
- },
- "required": [
- "vpn"
- ],
- "additionalProperties": false
- }
- },
- {
- "type": "array",
- "minItems": 1,
- "uniqueItems": true,
- "items": {
- "type": "object",
- "properties": {
- "interface": {
- "type": "object",
- "properties": {
- "optionType": {
- "type": "string",
- "enum": [
- "global"
- ]
- },
- "value": {
- "type": "string"
- }
- },
- "required": [
- "optionType",
- "value"
- ],
- "additionalProperties": false
- }
- },
- "required": [
- "interface"
- ],
- "additionalProperties": false
- }
- }
- ]
- }
- },
- "required": [
- "entries"
- ],
- "additionalProperties": false
- },
- "documentation": {
- "description": "This is the documentation for POST request schema for security-zone profile parcel",
- "details-1": "variable name should be present with given format as specified in schema if optionType value is variable",
- "details-2": "variable name should not be present if optionType value is NOT variable",
- "details-3": "when option Type is global, value should be present with given format/restrictions as specified in schema",
- "details-4": "when option Type is default, value should be present with given default value as specified in schema",
- "examples": [
- {
- "data": {
- "entries": [
- {
- "vpn": {
- "optionType": "global",
- "value": "Guest"
- }
- }
+ "$schema": "http://json-schema.org/draft/2019-09/schema",
+ "$id": "https://cisco.com/schema/profileparcel/sdwan/policy-object/security-zone/post/request_schema.json",
+ "title": "security-zone Parcel Schema",
+ "description": "security-zone profile parcel schema for POST request",
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "minLength": 1,
+ "maxLength": 32,
+ "pattern": "(?i)^(?:(?!\\b(untrusted|self|default|service)\\b).)*$"
+ },
+ "description": {
+ "type": "string"
+ },
+ "data": {
+ "type": "object",
+ "properties": {
+ "entries": {
+ "minItems": 1,
+ "oneOf": [
+ {
+ "type": "array",
+ "minItems": 1,
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "vpn": {
+ "type": "object",
+ "properties": {
+ "optionType": {
+ "type": "string",
+ "enum": [
+ "global"
]
+ },
+ "value": {
+ "type": "string"
+ }
},
- "name": "zoneList1"
+ "required": [
+ "optionType",
+ "value"
+ ],
+ "additionalProperties": false
+ }
},
- {
- "data": {
- "entries": [
- {
- "interface": {
- "optionType": "global",
- "value": "GigabitEthernet1"
- }
- }
+ "required": [
+ "vpn"
+ ],
+ "additionalProperties": false
+ }
+ },
+ {
+ "type": "array",
+ "minItems": 1,
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "interface": {
+ "type": "object",
+ "properties": {
+ "optionType": {
+ "type": "string",
+ "enum": [
+ "global"
]
+ },
+ "value": {
+ "type": "string",
+ "pattern": "^(ATM|ATM-ACR|AppGigabitEthernet|AppNav-Compress|AppNav-UnCompress|Async|BD-VIF|BDI|CEM|CEM-ACR|Cellular|Dialer|Embedded-Service-Engine|Ethernet|Ethernet-Internal|FastEthernet|FiftyGigabitEthernet|FiveGigabitEthernet|FortyGigabitEthernet|FourHundredGigE|GMPLS|GigabitEthernet|Group-Async|HundredGigE|L2LISP|LISP|Loopback|MFR|Multilink|Port-channel|SM|Serial|Service-Engine|TenGigabitEthernet|Tunnel|TwentyFiveGigE|TwentyFiveGigabitEthernet|TwoGigabitEthernet|TwoHundredGigE|Vif|Virtual-PPP|Virtual-Template|VirtualPortGroup|Vlan|Wlan-GigabitEthernet|nat64|nat66|ntp|nve|ospfv3|overlay|pseudowire|ucse|vasileft|vasiright|vmi)(\\w+)((\\/\\d+)*(\\.\\d+)?)?$",
+ "minLength": 3,
+ "maxLength": 32
+ }
},
- "name": "zoneList2"
+ "required": [
+ "optionType",
+ "value"
+ ],
+ "additionalProperties": false
+ }
+ },
+ "required": [
+ "interface"
+ ],
+ "additionalProperties": false
+ }
+ }
+ ]
+ }
+ },
+ "required": [
+ "entries"
+ ],
+ "additionalProperties": false
+ },
+ "documentation": {
+ "description": "This is the documentation for POST request schema for security-zone profile parcel",
+ "details-1": "variable name should be present with given format as specified in schema if optionType value is variable",
+ "details-2": "variable name should not be present if optionType value is NOT variable",
+ "details-3": "when option Type is global, value should be present with given format/restrictions as specified in schema",
+ "details-4": "when option Type is default, value should be present with given default value as specified in schema",
+ "examples": [
+ {
+ "data": {
+ "entries": [
+ {
+ "vpn": {
+ "optionType": "global",
+ "value": "Guest"
}
+ }
]
+ },
+ "name": "SecurityZoneList1"
+ },
+ {
+ "data": {
+ "entries": [
+ {
+ "interface": {
+ "optionType": "global",
+ "value": "GigabitEthernet1"
+ }
+ }
+ ]
+ },
+ "name": "SecurityZoneList2"
}
+ ]
},
+ "metadata": {
+ "minVManageVersion": "20.15.1"
+ }
+ },
+ "required": [
+ "data",
+ "name"
+ ],
+ "not": {
"required": [
- "data",
- "name"
- ],
- "not": {
- "required": [
- "documentation"
- ]
- },
- "additionalProperties": false
+ "documentation",
+ "metadata"
+ ]
+ },
+ "additionalProperties": false
}
}
\ No newline at end of file
diff --git a/internal/provider/data_source_sdwan_policy_object_security_zone.go b/internal/provider/data_source_sdwan_policy_object_security_zone.go
new file mode 100644
index 00000000..98fd09c2
--- /dev/null
+++ b/internal/provider/data_source_sdwan_policy_object_security_zone.go
@@ -0,0 +1,137 @@
+// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
+// All rights reserved.
+//
+// Licensed under the Mozilla Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://mozilla.org/MPL/2.0/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// SPDX-License-Identifier: MPL-2.0
+
+package provider
+
+// Section below is generated&owned by "gen/generator.go". //template:begin imports
+import (
+ "context"
+ "fmt"
+ "net/url"
+
+ "github.com/hashicorp/terraform-plugin-framework/datasource"
+ "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
+ "github.com/hashicorp/terraform-plugin-log/tflog"
+ "github.com/netascode/go-sdwan"
+)
+
+// End of section. //template:end imports
+
+// Section below is generated&owned by "gen/generator.go". //template:begin model
+
+// Ensure the implementation satisfies the expected interfaces.
+var (
+ _ datasource.DataSource = &PolicyObjectSecurityZoneProfileParcelDataSource{}
+ _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityZoneProfileParcelDataSource{}
+)
+
+func NewPolicyObjectSecurityZoneProfileParcelDataSource() datasource.DataSource {
+ return &PolicyObjectSecurityZoneProfileParcelDataSource{}
+}
+
+type PolicyObjectSecurityZoneProfileParcelDataSource struct {
+ client *sdwan.Client
+}
+
+func (d *PolicyObjectSecurityZoneProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
+ resp.TypeName = req.ProviderTypeName + "_policy_object_security_zone"
+}
+
+func (d *PolicyObjectSecurityZoneProfileParcelDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
+ resp.Schema = schema.Schema{
+ // This description is used by the documentation generator and the language server.
+ MarkdownDescription: "This data source can read the Policy Object Security Zone Policy_object.",
+
+ Attributes: map[string]schema.Attribute{
+ "id": schema.StringAttribute{
+ MarkdownDescription: "The id of the Policy_object",
+ Required: true,
+ },
+ "version": schema.Int64Attribute{
+ MarkdownDescription: "The version of the Policy_object",
+ Computed: true,
+ },
+ "name": schema.StringAttribute{
+ MarkdownDescription: "The name of the Policy_object",
+ Computed: true,
+ },
+ "description": schema.StringAttribute{
+ MarkdownDescription: "The description of the Policy_object",
+ Computed: true,
+ },
+ "feature_profile_id": schema.StringAttribute{
+ MarkdownDescription: "Feature Profile ID",
+ Required: true,
+ },
+ "entries": schema.ListNestedAttribute{
+ MarkdownDescription: "",
+ Computed: true,
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "vpn": schema.StringAttribute{
+ MarkdownDescription: "",
+ Computed: true,
+ },
+ "interface": schema.StringAttribute{
+ MarkdownDescription: "",
+ Computed: true,
+ },
+ },
+ },
+ },
+ },
+ }
+}
+
+func (d *PolicyObjectSecurityZoneProfileParcelDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
+ if req.ProviderData == nil {
+ return
+ }
+
+ d.client = req.ProviderData.(*SdwanProviderData).Client
+}
+
+// End of section. //template:end model
+
+// Section below is generated&owned by "gen/generator.go". //template:begin read
+func (d *PolicyObjectSecurityZoneProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
+ var config PolicyObjectSecurityZone
+
+ // Read config
+ diags := req.Config.Get(ctx, &config)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
+
+ res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString()))
+ if err != nil {
+ resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
+ return
+ }
+
+ config.fromBody(ctx, res)
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString()))
+
+ diags = resp.State.Set(ctx, &config)
+ resp.Diagnostics.Append(diags...)
+}
+
+// End of section. //template:end read
diff --git a/internal/provider/data_source_sdwan_policy_object_security_zone_test.go b/internal/provider/data_source_sdwan_policy_object_security_zone_test.go
new file mode 100644
index 00000000..f5b95317
--- /dev/null
+++ b/internal/provider/data_source_sdwan_policy_object_security_zone_test.go
@@ -0,0 +1,81 @@
+// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
+// All rights reserved.
+//
+// Licensed under the Mozilla Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://mozilla.org/MPL/2.0/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// SPDX-License-Identifier: MPL-2.0
+
+package provider
+
+// Section below is generated&owned by "gen/generator.go". //template:begin imports
+import (
+ "os"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-testing/helper/resource"
+)
+
+// End of section. //template:end imports
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource
+func TestAccDataSourceSdwanPolicyObjectSecurityZoneProfileParcel(t *testing.T) {
+ if os.Getenv("SDWAN_2015") == "" {
+ t.Skip("skipping test, set environment variable SDWAN_2015")
+ }
+ var checks []resource.TestCheckFunc
+ checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_zone.test", "entries.0.vpn", "Guest"))
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccDataSourceSdwanPolicyObjectSecurityZonePrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityZoneProfileParcelConfig(),
+ Check: resource.ComposeTestCheckFunc(checks...),
+ },
+ },
+ })
+}
+
+// End of section. //template:end testAccDataSource
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites
+const testAccDataSourceSdwanPolicyObjectSecurityZonePrerequisitesProfileParcelConfig = `
+resource "sdwan_policy_object_feature_profile" "test" {
+ name = "POLICY_OBJECT_FP_1"
+ description = "My policy object feature profile 1"
+}
+`
+
+// End of section. //template:end testPrerequisites
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig
+func testAccDataSourceSdwanPolicyObjectSecurityZoneProfileParcelConfig() string {
+ config := `resource "sdwan_policy_object_security_zone" "test" {` + "\n"
+ config += ` name = "TF_TEST"` + "\n"
+ config += ` description = "Terraform integration test"` + "\n"
+ config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n"
+ config += ` entries = [{` + "\n"
+ config += ` vpn = "Guest"` + "\n"
+ config += ` }]` + "\n"
+ config += `}` + "\n"
+
+ config += `
+ data "sdwan_policy_object_security_zone" "test" {
+ id = sdwan_policy_object_security_zone.test.id
+ feature_profile_id = sdwan_policy_object_feature_profile.test.id
+ }
+ `
+ return config
+}
+
+// End of section. //template:end testAccDataSourceConfig
diff --git a/internal/provider/model_sdwan_policy_object_security_zone.go b/internal/provider/model_sdwan_policy_object_security_zone.go
new file mode 100644
index 00000000..aa3b89f1
--- /dev/null
+++ b/internal/provider/model_sdwan_policy_object_security_zone.go
@@ -0,0 +1,190 @@
+// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
+// All rights reserved.
+//
+// Licensed under the Mozilla Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://mozilla.org/MPL/2.0/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// SPDX-License-Identifier: MPL-2.0
+
+package provider
+
+// Section below is generated&owned by "gen/generator.go". //template:begin imports
+import (
+ "context"
+ "fmt"
+ "net/url"
+
+ "github.com/hashicorp/terraform-plugin-framework/types"
+ "github.com/tidwall/gjson"
+ "github.com/tidwall/sjson"
+)
+
+// End of section. //template:end imports
+
+// Section below is generated&owned by "gen/generator.go". //template:begin types
+type PolicyObjectSecurityZone struct {
+ Id types.String `tfsdk:"id"`
+ Version types.Int64 `tfsdk:"version"`
+ Name types.String `tfsdk:"name"`
+ Description types.String `tfsdk:"description"`
+ FeatureProfileId types.String `tfsdk:"feature_profile_id"`
+ Entries []PolicyObjectSecurityZoneEntries `tfsdk:"entries"`
+}
+
+type PolicyObjectSecurityZoneEntries struct {
+ Vpn types.String `tfsdk:"vpn"`
+ Interface types.String `tfsdk:"interface"`
+}
+
+// End of section. //template:end types
+
+// Section below is generated&owned by "gen/generator.go". //template:begin getModel
+func (data PolicyObjectSecurityZone) getModel() string {
+ return "policy_object_security_zone"
+}
+
+// End of section. //template:end getModel
+
+// Section below is generated&owned by "gen/generator.go". //template:begin getPath
+func (data PolicyObjectSecurityZone) getPath() string {
+ return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-zone", url.QueryEscape(data.FeatureProfileId.ValueString()))
+}
+
+// End of section. //template:end getPath
+
+// Section below is generated&owned by "gen/generator.go". //template:begin toBody
+func (data PolicyObjectSecurityZone) toBody(ctx context.Context) string {
+ body := ""
+ body, _ = sjson.Set(body, "name", data.Name.ValueString())
+ body, _ = sjson.Set(body, "description", data.Description.ValueString())
+ path := "data."
+ if true {
+
+ for _, item := range data.Entries {
+ itemBody := ""
+ if !item.Vpn.IsNull() {
+ if true {
+ itemBody, _ = sjson.Set(itemBody, "vpn.optionType", "global")
+ itemBody, _ = sjson.Set(itemBody, "vpn.value", item.Vpn.ValueString())
+ }
+ }
+ if !item.Interface.IsNull() {
+ if true {
+ itemBody, _ = sjson.Set(itemBody, "interface.optionType", "global")
+ itemBody, _ = sjson.Set(itemBody, "interface.value", item.Interface.ValueString())
+ }
+ }
+ body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody)
+ }
+ }
+ return body
+}
+
+// End of section. //template:end toBody
+
+// Section below is generated&owned by "gen/generator.go". //template:begin fromBody
+func (data *PolicyObjectSecurityZone) fromBody(ctx context.Context, res gjson.Result) {
+ data.Name = types.StringValue(res.Get("payload.name").String())
+ if value := res.Get("payload.description"); value.Exists() && value.String() != "" {
+ data.Description = types.StringValue(value.String())
+ } else {
+ data.Description = types.StringNull()
+ }
+ path := "payload.data."
+ if value := res.Get(path + "entries"); value.Exists() && len(value.Array()) > 0 {
+ data.Entries = make([]PolicyObjectSecurityZoneEntries, 0)
+ value.ForEach(func(k, v gjson.Result) bool {
+ item := PolicyObjectSecurityZoneEntries{}
+ item.Vpn = types.StringNull()
+
+ if t := v.Get("vpn.optionType"); t.Exists() {
+ va := v.Get("vpn.value")
+ if t.String() == "global" {
+ item.Vpn = types.StringValue(va.String())
+ }
+ }
+ item.Interface = types.StringNull()
+
+ if t := v.Get("interface.optionType"); t.Exists() {
+ va := v.Get("interface.value")
+ if t.String() == "global" {
+ item.Interface = types.StringValue(va.String())
+ }
+ }
+ data.Entries = append(data.Entries, item)
+ return true
+ })
+ }
+}
+
+// End of section. //template:end fromBody
+
+// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody
+func (data *PolicyObjectSecurityZone) updateFromBody(ctx context.Context, res gjson.Result) {
+ data.Name = types.StringValue(res.Get("payload.name").String())
+ if value := res.Get("payload.description"); value.Exists() && value.String() != "" {
+ data.Description = types.StringValue(value.String())
+ } else {
+ data.Description = types.StringNull()
+ }
+ path := "payload.data."
+ for i := range data.Entries {
+ keys := [...]string{"vpn", "interface"}
+ keyValues := [...]string{data.Entries[i].Vpn.ValueString(), data.Entries[i].Interface.ValueString()}
+ keyValuesVariables := [...]string{"", ""}
+
+ var r gjson.Result
+ res.Get(path + "entries").ForEach(
+ func(_, v gjson.Result) bool {
+ found := false
+ for ik := range keys {
+ tt := v.Get(keys[ik] + ".optionType")
+ vv := v.Get(keys[ik] + ".value")
+ if tt.Exists() && vv.Exists() {
+ if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) {
+ found = true
+ continue
+ } else if tt.String() == "default" {
+ continue
+ }
+ found = false
+ break
+ }
+ continue
+ }
+ if found {
+ r = v
+ return false
+ }
+ return true
+ },
+ )
+ data.Entries[i].Vpn = types.StringNull()
+
+ if t := r.Get("vpn.optionType"); t.Exists() {
+ va := r.Get("vpn.value")
+ if t.String() == "global" {
+ data.Entries[i].Vpn = types.StringValue(va.String())
+ }
+ }
+ data.Entries[i].Interface = types.StringNull()
+
+ if t := r.Get("interface.optionType"); t.Exists() {
+ va := r.Get("interface.value")
+ if t.String() == "global" {
+ data.Entries[i].Interface = types.StringValue(va.String())
+ }
+ }
+ }
+}
+
+// End of section. //template:end updateFromBody
diff --git a/internal/provider/provider.go b/internal/provider/provider.go
index 619235c6..ae806947 100644
--- a/internal/provider/provider.go
+++ b/internal/provider/provider.go
@@ -353,6 +353,7 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc
NewPolicyObjectSecurityScalableGroupTagListProfileParcelResource,
NewPolicyObjectSecurityURLAllowListProfileParcelResource,
NewPolicyObjectSecurityURLBlockListProfileParcelResource,
+ NewPolicyObjectSecurityZoneProfileParcelResource,
NewPolicyObjectSLAClassListProfileParcelResource,
NewPolicyObjectStandardCommunityListProfileParcelResource,
NewPolicyObjectTLOCListProfileParcelResource,
@@ -600,6 +601,7 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat
NewPolicyObjectSecurityScalableGroupTagListProfileParcelDataSource,
NewPolicyObjectSecurityURLAllowListProfileParcelDataSource,
NewPolicyObjectSecurityURLBlockListProfileParcelDataSource,
+ NewPolicyObjectSecurityZoneProfileParcelDataSource,
NewPolicyObjectSLAClassListProfileParcelDataSource,
NewPolicyObjectStandardCommunityListProfileParcelDataSource,
NewPolicyObjectTLOCListProfileParcelDataSource,
diff --git a/internal/provider/resource_sdwan_policy_object_security_zone.go b/internal/provider/resource_sdwan_policy_object_security_zone.go
new file mode 100644
index 00000000..86027d97
--- /dev/null
+++ b/internal/provider/resource_sdwan_policy_object_security_zone.go
@@ -0,0 +1,274 @@
+// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
+// All rights reserved.
+//
+// Licensed under the Mozilla Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://mozilla.org/MPL/2.0/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// SPDX-License-Identifier: MPL-2.0
+
+package provider
+
+// Section below is generated&owned by "gen/generator.go". //template:begin imports
+import (
+ "context"
+ "fmt"
+ "net/url"
+ "strings"
+ "sync"
+
+ "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers"
+ "github.com/hashicorp/terraform-plugin-framework/path"
+ "github.com/hashicorp/terraform-plugin-framework/resource"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
+ "github.com/hashicorp/terraform-plugin-framework/types"
+ "github.com/hashicorp/terraform-plugin-log/tflog"
+ "github.com/netascode/go-sdwan"
+)
+
+// End of section. //template:end imports
+
+// Section below is generated&owned by "gen/generator.go". //template:begin model
+
+// Ensure provider defined types fully satisfy framework interfaces
+var _ resource.Resource = &PolicyObjectSecurityZoneProfileParcelResource{}
+var _ resource.ResourceWithImportState = &PolicyObjectSecurityZoneProfileParcelResource{}
+
+func NewPolicyObjectSecurityZoneProfileParcelResource() resource.Resource {
+ return &PolicyObjectSecurityZoneProfileParcelResource{}
+}
+
+type PolicyObjectSecurityZoneProfileParcelResource struct {
+ client *sdwan.Client
+ updateMutex *sync.Mutex
+}
+
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
+ resp.TypeName = req.ProviderTypeName + "_policy_object_security_zone"
+}
+
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
+ resp.Schema = schema.Schema{
+ // This description is used by the documentation generator and the language server.
+ MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Policy Object Security Zone Policy_object.").AddMinimumVersionDescription("20.15.0").String,
+
+ Attributes: map[string]schema.Attribute{
+ "id": schema.StringAttribute{
+ MarkdownDescription: "The id of the Policy_object",
+ Computed: true,
+ PlanModifiers: []planmodifier.String{
+ stringplanmodifier.UseStateForUnknown(),
+ },
+ },
+ "version": schema.Int64Attribute{
+ MarkdownDescription: "The version of the Policy_object",
+ Computed: true,
+ },
+ "name": schema.StringAttribute{
+ MarkdownDescription: "The name of the Policy_object",
+ Required: true,
+ },
+ "description": schema.StringAttribute{
+ MarkdownDescription: "The description of the Policy_object",
+ Optional: true,
+ },
+ "feature_profile_id": schema.StringAttribute{
+ MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String,
+ Required: true,
+ },
+ "entries": schema.ListNestedAttribute{
+ MarkdownDescription: helpers.NewAttributeDescription("").String,
+ Required: true,
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "vpn": schema.StringAttribute{
+ MarkdownDescription: helpers.NewAttributeDescription("").String,
+ Optional: true,
+ },
+ "interface": schema.StringAttribute{
+ MarkdownDescription: helpers.NewAttributeDescription("").String,
+ Optional: true,
+ },
+ },
+ },
+ },
+ },
+ }
+}
+
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
+ if req.ProviderData == nil {
+ return
+ }
+
+ r.client = req.ProviderData.(*SdwanProviderData).Client
+ r.updateMutex = req.ProviderData.(*SdwanProviderData).UpdateMutex
+}
+
+// End of section. //template:end model
+
+// Section below is generated&owned by "gen/generator.go". //template:begin create
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
+ var plan PolicyObjectSecurityZone
+
+ // Read plan
+ diags := req.Plan.Get(ctx, &plan)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString()))
+
+ // Create object
+ body := plan.toBody(ctx)
+
+ res, err := r.client.Post(plan.getPath(), body)
+ if err != nil {
+ resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String()))
+ return
+ }
+
+ plan.Id = types.StringValue(res.Get("parcelId").String())
+ plan.Version = types.Int64Value(0)
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Name.ValueString()))
+
+ diags = resp.State.Set(ctx, &plan)
+ resp.Diagnostics.Append(diags...)
+
+ helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
+}
+
+// End of section. //template:end create
+
+// Section below is generated&owned by "gen/generator.go". //template:begin read
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
+ var state PolicyObjectSecurityZone
+
+ // Read state
+ diags := req.State.Get(ctx, &state)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String()))
+
+ res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString()))
+ if res.Get("error.message").String() == "Invalid feature Id" {
+ resp.State.RemoveResource(ctx)
+ return
+ } else if err != nil {
+ resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
+ return
+ }
+
+ // If every attribute is set to null we are dealing with an import operation and therefore reading all attributes
+ state.fromBody(ctx, res)
+ if state.Version.IsNull() {
+ state.Version = types.Int64Value(0)
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Name.ValueString()))
+
+ diags = resp.State.Set(ctx, &state)
+ resp.Diagnostics.Append(diags...)
+
+ helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
+}
+
+// End of section. //template:end read
+
+// Section below is generated&owned by "gen/generator.go". //template:begin update
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
+ var plan, state PolicyObjectSecurityZone
+
+ // Read plan
+ diags := req.Plan.Get(ctx, &plan)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ // Read state
+ diags = req.State.Get(ctx, &state)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString()))
+
+ body := plan.toBody(ctx)
+ res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body)
+ if err != nil {
+ resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String()))
+ return
+ }
+
+ plan.Version = types.Int64Value(state.Version.ValueInt64() + 1)
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Name.ValueString()))
+
+ diags = resp.State.Set(ctx, &plan)
+ resp.Diagnostics.Append(diags...)
+}
+
+// End of section. //template:end update
+
+// Section below is generated&owned by "gen/generator.go". //template:begin delete
+func (r *PolicyObjectSecurityZoneProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
+ var state PolicyObjectSecurityZone
+
+ // Read state
+ diags := req.State.Get(ctx, &state)
+ resp.Diagnostics.Append(diags...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Name.ValueString()))
+
+ res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString()))
+ if err != nil && res.Get("error.message").String() != "Invalid Template Id" {
+ resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String()))
+ return
+ }
+
+ tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Name.ValueString()))
+
+ resp.State.RemoveResource(ctx)
+}
+
+// End of section. //template:end delete
+
+// Section below is generated&owned by "gen/generator.go". //template:begin import
+func (r *PolicyObjectSecurityZoneProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
+ count := 1
+ parts := strings.SplitN(req.ID, ",", (count + 1))
+
+ pattern := "policy_object_security_zone_id" + ",feature_profile_id"
+ if len(parts) != (count + 1) {
+ resp.Diagnostics.AddError(
+ "Unexpected Import Identifier", fmt.Sprintf("Expected import identifier with the format: %s. Got: %q", pattern, req.ID),
+ )
+ return
+ }
+
+ resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), parts[0])...)
+ resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("feature_profile_id"), parts[1])...)
+
+ helpers.SetFlagImporting(ctx, true, resp.Private, &resp.Diagnostics)
+}
+
+// End of section. //template:end import
diff --git a/internal/provider/resource_sdwan_policy_object_security_zone_test.go b/internal/provider/resource_sdwan_policy_object_security_zone_test.go
new file mode 100644
index 00000000..64d99630
--- /dev/null
+++ b/internal/provider/resource_sdwan_policy_object_security_zone_test.go
@@ -0,0 +1,79 @@
+// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
+// All rights reserved.
+//
+// Licensed under the Mozilla Public License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://mozilla.org/MPL/2.0/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// SPDX-License-Identifier: MPL-2.0
+
+package provider
+
+// Section below is generated&owned by "gen/generator.go". //template:begin imports
+import (
+ "os"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-testing/helper/resource"
+)
+
+// End of section. //template:end imports
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testAcc
+func TestAccSdwanPolicyObjectSecurityZoneProfileParcel(t *testing.T) {
+ if os.Getenv("SDWAN_2015") == "" {
+ t.Skip("skipping test, set environment variable SDWAN_2015")
+ }
+ var checks []resource.TestCheckFunc
+ checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_zone.test", "entries.0.vpn", "Guest"))
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
+ Steps: []resource.TestStep{
+
+ {
+ Config: testAccSdwanPolicyObjectSecurityZonePrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityZoneProfileParcelConfig_all(),
+ Check: resource.ComposeTestCheckFunc(checks...),
+ },
+ },
+ })
+}
+
+// End of section. //template:end testAcc
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites
+const testAccSdwanPolicyObjectSecurityZonePrerequisitesProfileParcelConfig = `
+resource "sdwan_policy_object_feature_profile" "test" {
+ name = "POLICY_OBJECT_FP_1"
+ description = "My policy object feature profile 1"
+}
+`
+
+// End of section. //template:end testPrerequisites
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum
+
+// End of section. //template:end testAccConfigMinimum
+
+// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll
+func testAccSdwanPolicyObjectSecurityZoneProfileParcelConfig_all() string {
+ config := `resource "sdwan_policy_object_security_zone" "test" {` + "\n"
+ config += ` name = "TF_TEST_ALL"` + "\n"
+ config += ` description = "Terraform integration test"` + "\n"
+ config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n"
+ config += ` entries = [{` + "\n"
+ config += ` vpn = "Guest"` + "\n"
+ config += ` }]` + "\n"
+ config += `}` + "\n"
+ return config
+}
+
+// End of section. //template:end testAccConfigAll
diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl
index ac95ce5d..bc246044 100644
--- a/templates/guides/changelog.md.tmpl
+++ b/templates/guides/changelog.md.tmpl
@@ -36,6 +36,7 @@ description: |-
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_advanced_malware_protection` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_decryption` to `20.15.0`
- BREAKING CHANGE: Bump the minimum supported version of `sdwan_policy_object_unified_tls_ssl_profile` to `20.15.0`
+- Add `sdwan_policy_object_security_zone` resource and data source
## 0.9.0