我请求为不同的服务器创建多个 VM,例如:
{
"type" = "ansibleserver"
"size" = "Standard_DC2s"
"count" = 2
},
{
"type" = "frontendserver"
"size" = "Standard_DC2s"
"count" = 2
},
{
"type" = "backendserver"
"size" = "Standard_L8s_v2"
"count" = 3
}
Run Code Online (Sandbox Code Playgroud)
对于所有 3 种服务器,我必须以不同的大小和数量创建它们,现在我只能以一种非常糟糕的方式来做到这一点:
resource "azurerm_virtual_machine" "ansibleserver" {
count = "${lookup(var.ansibleserver, "count")}"
name =
......
}
resource "azurerm_virtual_machine" "frontendserver" {
count = "${lookup(var.frontendserver, "count")}"
name =
......
}
Run Code Online (Sandbox Code Playgroud)
然后如果有新的需求进来,我不仅需要改变变量,还要改变脚本,太复杂了。有什么办法可以更体面地改变整个创建过程,比如代码中的for循环?