From db4ac1477ed49ab022c183da45d29c3b4978dc0c Mon Sep 17 00:00:00 2001 From: Neil Ye Date: Thu, 2 Nov 2023 17:37:57 +0800 Subject: [PATCH] azurerm_cosmosdb_postgresql_cluster - Mark administrator_login_password as optional (#23750) * azurerm_cosmosdb_postgresql_cluster - Mark administrator_login_password as optional * update code * update code * update code * update code --- .../cosmosdb_postgresql_cluster_resource.go | 20 ++++++++++++------- ...smosdb_postgresql_cluster_resource_test.go | 1 - .../cosmosdb_postgresql_cluster.html.markdown | 4 ++-- 3 files changed, 15 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..7cfa28c340f2 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, @@ -378,6 +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") } // If `shards_on_coordinator_enabled` isn't set, API would set it to `true` when `node_count` is `0`. @@ -423,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 } 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..695d78bf6855 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. 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`. * `coordinator_public_ip_access_enabled` - (Optional) Is public access enabled on coordinator? Defaults to `true`.