I’m trying to pass of list of Azure virtual machines to create by way of a variable to the root main.tf. However, I keep getting this error. I even consulted ChatGPT 4 and it produced the exact same code.
Here is the error:
│ The given value is not suitable for var.virtual_machines declared at variables.tf:44,1-28: element 0: attribute
│ "source_image_reference": list of object required.
Here is the definition of the variable in the variables.tf used in the root main.tf:
variable "virtual_machines" {
description = "A list of virtual machines to create."
type = list(object({
name = string
resource_group_name = string
location = string
size = string
admin_username = string
admin_password = string
availability_set = string
subnet_name = string
os_disk = list(object({
caching = string
storage_account_type = string
disk_size_gb = number
}))
source_image_reference = list(object({
publisher = string
offer = string
sku = string
version = string
}))
}))
default = []
}
Here is the value of the variable in the terraform.auto.tfvars file:
virtual_machines = [
{
name = "vm-dc1-eastus-001"
resource_group_name = "rg-servers-eastus-001"
location = "eastus"
size = "Standard_DS1_v2"
admin_username = ""
admin_password = ""
availability_set = "avb-dcs-eastus-001"
subnet_name = "snet-dcs-eastus-001"
os_disk = {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
disk_size_gb = 127
}
source_image_reference = {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter" # Server2022 to be added
version = "latest"
}
}
]
I’m not sure what exactly is wrong, any help would be greatly appreciated!