From 0a2fb357783a048674efe01a850046b4682ff39e Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Mon, 24 Apr 2023 00:44:26 -0600 Subject: [PATCH 1/3] Initial Check-in... --- .../cosmos/cosmosdb_account_resource.go | 2 +- website/docs/r/cosmosdb_account.html.markdown | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 37dcebe5106b..aa7a3a3c05c8 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -243,7 +243,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Optional: true, Computed: true, ValidateFunc: validation.Any( - validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "It may start with `UserAssignedIdentity`"), + validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "user assigned identities must be in the format of: 'UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}'"), validation.StringInSlice([]string{ "FirstPartyIdentity", "SystemAssignedIdentity", diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index f6fc05527d86..9c603da0fb25 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -66,6 +66,42 @@ resource "azurerm_cosmosdb_account" "db" { } ``` +## User Assigned Identity Example Usage + +```hcl +resource "azurerm_user_assigned_identity" "example" { + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + name = "example-resource" +} + +resource "azurerm_cosmosdb_account" "example" { + name = "example-resource" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + default_identity_type = join("=", ["UserAssignedIdentity", azurerm_user_assigned_identity.example.id]) + offer_type = "Standard" + kind = "MongoDB" + + capabilities { + name = "EnableMongo" + } + + consistency_policy { + consistency_level = "Strong" + } + + geo_location { + location = "westus" + failover_priority = 0 + } + + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.example.id] + } +} +``` ## Argument Reference The following arguments are supported: @@ -88,7 +124,9 @@ The following arguments are supported: ~> **NOTE:** `create_mode` only works when `backup.type` is `Continuous`. -* `default_identity_type` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or start with `UserAssignedIdentity`. +* `default_identity_type` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or `UserAssignedIdentity`. + +~> **NOTE:** When `default_identity_type` is set to `UserAssignedIdentity` it must be in the following format: `UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}`. * `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB`, `MongoDB` and `Parse`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created. From 3491b997eda0bfd5ba92c393ca61a14e9a3df207 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 25 Apr 2023 11:06:53 -0700 Subject: [PATCH 2/3] Update website/docs/r/cosmosdb_account.html.markdown --- website/docs/r/cosmosdb_account.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 9c603da0fb25..50864e187811 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -126,7 +126,7 @@ The following arguments are supported: * `default_identity_type` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or `UserAssignedIdentity`. -~> **NOTE:** When `default_identity_type` is set to `UserAssignedIdentity` it must be in the following format: `UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}`. +~> **NOTE:** When `default_identity_type` is a `UserAssignedIdentity` it must include the User Assigned Identity ID in the following format: `UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}`. * `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB`, `MongoDB` and `Parse`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created. From 7c786468da4d47bee42cb1a6c9c3f8c275118eb2 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 25 Apr 2023 11:06:59 -0700 Subject: [PATCH 3/3] Update internal/services/cosmos/cosmosdb_account_resource.go --- internal/services/cosmos/cosmosdb_account_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index aa7a3a3c05c8..5414087d3cc1 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -243,7 +243,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Optional: true, Computed: true, ValidateFunc: validation.Any( - validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "user assigned identities must be in the format of: 'UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}'"), + validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "user assigned identity must be in the format of: 'UserAssignedIdentity=/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userAssignedIdentityName}'"), validation.StringInSlice([]string{ "FirstPartyIdentity", "SystemAssignedIdentity",