尝试有条件地运行模块。
期望:仅当 env 不等于 prd 时运行模块
module "database_diagnostic_eventhub_setting" {
count = var.env != "prd" ? 1 : 0 // run block if condition is satisfied
source = "git::https://git_url//modules/...."
target_ids = [
"${data.terraform_remote_state.database.outputs.server_id}"
]
environment = "${var.environment}-database-eventhub"
destination = data.azurerm_eventhub_namespace_authorization_rule.event_hub.id
eventhub_name = var.eventhub_name
logs = [
"PostgreSQLLogs",
"QueryStoreWaitStatistics"
]
}
错误:
The name "count" is reserved for use in a future version of Terraform.
您需要使用 Terraform v0.13 或更高版本才能使用count
或for_each
在module
块内。
如果您无法从 Terraform v0.12 升级,那么在支持模块重复之前的旧方法是向模块添加一个变量以指定对象计数:
variable "instance_count" {
type = number
}
...然后在您的模块中添加count
到每个资源:
resource "example" "example" {
count = var.instance_count
}
但是,如果你能升级对terraform现在V0.13那么我强烈建议这样做,而不是使用上述解决办法,因为升级到使用模块级count
后,与已创建的对象,是相当涉及运行的繁琐过程terraform state mv
的该模块中的每个资源。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句