feat(vmware): adding vmware support
This commit is contained in:
parent
d02e96d4f1
commit
b1de088d87
|
@ -0,0 +1,86 @@
|
|||
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
|
||||
}
|
||||
|
||||
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" {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
output "shortnames" {
|
||||
value = keys(var.vms)
|
||||
}
|
||||
|
||||
//output "virtual_machines" {
|
||||
// value = vsphere.virtual_machine.vm //template_nic[0].computed_mac)
|
||||
//}
|
|
@ -0,0 +1,8 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
vsphere = {
|
||||
source = "hashicorp/vsphere"
|
||||
version = "~> 2.4.0"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue