diff --git a/quickstart/101-cosmos-db-free-tier/main.tf b/quickstart/101-cosmos-db-free-tier/main.tf index 195dc39d..be34548e 100644 --- a/quickstart/101-cosmos-db-free-tier/main.tf +++ b/quickstart/101-cosmos-db-free-tier/main.tf @@ -1,16 +1,16 @@ resource "azurerm_resource_group" "example" { - name = var.resource_group_name + name = "${random_pet.prefix.id}-rg" location = var.location } resource "azurerm_cosmosdb_account" "example" { - name = var.cosmosdb_account_name + name = "${random_pet.prefix.id}-cosmosdb-account" location = var.cosmosdb_account_location resource_group_name = azurerm_resource_group.example.name offer_type = "Standard" kind = "GlobalDocumentDB" enable_automatic_failover = false - enable_free_tier = true + enable_free_tier = true geo_location { location = var.location failover_priority = 0 @@ -25,18 +25,18 @@ resource "azurerm_cosmosdb_account" "example" { ] } -resource "azurerm_cosmosdb_sql_database" "example" { - name = var.cosmosdb_sqldb_name +resource "azurerm_cosmosdb_sql_database" "main" { + name = "${random_pet.prefix.id}-cosmosdb-sqldb" resource_group_name = azurerm_resource_group.example.name account_name = azurerm_cosmosdb_account.example.name throughput = var.throughput } resource "azurerm_cosmosdb_sql_container" "example" { - name = var.sql_container_name + name = "${random_pet.prefix.id}-sql-container" resource_group_name = azurerm_resource_group.example.name account_name = azurerm_cosmosdb_account.example.name - database_name = azurerm_cosmosdb_sql_database.example.name + database_name = azurerm_cosmosdb_sql_database.main.name partition_key_path = "/definition/id" partition_key_version = 1 throughput = var.throughput @@ -61,3 +61,8 @@ resource "azurerm_cosmosdb_sql_container" "example" { paths = ["/definition/idlong", "/definition/idshort"] } } + +resource "random_pet" "prefix" { + prefix = var.prefix + length = 1 +} \ No newline at end of file diff --git a/quickstart/101-cosmos-db-free-tier/outputs.tf b/quickstart/101-cosmos-db-free-tier/outputs.tf index 7f78abd8..eeb83014 100644 --- a/quickstart/101-cosmos-db-free-tier/outputs.tf +++ b/quickstart/101-cosmos-db-free-tier/outputs.tf @@ -3,5 +3,5 @@ output "cosmosdb_account_id" { } output "cosmosdb_sql_database_id" { - value = azurerm_cosmosdb_sql_database.example.id + value = azurerm_cosmosdb_sql_database.main.id } \ No newline at end of file diff --git a/quickstart/101-cosmos-db-free-tier/providers.tf b/quickstart/101-cosmos-db-free-tier/providers.tf index 47306772..dc42605e 100644 --- a/quickstart/101-cosmos-db-free-tier/providers.tf +++ b/quickstart/101-cosmos-db-free-tier/providers.tf @@ -1,8 +1,14 @@ terraform { + required_version = ">= 1.0" + required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">=3.0.0" + version = ">= 3.0, < 4.0" + } + random = { + source = "hashicorp/random" + version = ">= 3.0" } } } diff --git a/quickstart/101-cosmos-db-free-tier/variables.tf b/quickstart/101-cosmos-db-free-tier/variables.tf index 7387aa38..f804d68b 100644 --- a/quickstart/101-cosmos-db-free-tier/variables.tf +++ b/quickstart/101-cosmos-db-free-tier/variables.tf @@ -1,35 +1,24 @@ -variable "resource_group_name" { +variable "prefix" { type = string - description = "Resource group name" + default = "cosmos-db-free-tier" + description = "Prefix of the resource name" } variable "location" { type = string + default = "eastus" description = "Resource group location" } -variable "cosmosdb_account_name" { - type = string - description = "Cosmos db account name" -} - variable "cosmosdb_account_location" { type = string + default = "eastus" description = "Cosmos db account location" } -variable "cosmosdb_sqldb_name" { - type = string - description = "value" -} - -variable "sql_container_name" { - type = string - description = "SQL API container name." -} - variable "throughput" { type = number + default = 400 description = "Cosmos db database throughput" validation { condition = var.throughput >= 400 && var.throughput <= 1000000