azure - 如何通过 Terraform 创建多个虚拟机?

标签 azure terraform

我有一个为不同服务器创建多个虚拟机的请求,例如:

{
  "type"   = "ansibleserver"
  "size"   = "Standard_DC2s"
  "count" = 2
},
{
  "type"   = "frontendserver"
  "size"   = "Standard_DC2s"
  "count" = 2
},
{
  "type"   = "backendserver"
  "size"   = "Standard_L8s_v2"
  "count" = 3
}

对于所有 3 种服务器,我必须以不同的大小和数量创建它们,目前我只能以一种非常糟糕的方式来做到这一点:

resource "azurerm_virtual_machine" "ansibleserver" {
  count = "${lookup(var.ansibleserver, "count")}"

  name  = 
  ......
}

resource "azurerm_virtual_machine" "frontendserver" {
  count = "${lookup(var.frontendserver, "count")}"

  name  = 
  ......
}

然后如果有新的需求进来,我不仅要改变量,还要改脚本,太复杂了。有没有办法以更体面的方式改变整个创建过程,例如代码中的for循环?

最佳答案

引用link中提到的建议让我知道状态

这个 GitHub article应该对你有帮助

更多信息您可以引用此link中提到的建议。 .

您正在寻找这样的东西:

resource "azurerm_virtual_machine" "server" {
  name                  = "server-${count.index}"
  count                 = "${var.instance_count}"
  …
  storage_os_disk {
    name              = "server-${count.index}-os"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
} 

其他信息:azurerm_virtual_machine

Need to create multile vms in azure through terraform

请告诉我们上述内容是否有帮助或者您在此问题上需要进一步帮助。

关于azure - 如何通过 Terraform 创建多个虚拟机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57804406/

相关文章:

powershell - 用于复制所有 Web 应用程序设置的 Azure Runbook powershell 脚本

visual-studio - SSIS OData 源在 Visual Studio 2017 中工作,但在 Azure 数据工厂中运行时失败

azure - 如何用文本替换地形中的变量?

azure - Terraform - Azure 上的静态 IP 地址

azure - 从 terraform 中的字符串列表中获取子字符串

azure - 如何使用 Azure 服务总线 HTTP API 对消息设置死信

Azure Functions 开箱即用 : System.Net.Http 冲突

azure - VMSS 中的自定义扩展

azure-devops - Terraform:找不到 Azure CLI 授权配置文件。请确保已安装 Azure CLI

terraform - 在 Terraform 中生成具有两个列表的笛卡尔积