84 lines
1.9 KiB
Terraform
84 lines
1.9 KiB
Terraform
|
variable "vms" {
|
||
|
type = map(object(
|
||
|
{
|
||
|
domain = string
|
||
|
cpu = number
|
||
|
ram = number
|
||
|
guest_id = string
|
||
|
disks = list(object({
|
||
|
name = string
|
||
|
size = string
|
||
|
}))
|
||
|
network_interfaces = map(object(
|
||
|
{
|
||
|
mac = string
|
||
|
}
|
||
|
))
|
||
|
resource_pool_id = string
|
||
|
datastore_id = string
|
||
|
folder = string
|
||
|
}
|
||
|
))
|
||
|
description = "Virtual Machines description"
|
||
|
}
|
||
|
|
||
|
variable "cluster" {
|
||
|
type = map(object(
|
||
|
{
|
||
|
datacenter_name = string
|
||
|
datastore_name = string
|
||
|
resource_pool_name = string
|
||
|
folder = string
|
||
|
}
|
||
|
))
|
||
|
description = "vSphere cluster definition"
|
||
|
}
|
||
|
|
||
|
data "vsphere_datacenter" "datacenter" {
|
||
|
name = var.cluster.datacenter_name
|
||
|
}
|
||
|
|
||
|
data "vsphere_datastore" "datastore" {
|
||
|
name = var.cluster.datastore_name
|
||
|
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||
|
}
|
||
|
|
||
|
data "vsphere_resource_pool" "pool" {
|
||
|
name = var.cluster.resource_pool_name
|
||
|
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||
|
}
|
||
|
|
||
|
data "vsphere_network" "network" {
|
||
|
count = length(var.vms.network_interfaces)
|
||
|
|
||
|
name = var.networks[count.index].key
|
||
|
datacenter_id = data.vsphere_datacenter.datacenter.id
|
||
|
}
|
||
|
|
||
|
resource "vphere_virtual_virtual_machine" "vm" {
|
||
|
for_each = var.vms
|
||
|
iterator = "machine"
|
||
|
name = "${machine.key}.${machine.value.domain}"
|
||
|
resource_pool_id = "${machine.key.resource_pool_id}"
|
||
|
datastore_id = machine.key.datastore_id
|
||
|
folder = machine.folder
|
||
|
num_cpus = machine.cpu
|
||
|
memory = machine.ram
|
||
|
guest_id = machine.guest_id
|
||
|
dynamic "network_interface" {
|
||
|
for_each = data.vsphere_network.network
|
||
|
iterator = "vnet"
|
||
|
content {
|
||
|
networkid = vnet.value.id
|
||
|
mac = machine.network_interfaces["${vnet.key}"].mac
|
||
|
}
|
||
|
}
|
||
|
dynamic "disk" {
|
||
|
for_each = each.key.disks
|
||
|
content {
|
||
|
label = each.key.name
|
||
|
size = each.key.size
|
||
|
}
|
||
|
}
|
||
|
}
|