fup
This commit is contained in:
parent
0293e76708
commit
b6a0147749
|
@ -8,9 +8,9 @@ variable "vms" {
|
|||
disks = map(object({
|
||||
size = string
|
||||
}))
|
||||
network_interfaces = map(object(
|
||||
network_interfaces = list(object(
|
||||
{
|
||||
name = string
|
||||
id = string
|
||||
mac = string
|
||||
}
|
||||
))
|
||||
|
@ -26,23 +26,14 @@ variable "cluster" {
|
|||
datastore_name = string
|
||||
resource_pool_name = string
|
||||
folder = string
|
||||
vnets = map(object({
|
||||
name = string
|
||||
}))
|
||||
}
|
||||
)
|
||||
description = "vSphere cluster definition"
|
||||
}
|
||||
|
||||
locals {
|
||||
vnets = flatten([
|
||||
for vm_key, vm in var.vms : [
|
||||
for vnet in vm.network_interfaces : {
|
||||
vm_key = "${vm_key}.${vm.domain}"
|
||||
name = vnet.name
|
||||
mac = vnet.mac
|
||||
}
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
data "vsphere_datacenter" "datacenter" {
|
||||
name = var.cluster.datacenter_name
|
||||
}
|
||||
|
@ -58,9 +49,9 @@ data "vsphere_resource_pool" "pool" {
|
|||
}
|
||||
|
||||
data "vsphere_network" "network" {
|
||||
count = length(local.vnets)
|
||||
for_each = var.cluster.vnets
|
||||
|
||||
name = local.vnets[count.index].name
|
||||
name = each.value.name
|
||||
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||||
}
|
||||
|
||||
|
@ -75,10 +66,12 @@ resource "vsphere_virtual_machine" "vm" {
|
|||
guest_id = each.value.guest_id
|
||||
|
||||
dynamic "network_interface" {
|
||||
for_each = { for idx, vnet in data.vsphere_network.network : idx => vnet }
|
||||
for_each = each.value.network_interfaces
|
||||
//for_each = { for idx, value in each.value.network_interfaces : idx => value }
|
||||
//for_each = { for idx, vnet in data.vsphere_network.network : idx => vnet }
|
||||
content {
|
||||
network_id = network_interface.value.id
|
||||
mac_address = local.vnets[network_interface.key].mac
|
||||
network_id = data.vsphere_network.network[network_interface.value.id].id
|
||||
mac_address = network_interface.value.mac
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,6 @@ output "shortnames" {
|
|||
value = keys(var.vms)
|
||||
}
|
||||
|
||||
output "vnets" {
|
||||
value = local.vnets
|
||||
|
||||
}
|
||||
//output "virtual_machines" {
|
||||
// value = vsphere.virtual_machine.vm //template_nic[0].computed_mac)
|
||||
//}
|
Loading…
Reference in New Issue