feat(vmware): addin multiple disk support for vms

This commit is contained in:
Philippe Caseiro 2023-10-19 14:31:39 +02:00
parent b1de088d87
commit b9d7f4e414
2 changed files with 34 additions and 37 deletions

View File

@ -1,39 +1,3 @@
variable "vms" {
type = map(object(
{
domain = string
cpu = number
ram = number
guest_id = string
disks = map(object({
size = string
}))
network_interfaces = list(object(
{
id = string
mac = string
}
))
folder = string
}
))
description = "Virtual Machines description"
}
variable "cluster" {
type = object({
datacenter_name = string
datastore_name = string
resource_pool_name = string
folder = string
vnets = map(object({
name = string
}))
}
)
description = "vSphere cluster definition"
}
data "vsphere_datacenter" "datacenter" {
name = var.cluster.datacenter_name
}
@ -48,6 +12,11 @@ data "vsphere_resource_pool" "pool" {
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
@ -81,6 +50,34 @@ resource "vsphere_virtual_machine" "vm" {
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
}
}

View File

@ -2,7 +2,7 @@ terraform {
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "~> 2.4.0"
version = "~> 2.5.1"
}
}
}