Skip to content

Commit

Permalink
Zia_#193_new_app_service_data_sources (zscaler#193)
Browse files Browse the repository at this point in the history
* (feat) Added application services data source
* Added application services AccTest
* fixed conflicts
  • Loading branch information
willguibr authored Mar 1, 2023
1 parent a37a28e commit 3fe7b1e
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/guides/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,4 @@ The following resources are supported:
- New Data Source: data_source_zia_url_filtering_rules 🆕
- New Data Source: data_source_zia_user_management_departments 🆕
- New Data Source: data_source_zia_user_management_groups 🆕
- New Data Source: data_source_zia_user_management_users 🆕
- New Data Source: data_source_zia_user_management_users 🆕
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,4 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
6 changes: 6 additions & 0 deletions zia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/zscaler/zscaler-sdk-go/zia/services/dlp_notification_templates"
"github.com/zscaler/zscaler-sdk-go/zia/services/dlp_web_rules"
"github.com/zscaler/zscaler-sdk-go/zia/services/dlpdictionaries"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservices"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservicesgroup"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/filteringrules"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/ipdestinationgroups"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/ipsourcegroups"
Expand Down Expand Up @@ -48,6 +50,8 @@ type Client struct {
ipsourcegroups *ipsourcegroups.Service
networkapplications *networkapplications.Service
networkservices *networkservices.Service
applicationservices *applicationservices.Service
applicationservicesgroup *applicationservicesgroup.Service
timewindow *timewindow.Service
urlcategories *urlcategories.Service
urlfilteringpolicies *urlfilteringpolicies.Service
Expand Down Expand Up @@ -95,6 +99,8 @@ func (c *Config) Client() (*Client, error) {
ipsourcegroups: ipsourcegroups.New(cli),
networkapplications: networkapplications.New(cli),
networkservices: networkservices.New(cli),
applicationservices: applicationservices.New(cli),
applicationservicesgroup: applicationservicesgroup.New(cli),
timewindow: timewindow.New(cli),
urlcategories: urlcategories.New(cli),
urlfilteringpolicies: urlfilteringpolicies.New(cli),
Expand Down
67 changes: 67 additions & 0 deletions zia/data_source_zia_application_services_group_lite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package zia

import (
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservicesgroup"
)

func dataSourceFWApplicationServicesGroupLite() *schema.Resource {
return &schema.Resource{
Read: dataSourceFWApplicationServicesGroupLiteRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique identifier for the application service.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The name of the application service.",
},
"name_l10n_tag": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}

func dataSourceFWApplicationServicesGroupLiteRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)

var resp *applicationservicesgroup.ApplicationServicesGroupLite
id, ok := getIntFromResourceData(d, "id")
if ok {
log.Printf("[INFO] Getting data for application services group id: %d\n", id)
res, err := zClient.applicationservicesgroup.Get(id)
if err != nil {
return err
}
resp = res
}
name, _ := d.Get("name").(string)
if resp == nil && name != "" {
log.Printf("[INFO] Getting data for application services group: %s\n", name)
res, err := zClient.applicationservicesgroup.GetByName(name)
if err != nil {
return err
}
resp = res
}

if resp != nil {
d.SetId(fmt.Sprintf("%d", resp.ID))
_ = d.Set("name", resp.Name)
_ = d.Set("name_l10n_tag", resp.NameL10nTag)

} else {
return fmt.Errorf("couldn't find any device name '%s' or id '%d'", name, id)
}

return nil
}
51 changes: 51 additions & 0 deletions zia/data_source_zia_application_services_group_lite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package zia

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceFWApplicationServicesGroupLite_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceFWApplicationServicesGroupLiteConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.office365"),
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.zoom"),
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.webex"),
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.ring_central"),
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.logmein"),
),
},
},
})
}

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

var testAccCheckDataSourceFWApplicationServicesGroupLiteConfig_basic = `
data "zia_firewall_filtering_application_services_group" "office365"{
name = "OFFICE365"
}
data "zia_firewall_filtering_application_services_group" "zoom"{
name = "ZOOM"
}
data "zia_firewall_filtering_application_services_group" "webex"{
name = "WEBEX"
}
data "zia_firewall_filtering_application_services_group" "ring_central"{
name = "RINGCENTRAL"
}
data "zia_firewall_filtering_application_services_group" "logmein"{
name = "LOGMEIN"
}
`
67 changes: 67 additions & 0 deletions zia/data_source_zia_application_services_lite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package zia

import (
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservices"
)

func dataSourceFWApplicationServicesLite() *schema.Resource {
return &schema.Resource{
Read: dataSourceFWApplicationServicesLiteRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique identifier for the application service.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The name of the application service.",
},
"name_l10n_tag": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}

func dataSourceFWApplicationServicesLiteRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)

var resp *applicationservices.ApplicationServicesLite
id, ok := getIntFromResourceData(d, "id")
if ok {
log.Printf("[INFO] Getting data for application services id: %d\n", id)
res, err := zClient.applicationservices.Get(id)
if err != nil {
return err
}
resp = res
}
name, _ := d.Get("name").(string)
if resp == nil && name != "" {
log.Printf("[INFO] Getting data for admin role name: %s\n", name)
res, err := zClient.applicationservices.GetByName(name)
if err != nil {
return err
}
resp = res
}

if resp != nil {
d.SetId(fmt.Sprintf("%d", resp.ID))
_ = d.Set("name", resp.Name)
_ = d.Set("name_l10n_tag", resp.NameL10nTag)

} else {
return fmt.Errorf("couldn't find any device name '%s' or id '%d'", name, id)
}

return nil
}
90 changes: 90 additions & 0 deletions zia/data_source_zia_application_services_lite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package zia

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceFWApplicationServicesLite_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceFWApplicationServicesLiteConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.skype_business"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.one_drive"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.exchange_online"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.m365_common"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.zoom_meeting"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_meeting"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_teams"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_calling"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.ring_central_meeting"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.go_to_meeting"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.logmein_meeting"),
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.logmein_rescue"),
),
},
},
})
}

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

var testAccCheckDataSourceFWApplicationServicesLiteConfig_basic = `
data "zia_firewall_filtering_application_services" "skype_business"{
name = "SKYPEFORBUSINESS"
}
data "zia_firewall_filtering_application_services" "one_drive"{
name = "FILE_SHAREPT_ONEDRIVE"
}
data "zia_firewall_filtering_application_services" "exchange_online"{
name = "EXCHANGEONLINE"
}
data "zia_firewall_filtering_application_services" "m365_common"{
name = "M365COMMON"
}
data "zia_firewall_filtering_application_services" "zoom_meeting"{
name = "ZOOMMEETING"
}
data "zia_firewall_filtering_application_services" "webex_meeting"{
name = "WEBEXMEETING"
}
data "zia_firewall_filtering_application_services" "webex_teams"{
name = "WEBEXTEAMS"
}
data "zia_firewall_filtering_application_services" "webex_calling"{
name = "WEBEXCALLING"
}
data "zia_firewall_filtering_application_services" "ring_central_meeting"{
name = "RINGCENTRALMEETING"
}
data "zia_firewall_filtering_application_services" "go_to_meeting"{
name = "GOTOMEETING"
}
data "zia_firewall_filtering_application_services" "goto_meeting_inroom"{
name = "GOTOMEETING_INROOM"
}
data "zia_firewall_filtering_application_services" "logmein_meeting"{
name = "LOGMEINMEETING"
}
data "zia_firewall_filtering_application_services" "logmein_rescue"{
name = "LOGMEINRESCUE"
}
`
2 changes: 2 additions & 0 deletions zia/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func Provider() *schema.Provider {
"zia_firewall_filtering_network_service_groups": dataSourceFWNetworkServiceGroups(),
"zia_firewall_filtering_network_application": dataSourceFWNetworkApplication(),
"zia_firewall_filtering_network_application_groups": dataSourceFWNetworkApplicationGroups(),
"zia_firewall_filtering_application_services": dataSourceFWApplicationServicesLite(),
"zia_firewall_filtering_application_services_group": dataSourceFWApplicationServicesGroupLite(),
"zia_firewall_filtering_ip_source_groups": dataSourceFWIPSourceGroups(),
"zia_firewall_filtering_destination_groups": dataSourceFWIPDestinationGroups(),
"zia_firewall_filtering_time_window": dataSourceFWTimeWindow(),
Expand Down
24 changes: 12 additions & 12 deletions zia/resource_zia_firewall_filtering_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,24 @@ func resourceFirewallFilteringRules() *schema.Resource {
"dest_addresses": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
// Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"dest_ip_categories": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"default_rule": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Type: schema.TypeBool,
Optional: true,
// Computed: true,
Description: "If set to true, the default rule is applied",
},
"predefined": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Type: schema.TypeBool,
Optional: true,
// Computed: true,
Description: "If set to true, a predefined rule is applied",
},
"locations": listIDsSchemaTypeCustom(8, "list of locations for which rule must be applied"),
Expand All @@ -146,10 +146,10 @@ func resourceFirewallFilteringRules() *schema.Resource {
"departments": listIDsSchemaType("list of departments for which rule must be applied"),
"time_windows": listIDsSchemaType("list of time interval during which rule must be enforced."),
"labels": listIDsSchemaType("list of Labels that are applicable to the rule."),
"src_ip_groups": listIDsSchemaType("list of src ip groups"),
"dest_ip_groups": listIDsSchemaType("list of dest ip groups"),
"app_service_groups": listIDsSchemaType("list of app service groups"),
"app_services": listIDsSchemaType("list of app services"),
"src_ip_groups": listIDsSchemaType("list of source ip groups"),
"dest_ip_groups": listIDsSchemaType("list of destination ip groups"),
"app_service_groups": listIDsSchemaType("list of application service groups"),
"app_services": listIDsSchemaType("list of application services"),
"nw_application_groups": listIDsSchemaType("list of nw application groups"),
"nw_service_groups": listIDsSchemaType("list of nw service groups"),
"nw_services": listIDsSchemaTypeCustom(1024, "list of nw services"),
Expand Down

0 comments on commit 3fe7b1e

Please sign in to comment.