-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Application Segment By Type data Source and Fixes (#455)
- Loading branch information
Showing
15 changed files
with
403 additions
and
54 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
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,57 @@ | ||
--- | ||
page_title: "zpa_application_segment_by_type Data Source - terraform-provider-zpa" | ||
subcategory: "Application Segment By Type" | ||
description: |- | ||
Official documentation https://help.zscaler.com/zpa/about-applications | ||
API documentation https://help.zscaler.com/zpa/configuring-application-segments-using-api | ||
Get information about all configured enrollment certificate details. | ||
--- | ||
|
||
# zpa_application_segment_by_type (Data Source) | ||
|
||
* [Official documentation](https://help.zscaler.com/zpa/about-applications) | ||
* [API documentation](https://help.zscaler.com/zpa/configuring-application-segments-using-api) | ||
|
||
Use the **zpa_application_segment_by_type** data source to get all configured Application Segments by Access Type (e.g., ``BROWSER_ACCESS``, ``INSPECT``, or ``SECURE_REMOTE_ACCESS``) for the specified customer. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "BROWSER_ACCESS" | ||
} | ||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "INSPECT" | ||
} | ||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "SECURE_REMOTE_ACCESS" | ||
} | ||
``` | ||
|
||
## Schema | ||
|
||
### Required | ||
|
||
The following arguments are supported: | ||
|
||
* `application_type` - (String) The name of the enrollment certificate to be exported. | ||
|
||
### Read-Only | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - (String) The unique identifier of the Browser Access, inspection or secure remote access application. | ||
* `app_id` - (String) The unique identifier of the application. | ||
* `name` - (String) The name of the Browser Access, inspection or secure remote access application. | ||
* `enabled` - (bool) Whether the Browser Access, inspection or secure remote access application is enabled or not | ||
* `domain` - (string) The domain of the Browser Access, inspection or secure remote access application | ||
* `application_port` - (string) The port for the Browser Access, inspection or secure remote access application | ||
* `application_protocol` - (string) The protocol for the Browser Access, inspection or secure remote access application | ||
|
||
* `certificate_id` - (string) The unique identifier of the Browser Access certificate | ||
* `certificate_name` - (string) The name of the Browser Access certificate | ||
* `microtenant_id` - (string) The unique identifier of the Microtenant for the ZPA tenant. If you are within the Default Microtenant, pass microtenantId as 0 when making requests to retrieve data from the Default Microtenant. Pass microtenantId as null to retrieve data from all customers associated with the tenant | ||
* `microtenant_name` - (string) The name of the Microtenant | ||
|
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,28 @@ | ||
# Retrieves ALL application segments by type | ||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "BROWSER_ACCESS" | ||
} | ||
|
||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "INSPECT" | ||
} | ||
|
||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "SECURE_REMOTE_ACCESS" | ||
} | ||
|
||
# Retrieves ALL application segment names by type | ||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "BROWSER_ACCESS" | ||
name = "ba_app01" | ||
} | ||
|
||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "INSPECT" | ||
name = "inspect_app01" | ||
} | ||
|
||
data "zpa_application_segment_by_type" "this" { | ||
application_type = "SECURE_REMOTE_ACCESS" | ||
name = "pra_app01" | ||
} |
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
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,119 @@ | ||
package zpa | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceApplicationSegmentByType() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceApplicationSegmentByTypeRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The unique identifier of the Browser Access application", | ||
}, | ||
"app_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The unique identifier of the application", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The name of the Browser Access application", | ||
}, | ||
"application_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The type of application, BROWSER_ACCESS, INSPECT or SECURE_REMOTE_ACCESS", | ||
}, | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Whether the Browser Access application is enabled or not", | ||
}, | ||
"domain": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The domain of the Browser Access application", | ||
}, | ||
"application_port": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The port for the Browser Access application", | ||
}, | ||
"application_protocol": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The protocol for the Browser Access application", | ||
}, | ||
"certificate_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The unique identifier of the Browser Access certificate", | ||
}, | ||
"certificate_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The name of the Browser Access certificate", | ||
}, | ||
"microtenant_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The unique identifier of the Microtenant for the ZPA tenant. If you are within the Default Microtenant, pass microtenantId as 0 when making requests to retrieve data from the Default Microtenant. Pass microtenantId as null to retrieve data from all customers associated with the tenant", | ||
}, | ||
"microtenant_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The name of the Microtenant", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceApplicationSegmentByTypeRead(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*Client) | ||
service := client.applicationsegmentbytype.WithMicroTenant(GetString(d.Get("microtenant_id"))) | ||
|
||
applicationType := d.Get("application_type").(string) | ||
if applicationType != "BROWSER_ACCESS" && applicationType != "SECURE_REMOTE_ACCESS" && applicationType != "INSPECT" { | ||
return fmt.Errorf("invalid application_type '%s'. Valid types are 'BROWSER_ACCESS', 'SECURE_REMOTE_ACCESS', 'INSPECT'", applicationType) | ||
} | ||
|
||
name := d.Get("name").(string) | ||
log.Printf("[INFO] Getting data for application segment with type %s", applicationType) | ||
if name != "" { | ||
log.Printf("[INFO] Getting data for application segment with name %s and type %s", name, applicationType) | ||
} | ||
|
||
// Call the SDK function | ||
resp, _, err := service.GetByApplicationType(name, applicationType, true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(resp) == 0 { | ||
return fmt.Errorf("no application segment found for name '%s' and type '%s'", name, applicationType) | ||
} | ||
|
||
// Assuming we are only interested in the first result for simplicity | ||
appSegment := resp[0] | ||
|
||
d.SetId(appSegment.ID) | ||
_ = d.Set("app_id", appSegment.AppID) | ||
_ = d.Set("name", appSegment.Name) | ||
_ = d.Set("enabled", appSegment.Enabled) | ||
_ = d.Set("domain", appSegment.Domain) | ||
_ = d.Set("application_port", appSegment.ApplicationPort) | ||
_ = d.Set("application_protocol", appSegment.ApplicationProtocol) | ||
_ = d.Set("certificate_id", appSegment.CertificateID) | ||
_ = d.Set("certificate_name", appSegment.CertificateName) | ||
_ = d.Set("microtenant_id", appSegment.MicroTenantID) | ||
_ = d.Set("microtenant_name", appSegment.MicroTenantName) | ||
|
||
return nil | ||
} |
Oops, something went wrong.