diff --git a/internal/services/search/search_service_resource.go b/internal/services/search/search_service_resource.go index 75212ce7f6b3..ce31fe1b1e5b 100644 --- a/internal/services/search/search_service_resource.go +++ b/internal/services/search/search_service_resource.go @@ -239,13 +239,19 @@ func resourceSearchServiceCreate(d *pluginsdk.ResourceData, meta interface{}) er return fmt.Errorf("'hosting_mode' can only be defined if the 'sku' field is set to the %q SKU, got %q", string(services.SkuNameStandardThree), skuName) } - // NOTE: 'partition_count' values greater than 1 are not valid for 'free' or 'basic' SKUs... + // NOTE: 'partition_count' values greater than 1 are not valid for 'free' SKU... partitionCount := int64(d.Get("partition_count").(int)) - if (skuName == services.SkuNameFree || skuName == services.SkuNameBasic) && partitionCount > 1 { + if (skuName == services.SkuNameFree) && partitionCount > 1 { return fmt.Errorf("'partition_count' values greater than 1 cannot be set for the %q SKU, got %d)", string(skuName), partitionCount) } + // NOTE: 'partition_count' values greater than 3 are not valid for 'basic' SKU... + + if (skuName == services.SkuNameBasic) && partitionCount > 3 { + return fmt.Errorf("'partition_count' values greater than 3 cannot be set for the %q SKU, got %d)", string(skuName), partitionCount) + } + // NOTE: 'standard3' services with 'hostingMode' set to 'highDensity' the // 'partition_count' must be between 1 and 3. if skuName == services.SkuNameStandardThree && partitionCount > 3 && hostingMode == services.HostingModeHighDensity { @@ -452,10 +458,14 @@ func resourceSearchServiceUpdate(d *pluginsdk.ResourceData, meta interface{}) er if d.HasChange("partition_count") { partitionCount := int64(d.Get("partition_count").(int)) - // NOTE: 'partition_count' values greater than 1 are not valid for 'free' or 'basic' SKUs... - if (pointer.From(model.Sku.Name) == services.SkuNameFree || pointer.From(model.Sku.Name) == services.SkuNameBasic) && partitionCount > 1 { + // NOTE: 'partition_count' values greater than 1 are not valid for 'free' SKUs... + if (pointer.From(model.Sku.Name) == services.SkuNameFree) && partitionCount > 1 { return fmt.Errorf("'partition_count' values greater than 1 cannot be set for the %q SKU, got %d)", pointer.From(model.Sku.Name), partitionCount) } + // NOTE: 'partition_count' values greater than 3 are not valid for 'basic' SKUs... + if (pointer.From(model.Sku.Name) == services.SkuNameBasic) && partitionCount > 3 { + return fmt.Errorf("'partition_count' values greater than 3 cannot be set for the %q SKU, got %d)", pointer.From(model.Sku.Name), partitionCount) + } // NOTE: If SKU is 'standard3' and the 'hosting_mode' is set to 'highDensity' the maximum number of partitions allowed is 3 // where if 'hosting_mode' is set to 'default' the maximum number of partitions is 12... diff --git a/internal/services/search/search_service_resource_test.go b/internal/services/search/search_service_resource_test.go index b07471953314..fade7b980eca 100644 --- a/internal/services/search/search_service_resource_test.go +++ b/internal/services/search/search_service_resource_test.go @@ -349,9 +349,28 @@ func TestAccSearchService_partitionCountInvalidBySku(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.partitionCount(data, "basic", 3), + Config: r.partitionCount(data, "basic", 4), Check: acceptance.ComposeTestCheckFunc(), - ExpectError: regexp.MustCompile("values greater than 1 cannot be set"), + ExpectError: regexp.MustCompile("values greater than 3 cannot be set"), + }, + }) +} + +func TestAccSearchService_partitionCountvalidBySkuBasic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_search_service", "test") + r := SearchServiceResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.partitionCount(data, "basic", 3), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.partitionCount(data, "basic", 4), + ExpectError: regexp.MustCompile("values greater than 3 cannot be set"), }, }) } diff --git a/website/docs/r/search_service.html.markdown b/website/docs/r/search_service.html.markdown index 1bc39909ae84..d17874f6d4f4 100644 --- a/website/docs/r/search_service.html.markdown +++ b/website/docs/r/search_service.html.markdown @@ -100,7 +100,7 @@ The following arguments are supported: * `local_authentication_enabled` - (Optional) Specifies whether the Search Service allows authenticating using API Keys? Defaults to `true`. -* `partition_count` - (Optional) Specifies the number of partitions which should be created. This field cannot be set when using a `free` or `basic` sku ([see the Microsoft documentation](https://learn.microsoft.com/azure/search/search-sku-tier)). Possible values include `1`, `2`, `3`, `4`, `6`, or `12`. Defaults to `1`. +* `partition_count` - (Optional) Specifies the number of partitions which should be created. This field cannot be set when using a `free` sku ([see the Microsoft documentation](https://learn.microsoft.com/azure/search/search-sku-tier)). Possible values include `1`, `2`, `3`, `4`, `6`, or `12`. Defaults to `1`. -> **NOTE:** when `hosting_mode` is set to `highDensity` the maximum number of partitions allowed is `3`.