You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k8s-terraform/modules/libvirt-nodes/main.tf

85 lines
2.0 KiB
HCL

terraform {
required_version = ">= 0.13"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.6.11"
}
}
}
provider "libvirt" {
uri = var.libvirt-connection-url
}
resource "libvirt_volume" "node-images" {
name = "${var.name-prefix}-${count.index}"
pool = var.pool-name
source = var.base-image
count = var.num-nodes
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)
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}"
memory = var.node-memory
vcpu = var.node-vcpus
cloudinit = element(libvirt_cloudinit_disk.node-inits.*.id, count.index)
network_interface {
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
# we need to pass it
# https://bugs.launchpad.net/cloud-images/+bug/1573095
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
disk {
volume_id = element(libvirt_volume.node-images.*.id, count.index)
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}