Can we use for loop or something to create multiple things

Hi All,

I am new to terraform and learning about HCL.
My concern is how to I could create multiple resources by passing them into variable.

Like if I want to create multiple VMs then how could I create them in one go.

I tried with this, giving all the name in one varilable.

variable “vm_names” {
description = “Create IAM users with these names”
type = list(string)
default = [“TESTAPP06G”, “TESTAPP07G”, “TESTAPP08G”, “TESTAPP09G”]
}

and then I am trying to calling them in vm.tf file.

resource "azurerm_virtual_machine” “myterraformvm” {
count = length(var.vm_names)
name = “${var.vm_names}[count.index]”

location = “${var.location}”

resource_group_name = “${data.azurerm_resource_group.net.name}”
network_interface_ids = [azurerm_network_interface.myterraformnic.id[count.index]]
vm_size = “Standard_D8_v3”
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true

But it didn’t work I am getting error for “network_interface_ids” and not sure if this is right method to achieve my goal.

You could see my entire code on below link :-1:

Looking forward to replies and help,

Thanks in advance.