fix(vmware): adding name param to network definitions

This commit is contained in:
Philippe Caseiro 2023-07-05 09:49:30 +02:00
parent 0fad70363b
commit eae0dbce65
2 changed files with 11 additions and 14 deletions

View File

@ -5,17 +5,15 @@ variable "vms" {
cpu = number cpu = number
ram = number ram = number
guest_id = string guest_id = string
disks = list(object({ disks = map(object({
name = string
size = string size = string
})) }))
network_interfaces = map(object( network_interfaces = map(object(
{ {
name = string
mac = string mac = string
} }
)) ))
resource_pool_id = string
datastore_id = string
folder = string folder = string
} }
)) ))
@ -23,14 +21,13 @@ variable "vms" {
} }
variable "cluster" { variable "cluster" {
type = map(object( type = object({
{
datacenter_name = string datacenter_name = string
datastore_name = string datastore_name = string
resource_pool_name = string resource_pool_name = string
folder = string folder = string
} }
)) )
description = "vSphere cluster definition" description = "vSphere cluster definition"
} }
@ -51,16 +48,16 @@ data "vsphere_resource_pool" "pool" {
data "vsphere_network" "network" { data "vsphere_network" "network" {
count = length(var.vms.network_interfaces) count = length(var.vms.network_interfaces)
name = var.networks[count.index].key name = var.networks[count.index].name
datacenter_id = data.vsphere_datacenter.datacenter.id datacenter_id = data.vsphere_datacenter.datacenter.id
} }
resource "vphere_virtual_virtual_machine" "vm" { resource "vsphere_virtual_machine" "vm" {
for_each = var.vms for_each = var.vms
iterator = "machine" iterator = "machine"
name = "${machine.key}.${machine.value.domain}" name = "${machine.key}.${machine.value.domain}"
resource_pool_id = "${machine.key.resource_pool_id}" resource_pool_id = data.vsphere_resource_pool.id
datastore_id = machine.key.datastore_id datastore_id = data.vsphere_datastore.id
folder = machine.folder folder = machine.folder
num_cpus = machine.cpu num_cpus = machine.cpu
memory = machine.ram memory = machine.ram
@ -76,7 +73,7 @@ resource "vphere_virtual_virtual_machine" "vm" {
dynamic "disk" { dynamic "disk" {
for_each = each.key.disks for_each = each.key.disks
content { content {
label = each.key.name label = each.key
size = each.key.size size = each.key.size
} }
} }

View File

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