Terraform – Azure:variables追加

resource "azurerm_resource_group" "HVTest1" { location = "${var.location}" name = "HVTest1.RG" } resource "azurerm_network_interface" "nic"{ name = "TestLinux-nic${count.index}" location = "${var.location}" resource_group_name = "${azurerm_resource_group.HVTest1.name}" ip_configuration{ name = "test-ipconfig" subnet_id = "${var.subnet_id}" private_ip_address_allocation = "Dynamic" #public_ip_address_id = "None" } count = 2 } resource "azurerm_virtual_machine" "TestRHEL" { count = "${var.count}" location = "${var.location}" resource_group_name = "${azurerm_resource_group.HVTest1.name}" #name = "TestRHEL-${count.index}" name = "TestRHEL-${count.index}" vm_size = "Standard_DS1_v2" network_interface_ids = ["${azurerm_network_interface.nic.*.id[count.index]}"] delete_os_disk_on_termination = true delete_data_disks_on_termination = true storage_image_reference { publisher = "Canonical" offer = "Ubuntuserver" sku = "16.04-LTS" version = "latest" } storage_os_disk { #name = "${azurerm_virtual_machine.TestLVM.*.name}-osdisk" name = "TestRHELosdisk-${format(var.count_format, var.count_offset + count.index +1)}" caching = "None" create_option = "FromImage" managed_disk_type = "Standard_LRS" } os_profile { computer_name = "TestRHEL-${count.index}" admin_username = "venihe01" admin_password = "Nielsen@1234" } storage_data_disk { name = "${TestRHEL-${count.index}-data1}" managed_disk_type = "standard_LRS" create_option = "Empty" lun = "${count.index}" disk_size_gb = "100" count = 2 } } 

您不能在storage_data_disk计数,它们只能位于顶级资源中。

您可以在资源中执行多个storage_data_disk

  resource "azurerm_virtual_machine" "TestRHEL" { storage_data_disk { name = "${azurerm_virtual_machine.TestLVM.name}-data0" managed_disk_type = "standard_LRS" create_option = "Empty" lun = "0" disk_size_gb = "100" } storage_data_disk { name = "${azurerm_virtual_machine.TestLVM.name}-data1" managed_disk_type = "standard_LRS" create_option = "Empty" lun = "1" disk_size_gb = "100" } }