Skip to content

Commit

Permalink
azurerm_cosmosdb_postgresql_cluster - Mark `coordinator_storage_quo…
Browse files Browse the repository at this point in the history
…ta_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
  • Loading branch information
neil-yechenwei committed Nov 21, 2023
1 parent ab26b85 commit 2b6329e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
65 changes: 39 additions & 26 deletions internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
12 changes: 6 additions & 6 deletions website/docs/r/cosmosdb_postgresql_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 2b6329e

Please sign in to comment.