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.
This commit is contained in:
+7
-5
@@ -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'
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
output "ips" {
|
||||
value = libvirt_domain.nodes.*.network_interface.0.addresses.0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user