fix 101-cosmos-db-free-tier example (#160)

This commit is contained in:
Dingjia Chen 2023-02-16 19:44:57 -06:00 committed by GitHub
parent d8c965a294
commit 3e43a4eae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 26 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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"
}
}
}

View File

@ -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