【问题标题】:Bind fault domain to specific IP in azure and Terraform在 azure 和 Terraform 中将故障域绑定到特定 IP
【发布时间】:2017-04-30 16:08:30
【问题描述】:

我想用 teraaform 做这些事情。我将同时创建多个虚拟机,比如 10 个。 我将使用静态 IP 选项。
所以假设我的 IP 以

开头

192.168.5.4、192.168.5.5、192.168.5.6 ....等等

所以我想确保下面的 ip 应该进入同一个故障域。

说故障域 0

192.168.5.4

192.168.5.7

192.168.5.10

说故障域 1

192.168.5.5

192.168.5.8

192.168.5.11

说故障域 2

192.168.5.6

192.168.5.9

192.168.5.12

关系是 (lastnumber % 3) 相同。 我怎样才能做到这一点?

【问题讨论】:

    标签: azure terraform


    【解决方案1】:

    您可以将simple math interpolation 与以下内容一起使用:

    variable "count" {
      default = 10
    }
    
    resource "azurerm_network_interface" "test" {
        name = "${format("VM%02d-NIC1", count.index + 1)}"
        location = "West US"
        resource_group_name = "myResourceGroup"
        count = "${var.count}"
    
        ip_configuration {
            name = "${format("ipConfig-VM%02d-NIC1", count.index + 1)}"
            subnet_id = "SubNet"
            private_ip_address_allocation = "Static"
            private_ip_address = "192.168.5.${count.index + 1}"
        }
    
        tags {
            fault_domain = "${(count.index + 1) % 3}"
        }
    }
    

    然后根据您的要求创建其余的基础架构并将 NIC 分配给您的虚拟机:

    resource "azurerm_virtual_machine" "test" {
        count = "${var.count}"
        name = "${format("VM%02-test", cound.index + 1)}"
        location = "West US"
        resource_group_name = "myResourceGroup"
        network_interface_ids = ["${element(azurerm_network_interface.test, count.index).id}"]
        vm_size = "Standard_A0"
        ...
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2011-04-15
      • 2013-01-26
      • 2018-03-07
      相关资源
      最近更新 更多