From cb59a5b2f3e232ec9bd911ece74817d12a346d8f Mon Sep 17 00:00:00 2001 From: shnee Date: Fri, 12 Nov 2021 20:54:05 -0500 Subject: [PATCH] Made cloud-init configs an input to libvirt-nodes. --- main.tf | 38 ++++++++++++++++-------------- modules/libvirt-nodes/main.tf | 16 +++---------- modules/libvirt-nodes/variables.tf | 4 ++++ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/main.tf b/main.tf index cd96132..20f8bfc 100644 --- a/main.tf +++ b/main.tf @@ -97,29 +97,31 @@ module "worker-nodes" { # } # # module "master-nodes" { -# source = "./modules/libvirt-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.base-image -# root-admin-passwd = var.root-admin-passwd -# root-admin-pub-key = var.root-admin-pub-key +# source = "./modules/libvirt-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.base-image +# root-admin-passwd = var.root-admin-passwd +# root-admin-pub-key = var.root-admin-pub-key # libvirt-connection-url = var.libvirt-connection-url +# user-datas = data.template_file.master-node-user-datas # } # # module "worker-nodes" { -# source = "./modules/libvirt-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.base-image -# root-admin-passwd = var.root-admin-passwd -# root-admin-pub-key = var.root-admin-pub-key +# source = "./modules/libvirt-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.base-image +# root-admin-passwd = var.root-admin-passwd +# root-admin-pub-key = var.root-admin-pub-key # libvirt-connection-url = var.libvirt-connection-url +# user-datas = data.template_file.worker-node-user-datas # } # # resource "libvirt_pool" "images" { diff --git a/modules/libvirt-nodes/main.tf b/modules/libvirt-nodes/main.tf index 0507076..9b792d0 100644 --- a/modules/libvirt-nodes/main.tf +++ b/modules/libvirt-nodes/main.tf @@ -20,31 +20,21 @@ resource "libvirt_volume" "node-images" { format = "qcow2" } -data "template_file" "node-user-datas" { - template = file("${path.module}/cloud_init.cfg") - vars = { - admin-passwd = "${var.root-admin-passwd}" - admin-pub-key = "${var.root-admin-pub-key}" - hostname = "${var.name-prefix}-${count.index}" - } - count = var.num-nodes -} - data "template_file" "network-config" { template = file("${path.module}/network_config.cfg") } resource "libvirt_cloudinit_disk" "node-inits" { name = "${var.name-prefix}-${count.index}-init" - user_data = element(data.template_file.node-user-datas.*.rendered, count.index) + user_data = element(var.user-datas.*.rendered, count.index) network_config = data.template_file.network-config.rendered pool = var.pool-name count = var.num-nodes } resource "libvirt_domain" "nodes" { - count = var.num-nodes - name = "${var.name-prefix}-${count.index}" + count = var.num-nodes + name = "${var.name-prefix}-${count.index}" memory = var.node-memory vcpu = var.node-vcpus diff --git a/modules/libvirt-nodes/variables.tf b/modules/libvirt-nodes/variables.tf index 93d7ad0..4253b62 100644 --- a/modules/libvirt-nodes/variables.tf +++ b/modules/libvirt-nodes/variables.tf @@ -24,6 +24,10 @@ variable "node-vcpus" { type = number } +variable "user-datas" { + description = "A list of cloud-init configs that get applied to their corresponding node." +} + variable "num-nodes" { description = "The number of nodes to create with this config." }