Moved everything from k8s-nodes to the top-level.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13"
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.6.11"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "node-images" {
|
||||
name = "${var.name-prefix}-base"
|
||||
pool = var.pool-name
|
||||
source = var.base-image
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "node-images-resized" {
|
||||
name = "${var.name-prefix}-${count.index}-resized"
|
||||
pool = var.pool-name
|
||||
base_volume_id = libvirt_volume.node-images.id
|
||||
count = var.num-nodes
|
||||
size = var.node-disk-size
|
||||
}
|
||||
|
||||
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(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}"
|
||||
memory = var.node-memory
|
||||
vcpu = var.node-vcpus
|
||||
|
||||
cloudinit = element(libvirt_cloudinit_disk.node-inits.*.id, count.index)
|
||||
|
||||
network_interface {
|
||||
network_name = var.network-name
|
||||
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-resized.*.id, count.index)
|
||||
}
|
||||
|
||||
graphics {
|
||||
type = "spice"
|
||||
listen_type = "address"
|
||||
autoport = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
version: 2
|
||||
ethernets:
|
||||
ens3:
|
||||
dhcp4: true
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
# This only works on the default network. They will not work using the bridged
|
||||
# network.
|
||||
# output "ips" {
|
||||
# value = libvirt_domain.nodes.*.network_interface.0.addresses.0
|
||||
# }
|
||||
@@ -0,0 +1,56 @@
|
||||
variable "base-image" {
|
||||
default = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img"
|
||||
description = "The base image to be used for all nodes."
|
||||
}
|
||||
|
||||
variable "libvirt-connection-url" {
|
||||
description = "The libvirt connection URI, ie. qemu+ssh://<user>@<host>/system"
|
||||
}
|
||||
|
||||
variable "name-prefix" {
|
||||
default = "k8s-node"
|
||||
description = "This will be a prefix for all resource names, ie. domains will be created suck as \"k8s-node-2\"."
|
||||
}
|
||||
|
||||
variable "network-name" {
|
||||
default = "default"
|
||||
description = "The name of a pre-existing virtual-network."
|
||||
}
|
||||
|
||||
variable "node-disk-size" {
|
||||
default = 4294967296
|
||||
description = "The size of the disk to be used for libvirt nodes. (in bytes)"
|
||||
}
|
||||
|
||||
variable "node-memory" {
|
||||
default = "2048"
|
||||
description = "The amount of memory to be used for all the nodes."
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "node-vcpus" {
|
||||
default = "2"
|
||||
description = "The amount of vcpus to be used for all the nodes."
|
||||
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."
|
||||
}
|
||||
|
||||
variable "pool-name" {
|
||||
default = "default"
|
||||
description = "The name of the pool to put all disk images in."
|
||||
}
|
||||
|
||||
variable "root-admin-passwd" {
|
||||
description = "This will be the password for the root and admin user. The format of this can by any format accepted by cloud-init's chpasswd module."
|
||||
}
|
||||
|
||||
variable "root-admin-pub-key" {
|
||||
description = "The public key to be added to authorized_keys for the root and admin accounts."
|
||||
}
|
||||
Reference in New Issue
Block a user