diff --git a/.github/workflows/zia-test.yml b/.github/workflows/zia-test.yml index 2b7d78b..f5d5b58 100644 --- a/.github/workflows/zia-test.yml +++ b/.github/workflows/zia-test.yml @@ -94,7 +94,7 @@ jobs: environment: # - ZIA_ZSCLOUD - ZIA_ZS0 - - ZIA_ZS1 + # - ZIA_ZS1 # - ZIA_ZS2 # - ZIA_ZS3 environment: ${{ matrix.environment }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 21fa869..475ede0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ - `longitude` - (Number) The longitude coordinate of the GRE tunnel source. - `subcloud` - (String) The longitude coordinate of the GRE tunnel source. +- [PR #366](https://github.com/zscaler/terraform-provider-zia/pull/366) - Added centralized semaphore functionality to manipulate concurrent request limitations. + ## 3.0.1 (August, 13 2024) ### Notes diff --git a/GNUmakefile b/GNUmakefile index a24d5ac..eff9a3f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -40,14 +40,14 @@ sweep: test: echo $(TEST) | \ - xargs -t -n4 go test $(TESTARGS) $(TEST_FILTER) -timeout=30s -parallel=1 + xargs -t -n4 go test $(TESTARGS) $(TEST_FILTER) -timeout=30s -parallel=5 testacc: TF_ACC=1 go test $(TEST) $(TESTARGS) $(TEST_FILTER) -timeout 120m test\:integration\:zia: @echo "$(COLOR_ZSCALER)Running zia integration tests...$(COLOR_NONE)" - @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 1 -timeout 120m + @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 5 -timeout 120m go tool cover -html=coverage.out -o coverage.html # Default set of integration tests to run for ZscalerOne @@ -118,7 +118,7 @@ integration_tests := $(subst $(space),\|,$(INTEGRATION_TESTS)) # Target to run integration tests for ZscalerOne test\:integration\:zscalerone: @echo "Running integration tests for ZscalerOne..." - @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 1 -timeout 120m -run ^$(integration_tests)$$ + @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 5 -timeout 120m -run ^$(integration_tests)$$ go tool cover -html=coverage.out -o coverage.html # Default set of integration tests to run for ZscalerOne @@ -190,7 +190,7 @@ integration_zs2_tests := $(subst $(space),\|,$(ZS_INTEGRATION_TESTS)) # Target to run integration tests for ZscalerTwo test\:integration\:zscalertwo: @echo "Running integration tests for ZscalerTwo..." - @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 1 -timeout 120m -run ^$(integration_zs2_tests)$$ + @TF_ACC=1 go test -v -race -cover -coverprofile=coverage.out -covermode=atomic ./zia -parallel 5 -timeout 120m -run ^$(integration_zs2_tests)$$ go tool cover -html=coverage.out -o coverage.html build13: GOOS=$(shell go env GOOS) diff --git a/docs/guides/release-notes.md b/docs/guides/release-notes.md index b1fdb9f..be1e3db 100644 --- a/docs/guides/release-notes.md +++ b/docs/guides/release-notes.md @@ -35,6 +35,8 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi - `longitude` - (Number) The longitude coordinate of the GRE tunnel source. - `subcloud` - (String) The longitude coordinate of the GRE tunnel source. +- [PR #366](https://github.com/zscaler/terraform-provider-zia/pull/366) - Added centralized semaphore functionality to manipulate concurrent request limitations. + ## 3.0.1 (August, 13 2024) ### Notes @@ -44,11 +46,11 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fixes -- [PR #365](https://github.com/zscaler/terraform-provider-zia/365) - Fixed `ports` attribute in `zia_location_management` resource to support `TypeSet` with elements of `TypeInt`. +- [PR #365](https://github.com/zscaler/terraform-provider-zia/pull/365) - Fixed `ports` attribute in `zia_location_management` resource to support `TypeSet` with elements of `TypeInt`. ### Documentation -- [PR #365](https://github.com/zscaler/terraform-provider-zia/365) - Updated documentation for resources: `zia_location_management` and `zia_cloud_app_control_rule` +- [PR #365](https://github.com/zscaler/terraform-provider-zia/pull/365) - Updated documentation for resources: `zia_location_management` and `zia_cloud_app_control_rule` ## 3.0.0 (August, 12 2024) @@ -59,15 +61,15 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhancements -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Added new resource and datasource `zia_cloud_app_control_rule` for Cloud Application Control rule management. -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Added new datasource `zia_dlp_dictionary_predefined_identifiers` to retrieve DLP Dictionary Hierarchical Identifiers. The information can be used when configuring DLP Dictionary resource attribute `hierarchical_identifiers` to clone predefined dictionaries. -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Added new attribute `hierarchical_identifiers` to `zia_dlp_dictionaries` resource. -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Enhanced `zia_security_settings` to support maximum number of blacklist urls. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Added new resource and datasource `zia_cloud_app_control_rule` for Cloud Application Control rule management. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Added new datasource `zia_dlp_dictionary_predefined_identifiers` to retrieve DLP Dictionary Hierarchical Identifiers. The information can be used when configuring DLP Dictionary resource attribute `hierarchical_identifiers` to clone predefined dictionaries. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Added new attribute `hierarchical_identifiers` to `zia_dlp_dictionaries` resource. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Enhanced `zia_security_settings` to support maximum number of blacklist urls. ### Bug Fixes -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Added Semaphore retry logic to resource ``zia_url_categories`` to assist with rate limiting management. -- [PR #361](https://github.com/zscaler/terraform-provider-zia/361) - Fixed `ports` attribute in `zia_location_management` resource to support `TypeList`. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Added Semaphore retry logic to resource ``zia_url_categories`` to assist with rate limiting management. +- [PR #361](https://github.com/zscaler/terraform-provider-zia/pull/361) - Fixed `ports` attribute in `zia_location_management` resource to support `TypeList`. ## 2.91.4 (July, 3 2024) @@ -78,7 +80,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fix -- [PR #357](https://github.com/zscaler/terraform-provider-zia/357) - Fixed ``zia_url_filtering_rules`` drift due to attribute conversion ``validatidy_start_time`` and ``validity_end_time``. +- [PR #357](https://github.com/zscaler/terraform-provider-zia/pull/357) - Fixed ``zia_url_filtering_rules`` drift due to attribute conversion ``validatidy_start_time`` and ``validity_end_time``. ## 2.91.3 (July, 2 2024) @@ -89,8 +91,8 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fix -- [PR #356](https://github.com/zscaler/terraform-provider-zia/356) - Fixed ``zia_url_filtering_rules`` schema validation to ensure proper validation during plan and apply stages. -- [PR #356](https://github.com/zscaler/terraform-provider-zia/356) - Fixed ``zia_location_management`` drift due to missing `state` attribute in the READ function. +- [PR #356](https://github.com/zscaler/terraform-provider-zia/pull/356) - Fixed ``zia_url_filtering_rules`` schema validation to ensure proper validation during plan and apply stages. +- [PR #356](https://github.com/zscaler/terraform-provider-zia/pull/356) - Fixed ``zia_location_management`` drift due to missing `state` attribute in the READ function. ## 2.91.2 (July, 2 2024) @@ -101,7 +103,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fix -- [PR #356](https://github.com/zscaler/terraform-provider-zia/356) - Fixed ``zia_url_filtering_rules`` schema validation to ensure proper validation during plan and apply stages. +- [PR #356](https://github.com/zscaler/terraform-provider-zia/pull/356) - Fixed ``zia_url_filtering_rules`` schema validation to ensure proper validation during plan and apply stages. ## 2.91.1 (June, 29 2024) @@ -112,8 +114,8 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fix -- [PR #354](https://github.com/zscaler/terraform-provider-zia/354) - Fixed go.mod and go.sum -- [PR #354](https://github.com/zscaler/terraform-provider-zia/354) - Fixed computed attributes in the schema +- [PR #354](https://github.com/zscaler/terraform-provider-zia/pull/354) - Fixed go.mod and go.sum +- [PR #354](https://github.com/zscaler/terraform-provider-zia/pull/354) - Fixed computed attributes in the schema ## 2.91.0 (June, 19 2024) @@ -124,7 +126,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### BREAKING CHANGES and ENHACEMENTS -- [PR #350](https://github.com/zscaler/terraform-provider-zia/350) +- [PR #350](https://github.com/zscaler/terraform-provider-zia/pull/350) - `zia_url_filtering_rules` - The provider now explicitly validates during the plan and apply stages which attributes can be set based on the `action` value. - `zia_url_filtering_rules` - The provider now allows for the use of `RFC1123` date and time format i.e `Sun, 16 Jun 2024 15:04:05 UTC` when setting the attributes `validity_start_time` and `validity_end_time` instead of the native epoch unix format. @@ -139,7 +141,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Internal Changes -- [PR #350](https://github.com/zscaler/terraform-provider-zia/350) - Upgraded to [Zscaler-SDK-GO](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.61.0). The upgrade supports easier ZIA API Client instantiation for existing and new resources. +- [PR #350](https://github.com/zscaler/terraform-provider-zia/pull/350) - Upgraded to [Zscaler-SDK-GO](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.61.0). The upgrade supports easier ZIA API Client instantiation for existing and new resources. - [PR #350](https://github.com/zscaler/terraform-provider-zpa/pull/350) Upgraded ``releaser.yml`` to [GoReleaser v6](https://github.com/goreleaser/goreleaser-action/releases/tag/v6.0.0) ## 2.9.1 (June, 14 2024) @@ -151,8 +153,8 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Internal Changes -- [PR #350](https://github.com/zscaler/terraform-provider-zia/350) - Upgraded to [Zscaler-SDK-GO](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.61.0). The upgrade supports easier ZIA API Client instantiation for existing and new resources. -- [PR #350](https://github.com/zscaler/terraform-provider-zpa/pull/350) Upgraded ``releaser.yml`` to [GoReleaser v6](https://github.com/goreleaser/goreleaser-action/releases/tag/v6.0.0) +- [PR #350](https://github.com/zscaler/terraform-provider-zia/pull/350) - Upgraded to [Zscaler-SDK-GO](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.61.0). The upgrade supports easier ZIA API Client instantiation for existing and new resources. +- [PR #350](https://github.com/zscaler/terraform-provider-zpa/pull/pull/350) Upgraded ``releaser.yml`` to [GoReleaser v6](https://github.com/goreleaser/goreleaser-action/releases/tag/v6.0.0) ## 2.9.0 (May, 22 2024) - BREAKING CHANGE @@ -163,10 +165,10 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Bug Fixes - BREAKING CHANGE -- [PR #345](https://github.com/zscaler/terraform-provider-zia/345) - The attribute `ocr_enabled` has been deprecated at the upstream API and is no longer accepted. The OCR feature must be enabled via the [DLP Advanced Settings](https://help.zscaler.com/zia/configuring-dlp-advanced-settings). +- [PR #345](https://github.com/zscaler/terraform-provider-zia/pull/345) - The attribute `ocr_enabled` has been deprecated at the upstream API and is no longer accepted. The OCR feature must be enabled via the [DLP Advanced Settings](https://help.zscaler.com/zia/configuring-dlp-advanced-settings). **NOTE** DLP engines support OCR scanning of `PNG`, `JPEG`, `TIFF`, and `BMP` files. -- [PR #345](https://github.com/zscaler/terraform-provider-zia/345) - Implemented Fix for `zia_dlp_web_rules` for new attributes `parent_rule` and `sub_rules`. A parent rule must be configured with rank 0 and prior to any potential subrule. It is not possible to add existing rules as as subrules under the parent rule. +- [PR #345](https://github.com/zscaler/terraform-provider-zia/pull/345) - Implemented Fix for `zia_dlp_web_rules` for new attributes `parent_rule` and `sub_rules`. A parent rule must be configured with rank 0 and prior to any potential subrule. It is not possible to add existing rules as as subrules under the parent rule. ## 2.8.31 (May, 21 2024) @@ -179,7 +181,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi - [PR #344](https://github.com/zscaler/terraform-provider-zia/344) - Fixed `id` conversion for the resource `zia_traffic_forwarding_vpn_credentials` to ensure proper state file setting. -- [PR #344](https://github.com/zscaler/terraform-provider-zia/344) - Upgraded to [Zscaler-SDK-GO v2.5.2](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.5.2) +- [PR #344](https://github.com/zscaler/terraform-provider-zia/pull/344) - Upgraded to [Zscaler-SDK-GO v2.5.2](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.5.2) ## 2.8.3 (May, 7 2024) @@ -190,8 +192,8 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhancements -- [PR #340](https://github.com/zscaler/terraform-provider-zia/340) - Added new ZIA URL Filtering Rule attribute `source_ip_groups` to resources: `zia_url_filtering_rules` and `zia_dlp_web_rules` -- [PR #340](https://github.com/zscaler/terraform-provider-zia/340) - Upgraded to [Zscaler-GO-SDK v2.5.0](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.5.0) +- [PR #340](https://github.com/zscaler/terraform-provider-zia/pull/340) - Added new ZIA URL Filtering Rule attribute `source_ip_groups` to resources: `zia_url_filtering_rules` and `zia_dlp_web_rules` +- [PR #340](https://github.com/zscaler/terraform-provider-zia/pull/340) - Upgraded to [Zscaler-GO-SDK v2.5.0](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.5.0) ## 2.8.21 (April, 8 2024) @@ -202,7 +204,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhancements -- [PR #336](https://github.com/zscaler/terraform-provider-zia/336) - Upgraded provider to [Zscaler-SDK-GO v2.4.35](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.4.35) +- [PR #336](https://github.com/zscaler/terraform-provider-zia/pull/336) - Upgraded provider to [Zscaler-SDK-GO v2.4.35](https://github.com/zscaler/zscaler-sdk-go/releases/tag/v2.4.35) ## 2.8.2 (April, 8 2024) @@ -213,7 +215,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhancements -- [PR #332](https://github.com/zscaler/terraform-provider-zia/332) - Implemented optional environment variable `ZIA_ACTIVATION` for optional configuration activation. This is an improved version of the initial release [v2.8.0](https://github.com/zscaler/terraform-provider-zia/releases/tag/v2.8.0) where activations were done implicitly for every resource. With this enhancement the activation will only occur when this environment variable is set to true. +- [PR #332](https://github.com/zscaler/terraform-provider-zia/pull/332) - Implemented optional environment variable `ZIA_ACTIVATION` for optional configuration activation. This is an improved version of the initial release [v2.8.0](https://github.com/zscaler/terraform-provider-zia/releases/tag/v2.8.0) where activations were done implicitly for every resource. With this enhancement the activation will only occur when this environment variable is set to true. ## 2.8.1 (March, 27 2024) @@ -235,11 +237,11 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhacements -- [PR #330](https://github.com/zscaler/terraform-provider-zia/330) - Implemented auto activation functionality to all supported resources. Configurations will now be activated during `CREATE`, `UPDATE` AND `DELETE` actions when executing `terraform apply` or `terraform destroy`, which removes the need of out of band activation or the use of the resource: `zia_activation_status`. +- [PR #330](https://github.com/zscaler/terraform-provider-zia/pull/330) - Implemented auto activation functionality to all supported resources. Configurations will now be activated during `CREATE`, `UPDATE` AND `DELETE` actions when executing `terraform apply` or `terraform destroy`, which removes the need of out of band activation or the use of the resource: `zia_activation_status`. ### Fixes -- [PR #330](https://github.com/zscaler/terraform-provider-zia/330) - Fixed `zia_user_management` resource to support activation pre and post user enrolment using `BASIC` authentication method. +- [PR #330](https://github.com/zscaler/terraform-provider-zia/pull/330) - Fixed `zia_user_management` resource to support activation pre and post user enrolment using `BASIC` authentication method. ## 2.7.33 (March, 6 2024) @@ -250,7 +252,7 @@ Track all ZIA Terraform provider's releases. New resources, features, and bug fi ### Enhacements -- [PR #325](https://github.com/zscaler/terraform-provider-zia/325) Updated [support guide](/docs/guides/support.md) with new Zscaler support model. +- [PR #325](https://github.com/zscaler/terraform-provider-zia/pull/325) Updated [support guide](/docs/guides/support.md) with new Zscaler support model. - [PR #325](https://github.com/zscaler/terraform-provider-zia/pull/325) - Added support to import of the following resources: - ``zia_auth_settings_urls`` - ``zia_sandbox_behavioral_analysis`` diff --git a/zia/common/version.go b/zia/common/version.go index 94d47a4..8b9bbea 100644 --- a/zia/common/version.go +++ b/zia/common/version.go @@ -1,6 +1,6 @@ package common -var version = "3.0.0" +var version = "3.0.2" // Version returns version of provider func Version() string { diff --git a/zia/resource_zia_auth_settings_urls.go b/zia/resource_zia_auth_settings_urls.go index 11c9bc4..80df55b 100644 --- a/zia/resource_zia_auth_settings_urls.go +++ b/zia/resource_zia_auth_settings_urls.go @@ -68,6 +68,11 @@ func expandAuthSettingsUrls(d *schema.ResourceData) user_authentication_settings } func resourceAuthSettingsUrlsCreate(d *schema.ResourceData, m interface{}) error { + + // Acquire semaphore before making an API request + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done + zClient := m.(*Client) service := zClient.user_authentication_settings @@ -93,6 +98,11 @@ func resourceAuthSettingsUrlsCreate(d *schema.ResourceData, m interface{}) error } func resourceAuthSettingsUrlsUpdate(d *schema.ResourceData, m interface{}) error { + + // Acquire semaphore before making an API request + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done + zClient := m.(*Client) service := zClient.user_authentication_settings diff --git a/zia/resource_zia_dlp_web_rules_test.go b/zia/resource_zia_dlp_web_rules_test.go index 78bdbb8..baaf109 100644 --- a/zia/resource_zia_dlp_web_rules_test.go +++ b/zia/resource_zia_dlp_web_rules_test.go @@ -19,19 +19,16 @@ func TestAccResourceDlpWebRules_Basic(t *testing.T) { var rules dlp_web_rules.WebDLPRules resourceTypeAndName, _, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.DLPWebRules) - initialName := "tf-acc-test-" + generatedName - updatedName := "tf-updated-" + generatedName - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckDlpWebRulesDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, initialName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState), + Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, generatedName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState), Check: resource.ComposeTestCheckFunc( testAccCheckDlpWebRulesExists(resourceTypeAndName, &rules), - resource.TestCheckResourceAttr(resourceTypeAndName, "name", initialName), + resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName), resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPWebRuleDesc), resource.TestCheckResourceAttr(resourceTypeAndName, "action", variable.DLPRuleResourceAction), resource.TestCheckResourceAttr(resourceTypeAndName, "state", variable.DLPRuleResourceState), @@ -43,10 +40,10 @@ func TestAccResourceDlpWebRules_Basic(t *testing.T) { // Update test { - Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, updatedName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState), + Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, generatedName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState), Check: resource.ComposeTestCheckFunc( testAccCheckDlpWebRulesExists(resourceTypeAndName, &rules), - resource.TestCheckResourceAttr(resourceTypeAndName, "name", updatedName), + resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName), resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPWebRuleDesc), resource.TestCheckResourceAttr(resourceTypeAndName, "action", variable.DLPRuleResourceAction), resource.TestCheckResourceAttr(resourceTypeAndName, "state", variable.DLPRuleResourceState), @@ -113,22 +110,10 @@ func testAccCheckDlpWebRulesExists(resource string, rule *dlp_web_rules.WebDLPRu apiClient := testAccProvider.Meta().(*Client) service := apiClient.dlp_web_rules - var receivedRule *dlp_web_rules.WebDLPRules - - // Integrate retry here - retryErr := RetryOnError(func() error { - var innerErr error - receivedRule, innerErr = dlp_web_rules.Get(service, id) - if innerErr != nil { - return fmt.Errorf("failed fetching resource %s. Recevied error: %s", resource, innerErr) - } - return nil - }) - - if retryErr != nil { - return retryErr + receivedRule, err := dlp_web_rules.Get(service, id) + if err != nil { + return fmt.Errorf("failed fetching resource %s. Recevied error: %s", resource, err) } - *rule = *receivedRule return nil } @@ -184,12 +169,12 @@ data "zia_dlp_engines" "this" { } resource "%s" "%s" { - name = "%s" + name = "tf-acc-test-%s" description = "%s" action = "%s" state = "%s" order = 1 - rank = 0 + rank = 7 protocols = ["FTP_RULE", "HTTPS_RULE", "HTTP_RULE"] without_content_inspection = true file_types = [ "ALL_OUTBOUND" ] diff --git a/zia/resource_zia_security_policy_settings.go b/zia/resource_zia_security_policy_settings.go index 9e8d973..ce98908 100644 --- a/zia/resource_zia_security_policy_settings.go +++ b/zia/resource_zia_security_policy_settings.go @@ -74,6 +74,11 @@ func expandSecurityPolicySettings(d *schema.ResourceData) security_policy_settin } func resourceSecurityPolicySettingsCreate(d *schema.ResourceData, m interface{}) error { + + // Acquire semaphore before making an API request + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done + zClient := m.(*Client) service := zClient.security_policy_settings listUrls := expandSecurityPolicySettings(d) @@ -99,6 +104,11 @@ func resourceSecurityPolicySettingsCreate(d *schema.ResourceData, m interface{}) } func resourceSecurityPolicySettingsUpdate(d *schema.ResourceData, m interface{}) error { + + // Acquire semaphore before making an API request + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done + zClient := m.(*Client) service := zClient.security_policy_settings listUrls := expandSecurityPolicySettings(d) diff --git a/zia/resource_zia_url_categories.go b/zia/resource_zia_url_categories.go index f768e1c..a9d5a46 100644 --- a/zia/resource_zia_url_categories.go +++ b/zia/resource_zia_url_categories.go @@ -13,7 +13,7 @@ import ( ) // Allows only one API request at a time -var urlCategoriesSemaphore = make(chan struct{}, 1) +// var urlCategoriesSemaphore = make(chan struct{}, 1) func resourceURLCategories() *schema.Resource { return &schema.Resource{ @@ -198,8 +198,8 @@ func resourceURLCategories() *schema.Resource { func resourceURLCategoriesCreate(d *schema.ResourceData, m interface{}) error { // Acquire semaphore before making an API request - urlCategoriesSemaphore <- struct{}{} - defer func() { <-urlCategoriesSemaphore }() // Release semaphore after the request is done + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done zClient := m.(*Client) service := zClient.urlcategories @@ -299,8 +299,8 @@ func flattenScopesLite(scopes *urlcategories.URLCategory) []interface{} { func resourceURLCategoriesUpdate(d *schema.ResourceData, m interface{}) error { // Acquire semaphore before making an API request - urlCategoriesSemaphore <- struct{}{} - defer func() { <-urlCategoriesSemaphore }() // Release semaphore after the request is done + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done zClient := m.(*Client) service := zClient.urlcategories diff --git a/zia/utils.go b/zia/utils.go index db41a6b..14f9e2e 100644 --- a/zia/utils.go +++ b/zia/utils.go @@ -278,3 +278,27 @@ func isSingleDigitDay(timeStr string) bool { day := parts[1] return len(day) == 1 } + +// Global semaphore for controlling concurrent API requests +var apiSemaphore = make(chan struct{}, 1) // Default to 1, meaning only 1 API request at a time + +// SetSemaphoreSize allows adjusting the size of the semaphore globally +func SetSemaphoreSize(size int) { + apiSemaphore = make(chan struct{}, size) +} + +// WithSemaphore handles acquiring and releasing a semaphore around an API call. +func WithSemaphore(apiCall func() error) error { + // Acquire semaphore before making an API request + apiSemaphore <- struct{}{} + defer func() { <-apiSemaphore }() // Release semaphore after the request is done + + // Execute the actual API call + err := apiCall() + if err != nil { + log.Printf("[ERROR] API call failed: %v", err) + return err + } + + return nil +} diff --git a/zia/version.go b/zia/version.go index 19708fa..9df9aad 100644 --- a/zia/version.go +++ b/zia/version.go @@ -1,4 +1,4 @@ package zia // ProviderVersion is set at build-time in the release process -var ProviderVersion = "3.0.0" +var ProviderVersion = "3.0.2"