From 2b6329ef417ccb941126bbef2645d107d0130eb6 Mon Sep 17 00:00:00 2001 From: Neil Ye Date: Tue, 21 Nov 2023 15:43:41 +0800 Subject: [PATCH] `azurerm_cosmosdb_postgresql_cluster` - Mark `coordinator_storage_quota_in_mb` and `coordinator_vcore_count` as `optional` (#23938) * azurerm_cosmosdb_postgresql_cluster - Mark coordinator_storage_quota_in_mb and coordinator_vcore_count as optional * update code * update code --- .../cosmosdb_postgresql_cluster_resource.go | 65 +++++++++++-------- ...smosdb_postgresql_cluster_resource_test.go | 7 +- .../cosmosdb_postgresql_cluster.html.markdown | 12 ++-- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go index 7cfa28c340f2..e7522723b3ea 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go @@ -83,30 +83,6 @@ func (r CosmosDbPostgreSQLClusterResource) Arguments() map[string]*pluginsdk.Sch "location": commonschema.Location(), - "coordinator_storage_quota_in_mb": { - Type: pluginsdk.TypeInt, - Required: true, - ValidateFunc: validation.All( - validation.IntBetween(32768, 16777216), - validation.IntDivisibleBy(1024), - ), - }, - - "coordinator_vcore_count": { - Type: pluginsdk.TypeInt, - Required: true, - ValidateFunc: validation.IntInSlice([]int{ - 1, - 2, - 4, - 8, - 16, - 32, - 64, - 96, - }), - }, - "node_count": { Type: pluginsdk.TypeInt, Required: true, @@ -165,6 +141,30 @@ func (r CosmosDbPostgreSQLClusterResource) Arguments() map[string]*pluginsdk.Sch }, false), }, + "coordinator_storage_quota_in_mb": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.All( + validation.IntBetween(32768, 16777216), + validation.IntDivisibleBy(1024), + ), + }, + + "coordinator_vcore_count": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntInSlice([]int{ + 1, + 2, + 4, + 8, + 16, + 32, + 64, + 96, + }), + }, + "ha_enabled": { Type: pluginsdk.TypeBool, Optional: true, @@ -376,10 +376,15 @@ func (r CosmosDbPostgreSQLClusterResource) Create() sdk.ResourceFunc { parameters.Properties.SourceLocation = &model.SourceLocation } - if v := model.SourceResourceId; v != "" { + switch { + case model.SourceResourceId != "": parameters.Properties.SourceResourceId = &model.SourceResourceId - } else if model.AdministratorLoginPassword == "" { + case model.AdministratorLoginPassword == "": return fmt.Errorf("`administrator_login_password` is required when `source_resource_id` isn't set") + case model.CoordinatorStorageQuotaInMb == 0: + return fmt.Errorf("`coordinator_storage_quota_in_mb` is required when `source_resource_id` isn't set") + case model.CoordinatorVCoreCount == 0: + return fmt.Errorf("`coordinator_vcore_count` is required when `source_resource_id` isn't set") } // If `shards_on_coordinator_enabled` isn't set, API would set it to `true` when `node_count` is `0`. @@ -445,10 +450,18 @@ func (r CosmosDbPostgreSQLClusterResource) Update() sdk.ResourceFunc { } if metadata.ResourceData.HasChange("coordinator_storage_quota_in_mb") { + if model.SourceResourceId == "" && model.CoordinatorStorageQuotaInMb == 0 { + return fmt.Errorf("`coordinator_storage_quota_in_mb` is required when `source_resource_id` isn't set") + } + parameters.Properties.CoordinatorStorageQuotaInMb = &model.CoordinatorStorageQuotaInMb } if metadata.ResourceData.HasChange("coordinator_vcore_count") { + if model.SourceResourceId == "" && model.CoordinatorVCoreCount == 0 { + return fmt.Errorf("`coordinator_vcore_count` is required when `source_resource_id` isn't set") + } + parameters.Properties.CoordinatorVCores = &model.CoordinatorVCoreCount } diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go index 1a6f6c982d29..15795be3953e 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go @@ -263,10 +263,11 @@ resource "azurerm_cosmosdb_postgresql_cluster" "test2" { source_location = azurerm_cosmosdb_postgresql_cluster.test.location source_resource_id = azurerm_cosmosdb_postgresql_cluster.test.id point_in_time_in_utc = azurerm_cosmosdb_postgresql_cluster.test.earliest_restore_time + node_count = 0 - coordinator_storage_quota_in_mb = 131072 - coordinator_vcore_count = 2 - node_count = 0 + lifecycle { + ignore_changes = ["coordinator_storage_quota_in_mb", "coordinator_vcore_count"] + } } `, r.basic(data), data.RandomInteger) } diff --git a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown index 695d78bf6855..991266b896f9 100644 --- a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown +++ b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown @@ -39,12 +39,6 @@ The following arguments are supported: * `location` - (Required) The Azure Region where the Azure Cosmos DB for PostgreSQL Cluster should exist. Changing this forces a new resource to be created. -* `coordinator_storage_quota_in_mb` - (Required) The coordinator storage allowed for the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `32768`, `65536`, `131072`, `262144`, `524288`, `1048576`, `2097152`, `4194304`, `8388608`, `16777216`, and `33554432`. - --> **NOTE:** More information on [the types of compute resources available for CosmosDB can be found in the product documentation](https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute) - -* `coordinator_vcore_count` - (Required) The coordinator vCore count for the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `1`, `2`, `4`, `8`, `16`, `32`, `64` and `96`. - * `node_count` - (Required) The worker node count of the Azure Cosmos DB for PostgreSQL Cluster. Possible value is between `0` and `20` except `1`. * `administrator_login_password` - (Optional) The password of the administrator login. This is required when `source_resource_id` is not set. @@ -55,6 +49,12 @@ The following arguments are supported: * `coordinator_server_edition` - (Optional) The edition of the coordinator server. Possible values are `BurstableGeneralPurpose`, `BurstableMemoryOptimized`, `GeneralPurpose` and `MemoryOptimized`. Defaults to `GeneralPurpose`. +* `coordinator_storage_quota_in_mb` - (Optional) The coordinator storage allowed for the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `32768`, `65536`, `131072`, `262144`, `524288`, `1048576`, `2097152`, `4194304`, `8388608`, `16777216`, and `33554432`. + +-> **NOTE:** More information on [the types of compute resources available for CosmosDB can be found in the product documentation](https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute) + +* `coordinator_vcore_count` - (Optional) The coordinator vCore count for the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `1`, `2`, `4`, `8`, `16`, `32`, `64` and `96`. + * `ha_enabled` - (Optional) Is high availability enabled for the Azure Cosmos DB for PostgreSQL cluster? Defaults to `false`. * `maintenance_window` - (Optional) A `maintenance_window` block as defined below.