-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) New location management lite data source (#211)
* (feat) New location management lite data source (feat) New location management lite data source * Update CHANGELOG and release-notes
- Loading branch information
Showing
7 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters