From 732420170bc56a0a55d3531b8b8482c30fa16d98 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 1 Nov 2023 11:48:13 +0800 Subject: [PATCH 1/5] azurerm_cosmosdb_postgresql_cluster - Mark administrator_login_password as optional --- .../cosmos/cosmosdb_postgresql_cluster_resource.go | 14 +++++++------- .../cosmosdb_postgresql_cluster_resource_test.go | 1 - .../r/cosmosdb_postgresql_cluster.html.markdown | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go index ba8cb8467efc..c60d6439d469 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go @@ -83,13 +83,6 @@ func (r CosmosDbPostgreSQLClusterResource) Arguments() map[string]*pluginsdk.Sch "location": commonschema.Location(), - "administrator_login_password": { - Type: pluginsdk.TypeString, - Required: true, - Sensitive: true, - ValidateFunc: validation.StringLenBetween(8, 256), - }, - "coordinator_storage_quota_in_mb": { Type: pluginsdk.TypeInt, Required: true, @@ -123,6 +116,13 @@ func (r CosmosDbPostgreSQLClusterResource) Arguments() map[string]*pluginsdk.Sch ), }, + "administrator_login_password": { + Type: pluginsdk.TypeString, + Optional: true, + Sensitive: true, + ValidateFunc: validation.StringLenBetween(8, 256), + }, + "citus_version": { Type: pluginsdk.TypeString, Optional: true, diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go index 74f24cb79655..1a6f6c982d29 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource_test.go @@ -264,7 +264,6 @@ resource "azurerm_cosmosdb_postgresql_cluster" "test2" { source_resource_id = azurerm_cosmosdb_postgresql_cluster.test.id point_in_time_in_utc = azurerm_cosmosdb_postgresql_cluster.test.earliest_restore_time - administrator_login_password = "H@Sh1CoR3!" coordinator_storage_quota_in_mb = 131072 coordinator_vcore_count = 2 node_count = 0 diff --git a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown index a2d8e8c0fa85..713a57a849ad 100644 --- a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown +++ b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown @@ -39,8 +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. -* `administrator_login_password` - (Required) The password of the administrator login. - * `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) @@ -49,6 +47,8 @@ The following arguments are supported: * `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. + * `citus_version` - (Optional) The citus extension version on the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `8.3`, `9.0`, `9.1`, `9.2`, `9.3`, `9.4`, `9.5`, `10.0`, `10.1`, `10.2`, `11.0`, `11.1`, `11.2`, `11.3` and `12.1`. * `coordinator_public_ip_access_enabled` - (Optional) Is public access enabled on coordinator? Defaults to `true`. From b2e507727e00e519e7735c3b3c5468a76afeb3a7 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Nov 2023 09:18:49 +0800 Subject: [PATCH 2/5] update code --- .../services/cosmos/cosmosdb_postgresql_cluster_resource.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go index c60d6439d469..d2872b56b880 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go @@ -378,6 +378,10 @@ func (r CosmosDbPostgreSQLClusterResource) Create() sdk.ResourceFunc { if v := model.SourceResourceId; v != "" { parameters.Properties.SourceResourceId = &model.SourceResourceId + } else { + if model.AdministratorLoginPassword == "" { + return fmt.Errorf("`administrator_login_password` 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`. From 60aa1a1d4bf02c82bdfa0c376df9f9dafde50edf Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Nov 2023 09:28:03 +0800 Subject: [PATCH 3/5] update code --- .../services/cosmos/cosmosdb_postgresql_cluster_resource.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go index d2872b56b880..8e8e185e0fd3 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go @@ -378,10 +378,8 @@ func (r CosmosDbPostgreSQLClusterResource) Create() sdk.ResourceFunc { if v := model.SourceResourceId; v != "" { parameters.Properties.SourceResourceId = &model.SourceResourceId - } else { - if model.AdministratorLoginPassword == "" { - return fmt.Errorf("`administrator_login_password` is required when `source_resource_id` isn't set") - } + } else if model.AdministratorLoginPassword == "" { + return fmt.Errorf("`administrator_login_password` 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`. From 2b9dea9a9698db2dd2cad49011a1b981cf62519c Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Nov 2023 10:03:58 +0800 Subject: [PATCH 4/5] update code --- .../services/cosmos/cosmosdb_postgresql_cluster_resource.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go index 8e8e185e0fd3..7cfa28c340f2 100644 --- a/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go +++ b/internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go @@ -425,6 +425,10 @@ func (r CosmosDbPostgreSQLClusterResource) Update() sdk.ResourceFunc { } if metadata.ResourceData.HasChange("administrator_login_password") { + if model.SourceResourceId == "" && model.AdministratorLoginPassword == "" { + return fmt.Errorf("`administrator_login_password` is required when `source_resource_id` isn't set") + } + parameters.Properties.AdministratorLoginPassword = &model.AdministratorLoginPassword } From 22c18f9ef345122be389073e58b0a485a889ba64 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Nov 2023 17:12:55 +0800 Subject: [PATCH 5/5] update code --- website/docs/r/cosmosdb_postgresql_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown index 713a57a849ad..695d78bf6855 100644 --- a/website/docs/r/cosmosdb_postgresql_cluster.html.markdown +++ b/website/docs/r/cosmosdb_postgresql_cluster.html.markdown @@ -47,7 +47,7 @@ The following arguments are supported: * `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. +* `administrator_login_password` - (Optional) The password of the administrator login. This is required when `source_resource_id` is not set. * `citus_version` - (Optional) The citus extension version on the Azure Cosmos DB for PostgreSQL Cluster. Possible values are `8.3`, `9.0`, `9.1`, `9.2`, `9.3`, `9.4`, `9.5`, `10.0`, `10.1`, `10.2`, `11.0`, `11.1`, `11.2`, `11.3` and `12.1`.