From 75a6e1775ff4a96dc1ef7f23ebb4b6b86522c10a Mon Sep 17 00:00:00 2001 From: William Guilherme Date: Sat, 18 May 2024 00:40:46 -0700 Subject: [PATCH] feat: Added Application Segment By Type data Source and Fixes (#455) --- CHANGELOG.md | 16 +++ GNUmakefile | 6 +- .../zpa_application_segment_by_type.md | 57 ++++++++ docs/guides/release-notes.md | 18 ++- .../datasource.tf | 28 ++++ go.mod | 10 +- go.sum | 20 +-- zpa/config.go | 3 + ..._source_zpa_application_segment_by_type.go | 119 +++++++++++++++ ...ce_zpa_application_segment_by_type_test.go | 135 ++++++++++++++++++ ...urce_zpa_cloud_browser_isolation_region.go | 12 +- ...ata_source_zpa_customer_version_profile.go | 15 +- zpa/data_source_zpa_isolation_profiles.go | 15 +- zpa/provider.go | 1 + zpa/resource_zpa_service_edge_group.go | 2 +- 15 files changed, 403 insertions(+), 54 deletions(-) create mode 100644 docs/data-sources/zpa_application_segment_by_type.md create mode 100644 examples/zpa_application_segment_by_type/datasource.tf create mode 100644 zpa/data_source_zpa_application_segment_by_type.go create mode 100644 zpa/data_source_zpa_application_segment_by_type_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d4434d..511b1f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 3.3.0 (May, 17 2024) + +### Notes + +- Release date: **(May, 17 2024)** +- Supported Terraform version: **v1.x** + +### ENHACEMENTS +- [PR #455](https://github.com/zscaler/terraform-provider-zpa/pull/455) Added new data source `zpa_application_segment_by_type`. The data source allows for querying of application segments by type. The ``application_type`` attribute supports the following values: `BROWSER_ACCESS`, `INSPECT`, and `SECURE_REMOTE_ACCESS` + +### Bug Fixes +- [PR #455](https://github.com/zscaler/terraform-provider-zpa/pull/455) Fixed resource `zpa_service_edge_group` due to misconfiguration in the importing function. + +### Internal Changes +- [PR #454](https://github.com/zscaler/terraform-provider-zpa/pull/454) - Added Support to arbitrary clouds for testing purposes + ## 3.2.11 (May, 3 2024) ### Notes diff --git a/GNUmakefile b/GNUmakefile index 7c9566ae..fd78d436 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -54,14 +54,14 @@ test\:integration\:zpa: build13: GOOS=$(shell go env GOOS) build13: GOARCH=$(shell go env GOARCH) ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... -build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.2.11/$(GOOS)_$(GOARCH) +build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.3.0/$(GOOS)_$(GOARCH) else -build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.2.11/$(GOOS)_$(GOARCH) +build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.3.0/$(GOOS)_$(GOARCH) endif build13: fmtcheck @echo "==> Installing plugin to $(DESTINATION)" @mkdir -p $(DESTINATION) - go build -o $(DESTINATION)/terraform-provider-zpa_v3.2.11 + go build -o $(DESTINATION)/terraform-provider-zpa_v3.3.0 vet: @echo "==> Checking source code against go vet and staticcheck" diff --git a/docs/data-sources/zpa_application_segment_by_type.md b/docs/data-sources/zpa_application_segment_by_type.md new file mode 100644 index 00000000..2862ebdd --- /dev/null +++ b/docs/data-sources/zpa_application_segment_by_type.md @@ -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 + diff --git a/docs/guides/release-notes.md b/docs/guides/release-notes.md index c3ef3333..d65ca138 100644 --- a/docs/guides/release-notes.md +++ b/docs/guides/release-notes.md @@ -12,10 +12,26 @@ Track all ZPA Terraform provider's releases. New resources, features, and bug fi --- -``Last updated: v3.2.11`` +``Last updated: v3.3.0`` --- +## 3.3.0 (May, 17 2024) + +### Notes + +- Release date: **(May, 17 2024)** +- Supported Terraform version: **v1.x** + +### ENHACEMENTS +- [PR #455](https://github.com/zscaler/terraform-provider-zpa/pull/455) Added new data source `zpa_application_segment_by_type`. The data source allows for querying of application segments by type. The ``application_type`` attribute supports the following values: `BROWSER_ACCESS`, `INSPECT`, and `SECURE_REMOTE_ACCESS` + +### Bug Fixes +- [PR #455](https://github.com/zscaler/terraform-provider-zpa/pull/455) Fixed resource `zpa_service_edge_group` due to misconfiguration in the importing function. + +### Internal Changes +- [PR #454](https://github.com/zscaler/terraform-provider-zpa/pull/454) - Added Support to arbitrary clouds for testing purposes + ## 3.2.11 (May, 3 2024) ### Notes diff --git a/examples/zpa_application_segment_by_type/datasource.tf b/examples/zpa_application_segment_by_type/datasource.tf new file mode 100644 index 00000000..b191b9f3 --- /dev/null +++ b/examples/zpa_application_segment_by_type/datasource.tf @@ -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" +} \ No newline at end of file diff --git a/go.mod b/go.mod index ad3c1228..e83d9dcc 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,10 @@ require ( github.com/fabiotavarespr/iso3166 v0.0.2 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-hclog v1.6.3 - github.com/hashicorp/terraform-plugin-docs v0.19.2 + github.com/hashicorp/terraform-plugin-docs v0.19.1 github.com/hashicorp/terraform-plugin-sdk v1.17.2 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/zscaler/zscaler-sdk-go/v2 v2.5.0 + github.com/zscaler/zscaler-sdk-go/v2 v2.5.2 ) require ( @@ -43,7 +43,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.6.0 // indirect - github.com/hashicorp/go-retryablehttp v0.7.5 // indirect + github.com/hashicorp/go-retryablehttp v0.7.6 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/hc-install v0.6.4 // indirect @@ -73,7 +73,7 @@ require ( github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/yuin/goldmark v1.7.1 // indirect + github.com/yuin/goldmark v1.7.0 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect github.com/zclconf/go-cty v1.14.4 // indirect go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect @@ -81,7 +81,7 @@ require ( golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.16.0 // indirect golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect golang.org/x/tools v0.13.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index 1a77afe3..9e5fd4ae 100644 --- a/go.sum +++ b/go.sum @@ -230,8 +230,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9 github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0= github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= -github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= -github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= +github.com/hashicorp/go-retryablehttp v0.7.6 h1:TwRYfx2z2C4cLbXmT8I5PgP/xmuqASDyiVuGYfs9GZM= +github.com/hashicorp/go-retryablehttp v0.7.6/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -260,8 +260,8 @@ github.com/hashicorp/terraform-exec v0.20.0/go.mod h1:ckKGkJWbsNqFKV1itgMnE0hY9I github.com/hashicorp/terraform-json v0.10.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE= github.com/hashicorp/terraform-json v0.21.0 h1:9NQxbLNqPbEMze+S6+YluEdXgJmhQykRyRNd+zTI05U= github.com/hashicorp/terraform-json v0.21.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk= -github.com/hashicorp/terraform-plugin-docs v0.19.2 h1:YjdKa1vuqt9EnPYkkrv9HnGZz175HhSJ7Vsn8yZeWus= -github.com/hashicorp/terraform-plugin-docs v0.19.2/go.mod h1:gad2aP6uObFKhgNE8DR9nsEuEQnibp7il0jZYYOunWY= +github.com/hashicorp/terraform-plugin-docs v0.19.1 h1:XYIlGCfnUDVTyKPIHFKRDfB4INU+pyPKk6VZ/1apPIc= +github.com/hashicorp/terraform-plugin-docs v0.19.1/go.mod h1:NPfKCSfzTtq+YCFHr2qTAMknWUxR8C4KgTbGkHULSV8= github.com/hashicorp/terraform-plugin-go v0.22.0 h1:1OS1Jk5mO0f5hrziWJGXXIxBrMe2j/B8E+DVGw43Xmc= github.com/hashicorp/terraform-plugin-go v0.22.0/go.mod h1:mPULV91VKss7sik6KFEcEu7HuTogMLLO/EvWCuFkRVE= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= @@ -428,8 +428,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= -github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= +github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= @@ -441,8 +441,8 @@ github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8 github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= -github.com/zscaler/zscaler-sdk-go/v2 v2.5.0 h1:HMbSSdsdtOpbSXw7+zvgqeRVLu888Ofasm7/IiFiFWI= -github.com/zscaler/zscaler-sdk-go/v2 v2.5.0/go.mod h1:fg09cxBT9mpphzOPpE0iGBpOudhbwPtFAtNkBoXTJ54= +github.com/zscaler/zscaler-sdk-go/v2 v2.5.2 h1:R6BSrfVPptaJAAU8o2ZxIOWsA6WDvh7PsKX5gF6GNcY= +github.com/zscaler/zscaler-sdk-go/v2 v2.5.2/go.mod h1:ORk1VkYcUqRb5Ipg3h3kKacdwbbPydKL43Ku+AQjAr0= go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw= go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -597,8 +597,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= diff --git a/zpa/config.go b/zpa/config.go index 4dddcfdf..293af719 100644 --- a/zpa/config.go +++ b/zpa/config.go @@ -7,6 +7,7 @@ import ( "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorcontroller" "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorgroup" "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/applicationsegment" + "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/applicationsegmentbytype" "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/applicationsegmentinspection" "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/applicationsegmentpra" "github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appservercontroller" @@ -60,6 +61,7 @@ type Client struct { applicationsegment applicationsegment.Service applicationsegmentpra applicationsegmentpra.Service applicationsegmentinspection applicationsegmentinspection.Service + applicationsegmentbytype applicationsegmentbytype.Service appservercontroller appservercontroller.Service bacertificate bacertificate.Service browseraccess browseraccess.Service @@ -129,6 +131,7 @@ func (c *Config) Client() (*Client, error) { applicationsegment: *applicationsegment.New(zpaClient), applicationsegmentpra: *applicationsegmentpra.New(zpaClient), applicationsegmentinspection: *applicationsegmentinspection.New(zpaClient), + applicationsegmentbytype: *applicationsegmentbytype.New(zpaClient), appservercontroller: *appservercontroller.New(zpaClient), bacertificate: *bacertificate.New(zpaClient), browseraccess: *browseraccess.New(zpaClient), diff --git a/zpa/data_source_zpa_application_segment_by_type.go b/zpa/data_source_zpa_application_segment_by_type.go new file mode 100644 index 00000000..a413ac89 --- /dev/null +++ b/zpa/data_source_zpa_application_segment_by_type.go @@ -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 +} diff --git a/zpa/data_source_zpa_application_segment_by_type_test.go b/zpa/data_source_zpa_application_segment_by_type_test.go new file mode 100644 index 00000000..7cd6036d --- /dev/null +++ b/zpa/data_source_zpa_application_segment_by_type_test.go @@ -0,0 +1,135 @@ +package zpa + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/zscaler/terraform-provider-zpa/v3/zpa/common/testing/method" +) + +func TestAccDataSourceApplicationSegmentByType_Basic(t *testing.T) { + // Generate random suffixes + _, _, resourceNameSuffix := method.GenerateRandomSourcesTypeAndName("zpa_application_segment_pra") + _, _, domainNameSuffix := method.GenerateRandomSourcesTypeAndName("zpa_application_segment_inspection") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckDataSourceApplicationSegmentByTypeConfig_basic(resourceNameSuffix, domainNameSuffix), + Check: resource.ComposeTestCheckFunc( + testAccDataSourceApplicationSegmentByTypeCheck("data.zpa_application_segment_by_type.pra"), + testAccDataSourceApplicationSegmentByTypeCheck("data.zpa_application_segment_by_type.inspect"), + testAccDataSourceApplicationSegmentByTypeCheck("data.zpa_application_segment_by_type.ba"), + ), + }, + }, + }) +} + +func testAccDataSourceApplicationSegmentByTypeCheck(application_type string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(application_type, "application_type"), + resource.TestCheckResourceAttrSet(application_type, "name"), + ) +} + +func testAccCheckDataSourceApplicationSegmentByTypeConfig_basic(resourceNameSuffix, domainNameSuffix string) string { + return fmt.Sprintf(` +resource "zpa_segment_group" "this" { + name = "tf-acc-test-%s" + description = "tf-acc-test-%s" + enabled = true +} + +resource "zpa_application_segment_pra" "this" { + name = "tf-acc-test-%s-1" + description = "tf-acc-test-%s-1" + enabled = true + health_reporting = "ON_ACCESS" + bypass_type = "NEVER" + is_cname_enabled = true + tcp_port_ranges = ["2222", "2222"] + domain_names = ["tests-%s.example.com"] + segment_group_id = zpa_segment_group.this.id + common_apps_dto { + apps_config { + name = "%s-app" + domain = "tests-%s.example.com" + application_protocol = "SSH" + application_port = "2222" + enabled = true + app_types = [ "SECURE_REMOTE_ACCESS" ] + } + } +} + +data "zpa_ba_certificate" "jenkins" { + name = "jenkins.bd-hashicorp.com" +} + +resource "zpa_application_segment_inspection" "this" { + name = "tf-acc-test-%s-2" + description = "tf-acc-test-%s-2" + enabled = true + health_reporting = "ON_ACCESS" + bypass_type = "NEVER" + is_cname_enabled = true + tcp_port_ranges = ["4444", "4444"] + domain_names = ["tests-%s.example.com"] + segment_group_id = zpa_segment_group.this.id + common_apps_dto { + apps_config { + name = "%s-app" + domain = "tests-%s.example.com" + application_protocol = "HTTPS" + application_port = "4444" + certificate_id = data.zpa_ba_certificate.jenkins.id + enabled = true + app_types = [ "INSPECT" ] + } + } +} + +resource "zpa_application_segment_browser_access" "this" { + name = "tf-acc-test-%s-3" + description = "tf-acc-test-%s-3" + enabled = true + health_reporting = "ON_ACCESS" + bypass_type = "NEVER" + tcp_port_ranges = ["4445", "4445"] + domain_names = ["tests-%s.example.com"] + segment_group_id = zpa_segment_group.this.id + + clientless_apps { + name = "%s-app" + enabled = true + domain = "tests-%s.example.com" + application_protocol = "HTTPS" + application_port = "4445" + certificate_id = data.zpa_ba_certificate.jenkins.id + trust_untrusted_cert = true + } +} + +data "zpa_application_segment_by_type" "pra" { + application_type = "SECURE_REMOTE_ACCESS" + depends_on = [zpa_segment_group.this, zpa_application_segment_pra.this] +} + +data "zpa_application_segment_by_type" "inspect" { + application_type = "INSPECT" + depends_on = [zpa_segment_group.this, zpa_application_segment_inspection.this] +} + +data "zpa_application_segment_by_type" "ba" { + application_type = "BROWSER_ACCESS" + depends_on = [zpa_segment_group.this, zpa_application_segment_browser_access.this] + } +`, resourceNameSuffix, resourceNameSuffix, resourceNameSuffix, resourceNameSuffix, domainNameSuffix, resourceNameSuffix, domainNameSuffix, + resourceNameSuffix, resourceNameSuffix, domainNameSuffix, resourceNameSuffix, domainNameSuffix, + resourceNameSuffix, resourceNameSuffix, domainNameSuffix, resourceNameSuffix, domainNameSuffix, + ) +} diff --git a/zpa/data_source_zpa_cloud_browser_isolation_region.go b/zpa/data_source_zpa_cloud_browser_isolation_region.go index 6b386433..3ed6f520 100644 --- a/zpa/data_source_zpa_cloud_browser_isolation_region.go +++ b/zpa/data_source_zpa_cloud_browser_isolation_region.go @@ -30,15 +30,6 @@ func dataSourceCBIRegionsRead(d *schema.ResourceData, m interface{}) error { zClient := m.(*Client) var resp *cbiregions.CBIRegions - id, ok := d.Get("id").(string) - if ok && id != "" { - log.Printf("[INFO] Getting data for cbi regions %s\n", id) - res, _, err := zClient.cbiregions.Get(id) - if err != nil { - return err - } - resp = res - } name, ok := d.Get("name").(string) if ok && name != "" { log.Printf("[INFO] Getting data for cbi regions name %s\n", name) @@ -48,12 +39,13 @@ func dataSourceCBIRegionsRead(d *schema.ResourceData, m interface{}) error { } resp = res } + if resp != nil { d.SetId(resp.ID) _ = d.Set("name", resp.Name) } else { - return fmt.Errorf("couldn't find any cbi regions with name '%s' or id '%s'", name, id) + return fmt.Errorf("couldn't find any cbi regions with name '%s'", name) } return nil diff --git a/zpa/data_source_zpa_customer_version_profile.go b/zpa/data_source_zpa_customer_version_profile.go index e6a00c98..5c1c845a 100644 --- a/zpa/data_source_zpa_customer_version_profile.go +++ b/zpa/data_source_zpa_customer_version_profile.go @@ -139,19 +139,9 @@ func dataSourceCustomerVersionProfile() *schema.Resource { func dataSourceCustomerVersionProfileRead(d *schema.ResourceData, m interface{}) error { zClient := m.(*Client) - var resp *customerversionprofile.CustomerVersionProfile - id, ok := d.Get("id").(string) - if ok && id != "" { - log.Printf("[INFO] Getting data for customer version profile %s\n", id) - res, _, err := zClient.customerversionprofile.Get(id) - if err != nil { - return err - } - resp = res - } name, ok := d.Get("name").(string) - if id == "" && ok && name != "" { + if ok && name != "" { log.Printf("[INFO] Getting data for customer version profile name %s\n", name) res, _, err := zClient.customerversionprofile.GetByName(name) if err != nil { @@ -159,6 +149,7 @@ func dataSourceCustomerVersionProfileRead(d *schema.ResourceData, m interface{}) } resp = res } + if resp != nil { d.SetId(resp.ID) _ = d.Set("creation_time", resp.CreationTime) @@ -181,7 +172,7 @@ func dataSourceCustomerVersionProfileRead(d *schema.ResourceData, m interface{}) return fmt.Errorf("failed to read versions %s", err) } } else { - return fmt.Errorf("couldn't find any customer version profile with name '%s' or id '%s'", name, id) + return fmt.Errorf("couldn't find any customer version profilee with name '%s'", name) } return nil diff --git a/zpa/data_source_zpa_isolation_profiles.go b/zpa/data_source_zpa_isolation_profiles.go index b2e56b6a..1d84a2bc 100644 --- a/zpa/data_source_zpa_isolation_profiles.go +++ b/zpa/data_source_zpa_isolation_profiles.go @@ -60,17 +60,8 @@ func dataSourceIsolationProfileRead(d *schema.ResourceData, m interface{}) error zClient := m.(*Client) var resp *isolationprofile.IsolationProfile - id, ok := d.Get("id").(string) - if ok && id != "" { - log.Printf("[INFO] Getting data for isolation profile %s\n", id) - res, _, err := zClient.isolationprofile.Get(id) - if err != nil { - return err - } - resp = res - } name, ok := d.Get("name").(string) - if id == "" && ok && name != "" { + if ok && name != "" { log.Printf("[INFO] Getting data for isolation profile name %s\n", name) res, _, err := zClient.isolationprofile.GetByName(name) if err != nil { @@ -78,6 +69,7 @@ func dataSourceIsolationProfileRead(d *schema.ResourceData, m interface{}) error } resp = res } + if resp != nil { d.SetId(resp.ID) _ = d.Set("name", resp.Name) @@ -89,9 +81,8 @@ func dataSourceIsolationProfileRead(d *schema.ResourceData, m interface{}) error _ = d.Set("isolation_profile_id", resp.IsolationProfileID) _ = d.Set("isolation_tenant_id", resp.IsolationTenantID) _ = d.Set("isolation_url", resp.IsolationURL) - } else { - return fmt.Errorf("couldn't find any isolation profile with name '%s' or id '%s'", name, id) + return fmt.Errorf("couldn't find any isolation profile with name '%s'", name) } return nil diff --git a/zpa/provider.go b/zpa/provider.go index 54f97a85..5563531f 100644 --- a/zpa/provider.go +++ b/zpa/provider.go @@ -110,6 +110,7 @@ func ZPAProvider() *schema.Provider { "zpa_application_segment_pra": dataSourceApplicationSegmentPRA(), "zpa_application_segment_inspection": dataSourceApplicationSegmentInspection(), "zpa_application_segment_browser_access": dataSourceApplicationSegmentBrowserAccess(), + "zpa_application_segment_by_type": dataSourceApplicationSegmentByType(), "zpa_segment_group": dataSourceSegmentGroup(), "zpa_app_connector_group": dataSourceAppConnectorGroup(), "zpa_app_connector_controller": dataSourceAppConnectorController(), diff --git a/zpa/resource_zpa_service_edge_group.go b/zpa/resource_zpa_service_edge_group.go index db890ccc..11703ccc 100644 --- a/zpa/resource_zpa_service_edge_group.go +++ b/zpa/resource_zpa_service_edge_group.go @@ -20,7 +20,7 @@ func resourceServiceEdgeGroup() *schema.Resource { Delete: resourceServiceEdgeGroupDelete, Importer: &schema.ResourceImporter{ State: func(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - service := m.(*Client).appconnectorgroup.WithMicroTenant(GetString(d.Get("microtenant_id"))) + service := m.(*Client).serviceedgegroup.WithMicroTenant(GetString(d.Get("microtenant_id"))) id := d.Id() _, parseIDErr := strconv.ParseInt(id, 10, 64)