Skip to content

Commit

Permalink
(feat) New location management lite data source (#211)
Browse files Browse the repository at this point in the history
* (feat) New location management lite data source
(feat) New location management lite data source
* Update CHANGELOG and release-notes
  • Loading branch information
willguibr authored Mar 23, 2023
1 parent 02973fe commit 6e2baf0
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/data-sources/zia_location_lite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
subcategory: "Location Management"
layout: "zscaler"
page_title: "ZIA: location_lite"
description: |-
Get information about Location Lite.
---

# Data Source: zia_location_lite

Use the **zia_location_lite** data source to get information about a location in lite mode option available in the Zscaler Internet Access. This data source can be used to retrieve the Road Warrior location to then associated with one of the following resources: ``zia_url_filtering_rules``, ``zia_firewall_filtering_rule`` and ``zia_dlp_web_rules`

```hcl
# Retrieve ZIA Location Lite
data "zia_location_lite" "this" {
name = "Road Warrior"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Location group name
* `id` - (Optional) Unique identifier for the location group

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `kerberos_auth` - (Boolean)
* `digest_auth_enabled` - (Boolean)
* `parent_id` - (Number) - Parent Location ID. If this ID does not exist or is `0`, it is implied that it is a parent location. Otherwise, it is a sub-location whose parent has this ID. x-applicableTo: `SUB`
* `tz` - (String) Timezone of the location. If not specified, it defaults to GMT.
* `zapp_ssl_scan_enabled` - (Boolean) This parameter was deprecated and no longer has an effect on SSL policy. It remains supported in the API payload in order to maintain backwards compatibility with existing scripts, but it will be removed in future.
* `xff_forward_enabled` - (Boolean) Enable XFF Forwarding. When set to true, traffic is passed to Zscaler Cloud via the X-Forwarded-For (XFF) header.
* `surrogate_ip` - (Boolean) Enable Surrogate IP. When set to true, users are mapped to internal device IP addresses.
* `surrogate_ip_enforced_for_known_browsers` - (Boolean) Enforce Surrogate IP for Known Browsers. When set to true, IP Surrogate is enforced for all known browsers.
* `ofw_enabled` - (Boolean) Enable Firewall. When set to true, Firewall is enabled for the location.
* `ips_control` - (Boolean) Enable IPS Control. When set to true, IPS Control is enabled for the location if Firewall is enabled.
* `aup_enabled` - (Boolean) Enable AUP. When set to true, AUP is enabled for the location.
* `caution_enabled` - (Boolean) Enable Caution. When set to true, a caution notifcation is enabled for the location.
* `aup_block_internet_until_accepted` - (Boolean) For First Time AUP Behavior, Block Internet Access. When set, all internet access (including non-HTTP traffic) is disabled until the user accepts the AUP.
* `aup_force_ssl_inspection` - (Boolean) For First Time AUP Behavior, Force SSL Inspection. When set, Zscaler will force SSL Inspection in order to enforce AUP for HTTPS traffic.
* `ec_location` - (Boolean)
* `other_sub_location` - (Boolean) If set to true, indicates that this is a default sub-location created by the Zscaler service to accommodate IPv4 addresses that are not part of any user-defined sub-locations. The default sub-location is created with the name Other and it can be renamed, if required.
* `other6_sub_location` - (Boolean) If set to true, indicates that this is a default sub-location created by the Zscaler service to accommodate IPv6 addresses that are not part of any user-defined sub-locations. The default sub-location is created with the name Other6 and it can be renamed, if required. This field is applicable only if ipv6Enabled is set is true
* `ipv6_enabled` - (Number) If set to true, IPv6 is enabled for the location and IPv6 traffic from the location can be forwarded to the Zscaler service to enforce security policies.
22 changes: 22 additions & 0 deletions examples/zia_location_lite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Location Management Lite - Example

This example will show you how to use Terraform to retrieve a lite version of a location management including "Road Warrior" location for use in several resource types such as ``zia_url_filtering_rules``, ``zia_firewall_filtering_rule`` and ``zia_dlp_web_rules``
This example codifies [this API](https://help.zscaler.com/zia/location-management#/locations/lite-get).

To run, configure your ZIA provider as described [Here](https://github.com/zscaler/terraform-provider-zia/blob/master/docs/index.md)

## Run the example

From inside of this directory:

```bash
terraform init
terraform plan -out theplan
terraform apply theplan
```

## Destroy 💥

```bash
terraform destroy
```
7 changes: 7 additions & 0 deletions examples/zia_location_lite/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "zia_location_lite" "this" {
name = "Road Warrior"
}

output "zia_location_lite"{
value = data.zia_location_lite.this
}
3 changes: 3 additions & 0 deletions zia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/timewindow"
"github.com/zscaler/zscaler-sdk-go/zia/services/locationmanagement"
"github.com/zscaler/zscaler-sdk-go/zia/services/locationmanagement/locationgroups"
"github.com/zscaler/zscaler-sdk-go/zia/services/locationmanagement/locationlite"
"github.com/zscaler/zscaler-sdk-go/zia/services/rule_labels"
"github.com/zscaler/zscaler-sdk-go/zia/services/security_policy_settings"
"github.com/zscaler/zscaler-sdk-go/zia/services/trafficforwarding/greinternalipranges"
Expand Down Expand Up @@ -64,6 +65,7 @@ type Client struct {
vpncredentials *vpncredentials.Service
locationmanagement *locationmanagement.Service
locationgroups *locationgroups.Service
locationlite *locationlite.Service
activation *activation.Service
devicegroups *devicegroups.Service
dlpdictionaries *dlpdictionaries.Service
Expand Down Expand Up @@ -113,6 +115,7 @@ func (c *Config) Client() (*Client, error) {
staticips: staticips.New(cli),
locationmanagement: locationmanagement.New(cli),
locationgroups: locationgroups.New(cli),
locationlite: locationlite.New(cli),
activation: activation.New(cli),
devicegroups: devicegroups.New(cli),
dlpdictionaries: dlpdictionaries.New(cli),
Expand Down
149 changes: 149 additions & 0 deletions zia/data_source_zia_location_lite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package zia

import (
"fmt"
"log"

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

func dataSourceLocationLite() *schema.Resource {
return &schema.Resource{
Read: dataSourceLocationLiteRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"parent_id": {
Type: schema.TypeInt,
Computed: true,
},
"tz": {
Type: schema.TypeString,
Computed: true,
},
"kerberos_auth": {
Type: schema.TypeBool,
Optional: true,
},
"digest_auth_enabled": {
Type: schema.TypeBool,
Optional: true,
},
"xff_forward_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"aup_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"caution_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"aup_block_internet_until_accepted": {
Type: schema.TypeBool,
Computed: true,
},
"aup_force_ssl_inspection": {
Type: schema.TypeBool,
Computed: true,
},
"surrogate_ip": {
Type: schema.TypeBool,
Computed: true,
},
"zapp_ssl_scan_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"surrogate_ip_enforced_for_known_browsers": {
Type: schema.TypeBool,
Computed: true,
},
"other_sub_location": {
Type: schema.TypeBool,
Computed: true,
},
"other6_sub_location": {
Type: schema.TypeBool,
Computed: true,
},
"ofw_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"ips_control": {
Type: schema.TypeBool,
Computed: true,
},
"ipv6_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"ec_location": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}

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

var resp *locationlite.LocationLite
id, ok := getIntFromResourceData(d, "id")
if ok {
log.Printf("[INFO] Getting data for location id: %d\n", id)
res, err := zClient.locationlite.GetLocationLiteID(id)
if err != nil {
return err
}
resp = res
}
name, _ := d.Get("name").(string)
if resp == nil && name != "" {
log.Printf("[INFO] Getting data for location name: %s\n", name)
res, err := zClient.locationlite.GetLocationLiteByName(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("kerberos_auth", resp.KerberosAuth)
_ = d.Set("digest_auth_enabled", resp.DigestAuthEnabled)
_ = d.Set("parent_id", resp.ParentID)
_ = d.Set("tz", resp.TZ)
_ = d.Set("zapp_ssl_scan_enabled", resp.ZappSSLScanEnabled)
_ = d.Set("xff_forward_enabled", resp.XFFForwardEnabled)
_ = d.Set("surrogate_ip", resp.SurrogateIP)
_ = d.Set("surrogate_ip_enforced_for_known_browsers", resp.SurrogateIPEnforcedForKnownBrowsers)
_ = d.Set("ofw_enabled", resp.OFWEnabled)
_ = d.Set("ips_control", resp.IPSControl)
_ = d.Set("aup_enabled", resp.AUPEnabled)
_ = d.Set("caution_enabled", resp.CautionEnabled)
_ = d.Set("aup_block_internet_until_accepted", resp.AUPBlockInternetUntilAccepted)
_ = d.Set("aup_force_ssl_inspection", resp.AUPForceSSLInspection)
_ = d.Set("ec_location", resp.ECLocation)
_ = d.Set("other_sub_location", resp.OtherSubLocation)
_ = d.Set("other6_sub_location", resp.Other6SubLocation)
_ = d.Set("ipv6_enabled", resp.IPv6Enabled)

} else {
return fmt.Errorf("couldn't find any location with name '%s'", name)
}

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

import (
"testing"

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

func TestAccDataSourceLocationLite_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceLocationLiteConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceLocationLiteCheck("data.zia_location_lite.road_warrior"),
),
},
},
})
}

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

var testAccCheckDataSourceLocationLiteConfig_basic = `
data "zia_location_lite" "road_warrior"{
name = "Road Warrior"
}
`
1 change: 1 addition & 0 deletions zia/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func Provider() *schema.Provider {
"zia_gre_internal_ip_range_list": dataSourceTrafficForwardingGreInternalIPRangeList(),
"zia_location_management": dataSourceLocationManagement(),
"zia_location_groups": dataSourceLocationGroup(),
"zia_location_lite": dataSourceLocationLite(),
"zia_dlp_dictionaries": dataSourceDLPDictionaries(),
"zia_dlp_engines": dataSourceDLPEngines(),
"zia_dlp_icap_servers": dataSourceDLPICAPServers(),
Expand Down

0 comments on commit 6e2baf0

Please sign in to comment.