Fix concurrent error in cosmosdb example (#191)

* fix concurrent error in cosmosdb example

* change to random_string to reduce the collision rate

* fix 101-cosmos-db-free-tier account name too long issue

---------

Co-authored-by: zjhe <hezijie@microsoft.com>
This commit is contained in:
lonegunmanb
2023-03-15 08:49:16 +08:00
committed by GitHub
parent c4d4d696a5
commit 2f73fa933f
13 changed files with 73 additions and 8 deletions

View File

@ -3,8 +3,21 @@ resource "azurerm_resource_group" "example" {
location = var.location
}
resource "random_string" "db_account_name" {
count = var.cosmosdb_account_name == null ? 1 : 0
length = 20
upper = false
special = false
numeric = false
}
locals {
cosmosdb_account_name = try(random_string.db_account_name[0].result, var.cosmosdb_account_name)
}
resource "azurerm_cosmosdb_account" "example" {
name = var.cosmosdb_account_name
name = local.cosmosdb_account_name
location = var.cosmosdb_account_location
resource_group_name = azurerm_resource_group.example.name
offer_type = "Standard"