83 lines
2.5 KiB
HCL
83 lines
2.5 KiB
HCL
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_host" "host" {
|
|
name = "10.253.10.50"
|
|
datacenter_id = data.vsphere_datacenter.datacenter.id
|
|
}
|
|
|
|
data "vsphere_network" "network" {
|
|
for_each = var.cluster.vnets
|
|
|
|
name = each.value.name
|
|
datacenter_id = data.vsphere_datacenter.datacenter.id
|
|
}
|
|
|
|
resource "vsphere_virtual_machine" "vm" {
|
|
for_each = var.vms
|
|
name = "${each.key}.${each.value.domain}"
|
|
resource_pool_id = data.vsphere_resource_pool.pool.id
|
|
datastore_id = data.vsphere_datastore.datastore.id
|
|
folder = each.value.folder
|
|
num_cpus = each.value.cpu
|
|
memory = each.value.ram
|
|
guest_id = each.value.guest_id
|
|
|
|
dynamic "network_interface" {
|
|
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 = data.vsphere_network.network[network_interface.value.id].id
|
|
use_static_mac = true
|
|
mac_address = network_interface.value.mac
|
|
}
|
|
}
|
|
|
|
dynamic "disk" {
|
|
for_each = each.value.disks
|
|
content {
|
|
label = disk.key
|
|
size = disk.value.size
|
|
thin_provisioned = disk.thin_provisioned
|
|
unit_number = disk.unit_number
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "vsphere_virtual_machine" "ova" {
|
|
for_each = var.ovfs
|
|
name = "${each.key}.${each.value.domain}"
|
|
resource_pool_id = data.vsphere_resource_pool.pool.id
|
|
datastore_id = data.vsphere_datastore.datastore.id
|
|
host_system_id = data.vsphere_host.host.id
|
|
folder = var.cluster.folder
|
|
|
|
wait_for_guest_net_timeout = 0
|
|
wait_for_guest_ip_timeout = 0
|
|
|
|
ovf_deploy {
|
|
allow_unverified_ssl_cert = each.value.allow_unverified_ssl_cert
|
|
remote_ovf_url = each.value.remote_ovf_url
|
|
disk_provisioning = each.value.disk_provisioning
|
|
ip_protocol = each.value.ip_protocol
|
|
ip_allocation_policy = each.value.ip_allocation_policy
|
|
ovf_network_map = {
|
|
"Network 1" = data.vsphere_network.network[each.value.network_map[0]].id
|
|
}
|
|
}
|
|
vapp {
|
|
properties = each.value.vapp_properties
|
|
}
|
|
} |