I am trying to spin up multiple VMware VM’s using for_each. But I am getting Error: Argument or block definition required
Following is my configuration file:
variable “virtual_machines” {
default = [
{
name = “terraform-test-1”
number_cpus = “2”
host_name = “terraform-test-1”
},
{
name = “terraform-test-2”
number_cpus = “2”
host_name = “terraform-test-2”
},
{
name = “terraform-test-3”
number_cpus = “2”
host_name = “terraform-test-3”
},
]
}
data “vsphere_virtual_machine” “template-centos-7” {
name = “centos-7-template”
datacenter_id = “${data.vsphere_datacenter.X.id}”
}
resource “vsphere_virtual_machine” “vm-3” {
// I copied the block from
dynamic “vm” {
for_each = [for s in virtual_machines: {
name = s.name
number_cpus = s.number_cpus
host_name = s.host_name
}]
name = vm.value.name
resource_pool_id = “{data.vsphere_compute_cluster.x-cluster.resource_pool_id}"
datastore_id = "{data.vsphere_datastore.x-datastore.id}”
num_cpus = vm.value.num_cpus
memory = 1024
guest_id = “${data.vsphere_virtual_machine.template-centos-7.guest_id}”
scsi_type = “${data.vsphere_virtual_machine.template-centos-7.scsi_type}”
network_interface {
network_id = “{data.vsphere_network.x-network.id}"
# adapter_type = "{data.vsphere_virtual_machine.template.network_interface_types[0]}”
}
disk {
label = “disk0”
size = “100”
# eagerly_scrub = “{data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
# thin_provisioned = "{data.vsphere_virtual_machine.template.disks.0.thin_provisioned}”
}
clone {
template_uuid = “${data.vsphere_virtual_machine.template-centos-7.id}”
customize {
linux_options {
host_name = vm.value.host_name
domain = "x.lab"
}
network_interface {}
ipv4_gateway = "X.X.X.X"
}
}
}
How can I reuse the list of maps to provision multiple VM’s?