Skip to content

Commit

Permalink
azurerm_search_service:Update basic SKU partition count from 1 to 3 (h…
Browse files Browse the repository at this point in the history
…ashicorp#28105)

* Update max partition count of basic sku from 1 to 3

* Update search_service_resource_test.go to test basic sku count greater than 3

* Update search_service_resource.go

* Update search_service_resource.go

* Update readme file partition atribute

* Update search_service_resource_test.go

* Update search_service_resource.go

* Update search_service_resource_test.go

* Update search_service_resource_test.go

* Update search_service_resource_test.go

* Update search_service_data_source_test.go

* Update search_service_data_source_test.go

* Update search_service_resource_test.go
  • Loading branch information
Gnana-Bharathi-K authored Dec 4, 2024
1 parent f536cac commit 6ba6882
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
18 changes: 14 additions & 4 deletions internal/services/search/search_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...
Expand Down
23 changes: 21 additions & 2 deletions internal/services/search/search_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/search_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down

0 comments on commit 6ba6882

Please sign in to comment.