commit b4a39f1d9afc918f3cf8482788a824ad939fc340
parent b228544927c5b17c9fe23b424f2fa2869b39eeed
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date: Sun, 24 Jan 2021 23:32:32 +0200
autonomous: Init k3s infrastructure on autonomous
Diffstat:
3 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/terraform/infrastructure/autonomous/main.tf b/terraform/infrastructure/autonomous/main.tf
@@ -0,0 +1,46 @@
+provider "libvirt" {
+ uri = var.libvirt_uri
+}
+
+module "autonomous_network" {
+ source = "../../modules/libvirt_network"
+
+ network_bridge_interface = "virbr1"
+ network_name = "autonomous_network"
+ network_cidr = ["192.168.133.0/24", "2a01:4f8:211:1418::/116"]
+ network_dns_enabled = false
+}
+
+resource "libvirt_pool" "tf_pool" {
+ name = var.libvirt_storage_pool
+ type = "dir"
+ path = "/opt/Disks/${var.libvirt_storage_pool}"
+}
+
+resource "libvirt_volume" "base_debian_volume" {
+ name = "debian_base_volume"
+ pool = var.libvirt_storage_pool
+ format = "qcow2"
+ source = "/opt/Disks/packer-debian10-base"
+}
+
+module "k3s_1" {
+ source = "../../modules/libvirt_host"
+ for_each = toset(["2", "3", "4"])
+
+ host_name = "k3s_${each.key}"
+ host_memory = "2048"
+ host_vcpu = 2
+ storage_pool = var.libvirt_storage_pool
+ volume_name = "k3s_${each.key}"
+ base_volume_id = libvirt_volume.base_debian_volume.id
+ disks = [{ "volume_id" : libvirt_volume.base_debian_volume.id }]
+ network_id = module.autonomous_network.id
+ network_cidr = module.autonomous_network.cidr[0]
+ network_host = each.key
+ enable_cloud_init = true
+ cloudinit_user_template = <<EOF
+runcmd:
+ - echo 'source /etc/network/interfaces.d/*' > /etc/network/interfaces
+EOF
+}
diff --git a/terraform/infrastructure/autonomous/variables.tf b/terraform/infrastructure/autonomous/variables.tf
@@ -0,0 +1,9 @@
+variable "libvirt_uri" {
+ description = "URI for libvirt to use"
+ default = "qemu:///system"
+}
+
+variable "libvirt_storage_pool" {
+ description = "Storage pool to use for VM disks"
+ default = "tf_pool"
+}
diff --git a/terraform/infrastructure/autonomous/versions.tf b/terraform/infrastructure/autonomous/versions.tf
@@ -0,0 +1,9 @@
+terraform {
+ required_providers {
+ libvirt = {
+ source = "erethon.com/third-party/libvirt"
+ version = "0.6.2"
+ }
+ }
+ required_version = ">= 0.13"
+}