2022-05-22 09:39:30 -04:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
libvirt = {
|
|
|
|
source = "dmacvicar/libvirt"
|
|
|
|
version = "0.6.14"
|
|
|
|
}
|
2022-06-30 05:14:26 -04:00
|
|
|
docker = {
|
2022-07-08 04:59:59 -04:00
|
|
|
source = "kreuzwerker/docker"
|
2022-06-30 05:14:26 -04:00
|
|
|
version = "2.17.0"
|
|
|
|
}
|
2022-05-22 09:39:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provider "libvirt" {
|
2022-10-05 03:11:30 -04:00
|
|
|
uri = var.libvirt_uri
|
2022-05-22 09:39:30 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 05:14:26 -04:00
|
|
|
provider "docker" {
|
|
|
|
host = "unix:///var/run/docker.sock"
|
|
|
|
|
|
|
|
registry_auth {
|
|
|
|
address = "ghcr.io"
|
|
|
|
config_file = pathexpand("~/.docker/config.json")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 03:11:30 -04:00
|
|
|
resource "docker_image" "qemu_metadata" {
|
2022-09-27 04:47:45 -04:00
|
|
|
name = var.metadata_api_image
|
2022-07-08 04:59:59 -04:00
|
|
|
keep_locally = true
|
2022-06-30 05:14:26 -04:00
|
|
|
}
|
|
|
|
|
2022-10-05 03:11:30 -04:00
|
|
|
resource "docker_container" "qemu_metadata" {
|
2022-09-26 09:52:31 -04:00
|
|
|
name = "${var.name}-qemu-metadata"
|
2022-10-05 03:11:30 -04:00
|
|
|
image = docker_image.qemu_metadata.latest
|
2022-06-30 05:14:26 -04:00
|
|
|
network_mode = "host"
|
2022-07-08 04:59:59 -04:00
|
|
|
rm = true
|
2022-09-27 04:47:45 -04:00
|
|
|
command = [
|
2022-09-26 09:52:31 -04:00
|
|
|
"--network",
|
|
|
|
"${var.name}-network",
|
2022-10-05 03:11:30 -04:00
|
|
|
"--libvirt-uri",
|
|
|
|
"${var.metadata_libvirt_uri}",
|
2022-09-26 09:52:31 -04:00
|
|
|
]
|
2022-06-30 05:14:26 -04:00
|
|
|
mounts {
|
2022-10-05 03:11:30 -04:00
|
|
|
source = abspath(var.libvirt_socket_path)
|
2022-06-30 05:14:26 -04:00
|
|
|
target = "/var/run/libvirt/libvirt-sock"
|
2022-07-08 04:59:59 -04:00
|
|
|
type = "bind"
|
2022-06-30 05:14:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 09:39:30 -04:00
|
|
|
module "control_plane" {
|
|
|
|
source = "./modules/instance_group"
|
|
|
|
role = "control-plane"
|
|
|
|
amount = var.control_plane_count
|
|
|
|
vcpus = var.vcpus
|
|
|
|
memory = var.memory
|
|
|
|
state_disk_size = var.state_disk_size
|
|
|
|
cidr = "10.42.1.0/24"
|
|
|
|
network_id = libvirt_network.constellation.id
|
|
|
|
pool = libvirt_pool.cluster.name
|
|
|
|
boot_volume_id = libvirt_volume.constellation_coreos_image.id
|
2022-05-30 04:29:34 -04:00
|
|
|
machine = var.machine
|
2022-09-26 09:52:31 -04:00
|
|
|
name = var.name
|
2022-05-22 09:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module "worker" {
|
|
|
|
source = "./modules/instance_group"
|
|
|
|
role = "worker"
|
|
|
|
amount = var.worker_count
|
|
|
|
vcpus = var.vcpus
|
|
|
|
memory = var.memory
|
|
|
|
state_disk_size = var.state_disk_size
|
|
|
|
cidr = "10.42.2.0/24"
|
|
|
|
network_id = libvirt_network.constellation.id
|
|
|
|
pool = libvirt_pool.cluster.name
|
|
|
|
boot_volume_id = libvirt_volume.constellation_coreos_image.id
|
2022-05-30 04:29:34 -04:00
|
|
|
machine = var.machine
|
2022-09-26 09:52:31 -04:00
|
|
|
name = var.name
|
2022-05-22 09:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_pool" "cluster" {
|
2022-09-26 09:52:31 -04:00
|
|
|
name = "${var.name}-storage-pool"
|
2022-05-22 09:39:30 -04:00
|
|
|
type = "dir"
|
|
|
|
path = "/var/lib/libvirt/images"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_volume" "constellation_coreos_image" {
|
2022-09-26 09:52:31 -04:00
|
|
|
name = "${var.name}-node-image"
|
2022-05-22 09:39:30 -04:00
|
|
|
pool = libvirt_pool.cluster.name
|
2022-07-04 06:59:43 -04:00
|
|
|
source = var.constellation_coreos_image
|
|
|
|
format = var.image_format
|
2022-05-22 09:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_network" "constellation" {
|
2022-09-26 09:52:31 -04:00
|
|
|
name = "${var.name}-network"
|
2022-05-22 09:39:30 -04:00
|
|
|
mode = "nat"
|
|
|
|
addresses = ["10.42.0.0/16"]
|
|
|
|
dhcp {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
dns {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
}
|