From 4a62875b8e381bcbecc95220720a76221eaf4e52 Mon Sep 17 00:00:00 2001 From: shnee Date: Thu, 11 Nov 2021 14:50:45 -0500 Subject: [PATCH] Added outputs for IPs. - Made sure node-memory ad node-vcpus is passed down to module. - Fixed get-vm-ips.sh after move to module. --- get-vm-ips.sh | 12 +++++++----- main.tf | 12 ++++++++++++ modules/node/main.tf | 5 +++-- modules/node/outpus.tf | 4 ++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/get-vm-ips.sh b/get-vm-ips.sh index cef5323..25e36fe 100755 --- a/get-vm-ips.sh +++ b/get-vm-ips.sh @@ -3,15 +3,17 @@ # Use eval $(./get-vm-ips.sh) to set env vars for ips. terraform refresh > /dev/null -IPS_JSON="$(terraform show -json | jq '.values.root_module.resources[] | select(.type == "libvirt_domain") | {name: .values.name, ip: .values.network_interface[0].addresses[0]}')" + +IPS_JSON="$(terraform show -json | jq '.values.outputs')" echo $IPS_JSON | \ - jq 'select(.name | contains("master")) | .ip' | \ - xargs -I% echo export MASTER=% + jq '."master-ips".value[]' | \ + nl -v 0 | \ + awk '{print "export MASTER" $1 "=" $2}' | \ + sed 's/"//g' echo $IPS_JSON | \ - jq 'select(.name | contains("worker")) | .ip' | \ + jq '."worker-ips".value[]' | \ nl -v 0 | \ awk '{print "export WORKER" $1 "=" $2}' | \ sed 's/"//g' - diff --git a/main.tf b/main.tf index 80a181c..d273d9b 100644 --- a/main.tf +++ b/main.tf @@ -17,6 +17,8 @@ module "master-nodes" { pool-name = libvirt_pool.images.name name-prefix = "${var.vm-name-prefix}-master" num-nodes = var.master-nodes + node-memory = var.node-memory + node-vcpus = var.node-vcpus base-image = var.ubuntu-image root-admin-passwd = var.root-admin-passwd root-admin-pub-key = var.root-admin-pub-key @@ -28,6 +30,8 @@ module "worker-nodes" { pool-name = libvirt_pool.images.name name-prefix = "${var.vm-name-prefix}-worker" num-nodes = var.worker-nodes + node-memory = var.node-memory + node-vcpus = var.node-vcpus base-image = var.ubuntu-image root-admin-passwd = var.root-admin-passwd root-admin-pub-key = var.root-admin-pub-key @@ -39,3 +43,11 @@ resource "libvirt_pool" "images" { type = "dir" path = var.disk-image-dir } + +output "master-ips" { + value = module.master-nodes.ips +} + +output "worker-ips" { + value = module.worker-nodes.ips +} diff --git a/modules/node/main.tf b/modules/node/main.tf index b4b0835..0507076 100644 --- a/modules/node/main.tf +++ b/modules/node/main.tf @@ -51,8 +51,9 @@ resource "libvirt_domain" "nodes" { cloudinit = element(libvirt_cloudinit_disk.node-inits.*.id, count.index) network_interface { - network_name = "default" - hostname = "${var.name-prefix}-${count.index}" + network_name = "default" + hostname = "${var.name-prefix}-${count.index}" + wait_for_lease = true } # IMPORTANT: this is a known bug on cloud images, since they expect a console diff --git a/modules/node/outpus.tf b/modules/node/outpus.tf index e69de29..4d399a6 100644 --- a/modules/node/outpus.tf +++ b/modules/node/outpus.tf @@ -0,0 +1,4 @@ + +output "ips" { + value = libvirt_domain.nodes.*.network_interface.0.addresses.0 +}