feat(vmware): adding vmware support
This commit is contained in:
parent
d02e96d4f1
commit
0fad70363b
|
@ -0,0 +1,83 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
opennebula = {
|
||||
source = "hashicorp/vsphere"
|
||||
version = "~> 2.4.0"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue