Made cloud-init configs an input to libvirt-nodes.

ansible-test
shnee 4 years ago
parent f8b894739f
commit cb59a5b2f3

@ -97,29 +97,31 @@ module "worker-nodes" {
# } # }
# #
# module "master-nodes" { # module "master-nodes" {
# source = "./modules/libvirt-nodes" # source = "./modules/libvirt-nodes"
# pool-name = libvirt_pool.images.name # pool-name = libvirt_pool.images.name
# name-prefix = "${var.vm-name-prefix}-master" # name-prefix = "${var.vm-name-prefix}-master"
# num-nodes = var.master-nodes # num-nodes = var.master-nodes
# node-memory = var.node-memory # node-memory = var.node-memory
# node-vcpus = var.node-vcpus # node-vcpus = var.node-vcpus
# base-image = var.base-image # base-image = var.base-image
# root-admin-passwd = var.root-admin-passwd # root-admin-passwd = var.root-admin-passwd
# root-admin-pub-key = var.root-admin-pub-key # root-admin-pub-key = var.root-admin-pub-key
# libvirt-connection-url = var.libvirt-connection-url # libvirt-connection-url = var.libvirt-connection-url
# user-datas = data.template_file.master-node-user-datas
# } # }
# #
# module "worker-nodes" { # module "worker-nodes" {
# source = "./modules/libvirt-nodes" # source = "./modules/libvirt-nodes"
# pool-name = libvirt_pool.images.name # pool-name = libvirt_pool.images.name
# name-prefix = "${var.vm-name-prefix}-worker" # name-prefix = "${var.vm-name-prefix}-worker"
# num-nodes = var.worker-nodes # num-nodes = var.worker-nodes
# node-memory = var.node-memory # node-memory = var.node-memory
# node-vcpus = var.node-vcpus # node-vcpus = var.node-vcpus
# base-image = var.base-image # base-image = var.base-image
# root-admin-passwd = var.root-admin-passwd # root-admin-passwd = var.root-admin-passwd
# root-admin-pub-key = var.root-admin-pub-key # root-admin-pub-key = var.root-admin-pub-key
# libvirt-connection-url = var.libvirt-connection-url # libvirt-connection-url = var.libvirt-connection-url
# user-datas = data.template_file.worker-node-user-datas
# } # }
# #
# resource "libvirt_pool" "images" { # resource "libvirt_pool" "images" {

@ -20,31 +20,21 @@ resource "libvirt_volume" "node-images" {
format = "qcow2" 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" { data "template_file" "network-config" {
template = file("${path.module}/network_config.cfg") template = file("${path.module}/network_config.cfg")
} }
resource "libvirt_cloudinit_disk" "node-inits" { resource "libvirt_cloudinit_disk" "node-inits" {
name = "${var.name-prefix}-${count.index}-init" 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 network_config = data.template_file.network-config.rendered
pool = var.pool-name pool = var.pool-name
count = var.num-nodes count = var.num-nodes
} }
resource "libvirt_domain" "nodes" { resource "libvirt_domain" "nodes" {
count = var.num-nodes count = var.num-nodes
name = "${var.name-prefix}-${count.index}" name = "${var.name-prefix}-${count.index}"
memory = var.node-memory memory = var.node-memory
vcpu = var.node-vcpus vcpu = var.node-vcpus

@ -24,6 +24,10 @@ variable "node-vcpus" {
type = number type = number
} }
variable "user-datas" {
description = "A list of cloud-init configs that get applied to their corresponding node."
}
variable "num-nodes" { variable "num-nodes" {
description = "The number of nodes to create with this config." description = "The number of nodes to create with this config."
} }

Loading…
Cancel
Save