Skip to content

Commit

Permalink
fix firewall filtering network service & service group resource and d…
Browse files Browse the repository at this point in the history
…ata source
  • Loading branch information
amazzalel-habib committed Oct 22, 2021
1 parent b0aa00f commit 38c269c
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 272 deletions.
70 changes: 37 additions & 33 deletions examples/zia_fw_filtering_network_services/main.tf
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
terraform {
required_providers {
zia = {
version = "1.0.0"
source = "zscaler.com/zia/zia"
}
required_providers {
zia = {
version = "1.0.0"
source = "zscaler.com/zia/zia"
}
}
}

provider "zia" {}

/*
resource "zia_firewall_filtering_network_service" "example"{
name = "example"
description = "example"
src_tcp_ports {
start = 123
end = 125
}
dest_tcp_ports {
start = 123
end = 125
}
src_udp_ports {
start = 123
end = 125
start = 126
end = 127
}
dest_udp_ports {
start = 123
end = 125
start = 126
end = 127
}
type = "CUSTOM"
resource "zia_firewall_filtering_network_service" "example" {
name = "example"
description = "example"
src_tcp_ports {
start = 123
end = 125
}
dest_tcp_ports {
start = 123
end = 125
}
src_udp_ports {
start = 123
end = 125
}
src_udp_ports {
start = 126
end = 127
}

dest_udp_ports {
start = 123
end = 125
}
dest_udp_ports {
start = 126
end = 127
}
type = "CUSTOM"
}
*/


data "zia_firewall_filtering_network_service" "example" {
name = "ZSCALER_PROXY_NW_SERVICES"
name = zia_firewall_filtering_network_service.example.name
}

output "zia_firewall_filtering_network_service" {
value = data.zia_firewall_filtering_network_service.example
value = data.zia_firewall_filtering_network_service.example
}
10 changes: 9 additions & 1 deletion examples/zia_fw_filtering_network_services_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ resource "zia_firewall_filtering_network_service_groups" "example"{
name = "example"
description = "example"
services {
id = 773995
id = [773995]
}
}

data "zia_firewall_filtering_network_service_groups" "example"{
name = zia_firewall_filtering_network_service_groups.example.name
}


output "zia_firewall_filtering_network_service_groups" {
value = data.zia_firewall_filtering_network_service_groups.example
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type Services struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
Tag string `json:"tag,omitempty"`
SrcTCPPorts []SrcTCPPorts `json:"srcTcpPorts,omitempty"`
DestTCPPorts []DestTCPPorts `json:"destTcpPorts,omitempty"`
SrcUDPPorts []SrcUDPPorts `json:"srcUdpPorts,omitempty"`
DestUDPPorts []DestUDPPorts `json:"destUdpPorts,omitempty"`
SrcTCPPorts []NetworkPorts `json:"srcTcpPorts,omitempty"`
DestTCPPorts []NetworkPorts `json:"destTcpPorts,omitempty"`
SrcUDPPorts []NetworkPorts `json:"srcUdpPorts,omitempty"`
DestUDPPorts []NetworkPorts `json:"destUdpPorts,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
IsNameL10nTag bool `json:"isNameL10nTag,omitempty"`
Expand Down
24 changes: 5 additions & 19 deletions gozscaler/firewallpolicies/networkservices/networkservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,15 @@ type NetworkServices struct {
ID int `json:"id"`
Name string `json:"name,omitempty"`
Tag string `json:"tag,omitempty"`
SrcTCPPorts []SrcTCPPorts `json:"srcTcpPorts,omitempty"`
DestTCPPorts []DestTCPPorts `json:"destTcpPorts,omitempty"`
SrcUDPPorts []SrcUDPPorts `json:"srcUdpPorts,omitempty"`
DestUDPPorts []DestUDPPorts `json:"destUdpPorts,omitempty"`
SrcTCPPorts []NetworkPorts `json:"srcTcpPorts,omitempty"`
DestTCPPorts []NetworkPorts `json:"destTcpPorts,omitempty"`
SrcUDPPorts []NetworkPorts `json:"srcUdpPorts,omitempty"`
DestUDPPorts []NetworkPorts `json:"destUdpPorts,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
IsNameL10nTag bool `json:"isNameL10nTag,omitempty"`
}
type SrcTCPPorts struct {
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
}

type DestTCPPorts struct {
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
}
type SrcUDPPorts struct {
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
}

type DestUDPPorts struct {
type NetworkPorts struct {
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
}
Expand Down
74 changes: 74 additions & 0 deletions zia/common.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package zia

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/willguibr/terraform-provider-zia/gozscaler/common"
"github.com/willguibr/terraform-provider-zia/gozscaler/firewallpolicies/networkservices"
)

func listIDsSchemaType(desc string) *schema.Schema {
Expand Down Expand Up @@ -125,3 +128,74 @@ func flattenLastModifiedBy(lastModifiedBy *common.IDNameExtensions) []interface{
}
return lastModified
}

func resourceNetworkPortsSchema(desc string) *schema.Schema {
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Description: desc,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start": {
Type: schema.TypeInt,
Optional: true,
},
"end": {
Type: schema.TypeInt,
Optional: true,
},
},
},
}
}

func dataNetworkPortsSchema(desc string) *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: desc,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start": {
Type: schema.TypeInt,
Computed: true,
},
"end": {
Type: schema.TypeInt,
Computed: true,
},
},
},
}
}

func flattenNetwordPorts(ports []networkservices.NetworkPorts) []interface{} {
portsObj := make([]interface{}, len(ports))
for i, val := range ports {
portsObj[i] = map[string]interface{}{
"start": val.Start,
"end": val.End,
}
}
return portsObj
}

func expandNetwrokPorts(d *schema.ResourceData, key string) []networkservices.NetworkPorts {
var ports []networkservices.NetworkPorts
if portsInterface, ok := d.GetOk(key); ok {
portSet, ok := portsInterface.(*schema.Set)
if !ok {
log.Printf("[ERROR] conversion failed, destUdpPortsInterface")
return ports
}
ports = make([]networkservices.NetworkPorts, len(portSet.List()))
for i, val := range portSet.List() {
portItem := val.(map[string]interface{})
ports[i] = networkservices.NetworkPorts{
Start: portItem["start"].(int),
End: portItem["end"].(int),
}
}
}
return ports
}
4 changes: 0 additions & 4 deletions zia/data_source_zia_fw_filtering_network_service_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ func flattenServices(service []networkservices.Services) []interface{} {
"name": val.Name,
"description": val.Description,
"is_name_l10n_tag": val.IsNameL10nTag,
"src_tcp_ports": flattenSrcTCPPorts(val.SrcTCPPorts),
"dest_tcp_ports": flattenDestTCPPorts(val.DestTCPPorts),
"src_udp_ports": flattenSrcUDPPorts(val.SrcUDPPorts),
"dest_udp_ports": flattenDestUDPPorts(val.DestUDPPorts),
}
}

Expand Down
Loading

0 comments on commit 38c269c

Please sign in to comment.