From 76b7c779bc04f08dbb2d7b218d269a415bb77602 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 24 Mar 2021 10:14:16 +0100 Subject: [PATCH] Manage network dependencies for virtual machines --- .terraform/main.tf | 9 +++++---- .terraform/tfvars/04-virtual-machines.tfvars | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.terraform/main.tf b/.terraform/main.tf index f68b0fd..6d9a822 100644 --- a/.terraform/main.tf +++ b/.terraform/main.tf @@ -22,7 +22,7 @@ provider "dns" { /* * Virtual networks */ -resource "opennebula_virtual_network" "vnet"{ +resource "opennebula_virtual_network" "vnets"{ for_each = var.virtual_networks name = each.key vlan_id = each.value.vlan_id @@ -60,7 +60,7 @@ module "vms" { vcpu = each.value.vcpu ram = each.value.memory - vnets = opennebula_virtual_network.vnet + vnets = opennebula_virtual_network.vnets network_interfaces = each.value.network_interfaces tag_labels = each.value.labels @@ -71,8 +71,9 @@ module "vms" { system_image_source = each.value.disks.system.source data_image_source = "" - depends = [ - opennebula_virtual_network.vnet[each.value.depends[0]].id + depends = [ + for dp in each.value.network_interfaces: + opennebula_virtual_network.vnets[dp.network_name].id ] } diff --git a/.terraform/tfvars/04-virtual-machines.tfvars b/.terraform/tfvars/04-virtual-machines.tfvars index 9b1c64a..3316db9 100644 --- a/.terraform/tfvars/04-virtual-machines.tfvars +++ b/.terraform/tfvars/04-virtual-machines.tfvars @@ -19,7 +19,6 @@ virtual_machines = { source = "http://localhost/fabrica/infra/production/amon.fabrica.local/system/amon.fabrica.local.img" } } - depends = [ "internet" ] }, scribe = { fqdn = "scribe.fabrica.local", @@ -40,6 +39,5 @@ virtual_machines = { source = "http://localhost/fabrica/infra/production/scribe.fabrica.local/system/scribe.fabrica.local.img" } } - depends = [ "internet" ] } } \ No newline at end of file