Azure 如何在地形中插值计数?
我正在Azure中创建许多虚拟机,其中包含腐蚀性NIC和公共IP 我可以为虚拟机创建唯一的名称没有问题:Azure 如何在地形中插值计数?,azure,terraform,Azure,Terraform,我正在Azure中创建许多虚拟机,其中包含腐蚀性NIC和公共IP 我可以为虚拟机创建唯一的名称没有问题: resource "azurerm_virtual_machine" "workernode" { count = "${var.nodeCount}" name = "workernode-${count.index +1}" 以及公众: resource "azurerm_public_ip" "AliasworkerPubIP" { count = "${va
resource "azurerm_virtual_machine" "workernode" {
count = "${var.nodeCount}"
name = "workernode-${count.index +1}"
以及公众:
resource "azurerm_public_ip" "AliasworkerPubIP" {
count = "${var.nodeCount}"
name = "workerpubip${count.index +1}"
和NIC:
resource "azurerm_network_interface" "workerNIC" {
count = "${var.nodeCount}"
name = "workerNIC.${count.index +1}"
但是我不知道如何让它工作,然后将NIC连接到刚刚创建的PublicIP
尝试了各种不同的方法,但没有任何东西是点击。。。我知道我遗漏了什么或者没有正确理解,但是什么
我尝试过的例子:
public_ip_address_id = "${azurerm_public_ip}.${format("Alias_WorkerIP%d.id", count.index +1)}"
public_ip_address_id = "${format("Alias_WorkerIP%d.id", count.index +1)}"
public_ip_address_id = "${format("azurerm_public_ip.workerpubip.%s.id", count.index +1)}"
你知道我哪里出了问题吗?我就是这样解决的:
public_ip_address_id=“${element(azurerm_public_ip.workerpubip.*.id,count.index)}”我就是这样解决的:
public_ip_address_id=“${element(azurerm_public_ip.workerpubip.*.id,count.index)}”当前推荐的表达方式是:
public_ip_address_id = "${azurerm_public_ip.workerpubip.*.id[count.index]}"
使用这个索引操作符([…]
)可以让Terraform更好地理解这意味着的依赖关系,这样,如果只需要更换一个公共IP实例,它就可以理解只需要更新一个相应的azurerm\u网络接口
当使用元素
函数时,Terraform仅“看到”azurerm_public_ip.workerpubip.*.id
表达式,保守地假设存在对所有azurerm_public_ip
id的依赖关系。当前建议的表达方式是:
public_ip_address_id = "${azurerm_public_ip.workerpubip.*.id[count.index]}"
使用这个索引操作符([…]
)可以让Terraform更好地理解这意味着的依赖关系,这样,如果只需要更换一个公共IP实例,它就可以理解只需要更新一个相应的azurerm\u网络接口
当使用元素
函数时,Terraform仅“看到”azurerm_public_ip.workerpubip.*.id
表达式,保守地假设存在对所有azurerm_public_ip
id的依赖关系。在azurerm_网络接口模块中尝试此操作
public_ip_address_id = "${element(azurerm_public_ip.main-rg__vm-ip.*.id, count.index)}"
在azurerm_公共_ip模块中
resource azurerm_public_ip main-rg__vm-ip {
count = "${var.vm_count}"
name = "${var.environment}-vm${count.index+1}-ip"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.main-rg.name}"
sku = "Basic"
allocation_method = "Dynamic"
}
在azurerm_网络_接口模块中尝试此操作
public_ip_address_id = "${element(azurerm_public_ip.main-rg__vm-ip.*.id, count.index)}"
在azurerm_公共_ip模块中
resource azurerm_public_ip main-rg__vm-ip {
count = "${var.vm_count}"
name = "${var.environment}-vm${count.index+1}-ip"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.main-rg.name}"
sku = "Basic"
allocation_method = "Dynamic"
}