I have a request to create multiple VMs for different servers, for example:
{
"type" = "ansibleserver"
"size" = "Standard_DC2s"
"count" = 2
},
{
"type" = "frontendserver"
"size" = "Standard_DC2s"
"count" = 2
},
{
"type" = "backendserver"
"size" = "Standard_L8s_v2"
"count" = 3
}
For all the 3 kinds of servers, I have to create them in different sizes and counts, for now I can only do it in a pretty bad way:
resource "azurerm_virtual_machine" "ansibleserver" {
count = "${lookup(var.ansibleserver, "count")}"
name =
......
}
resource "azurerm_virtual_machine" "frontendserver" {
count = "${lookup(var.frontendserver, "count")}"
name =
......
}
Then if any new requirements coming in, I not only need to change the variables but also the script, it is too complicated. Is there any way to change the whole creation process in a more decent way, such as for-loop in code?