【发布时间】:2021-11-05 20:21:16
【问题描述】:
我在 Azure cosmosdb 数据库中添加自动缩放设置,我的问题不是我们的所有数据库都需要自动缩放,只有选择的数据库需要自动缩放其余都是手动的。我将无法在同一资源中指定 autoscalse 块,因为这两者之间存在冲突。所以我想到了使用计数,但我将无法仅为其中一个数据库运行资源块。下面的例子
变量
variable "databases" {
description = "The list of Cosmos DB SQL Databases."
type = list(object({
name = string
throughput = number
autoscale = bool
max_throughput = number
}))
default = [
{
name = "testcoll1"
throughput = 400
autoscale = false
max_throughput = 0
},
{
name = "testcoll2"
throughput = 400
autoscale = true
max_throughput = 1000
}
]
}
第一个我不需要自动缩放,下一个我需要。我的 main.tf 代码
resource "azurerm_cosmosdb_mongo_database" "database_manual" {
count = length(var.databases)
name = var.databases[count.index].name
resource_group_name = azurerm_cosmosdb_account.cosmosdb.resource_group_name
account_name = local.account_name
throughput = var.databases[count.index].throughput
}
resource "azurerm_cosmosdb_mongo_database" "database_autoscale" {
count = length(var.databases)
name = var.databases[count.index].name
resource_group_name = azurerm_cosmosdb_account.cosmosdb.resource_group_name
account_name = local.account_name
autoscale_settings {
max_throughput = var.databases[count.index].max_throughput
}
}
首先我想运行两个块,一个有刻度,一个没有,但我无法继续,因为它需要计数
count = var.autoscale_required == true ?长度(数据库):0
在开始时,但在我的情况下,我只会在迭代时知道。我尝试在块内使用动态但出错了。
*更新 我已切换到 foreach 并能够运行该条件,但仍需要 2 个块 资源“azurerm_cosmosdb_mongo_database”“database_autoscale” 资源 "azurerm_cosmosdb_mongo_database" "database_manual"
resource "azurerm_cosmosdb_mongo_database" "database_autoscale" {
for_each = {
for key, value in var.databases : key => value
if value.autoscale_required == true }
name = each.value.name
resource_group_name = azurerm_cosmosdb_account.cosmosdb.resource_group_name
account_name = local.account_name
autoscale_settings {
max_throughput = each.value.max_throughput
}
}
【问题讨论】:
标签: terraform azure-cosmosdb terraform-provider-azure azure-cosmosdb-mongoapi