Created
September 29, 2019 23:52
-
-
Save FreekingDean/dd3735523433f49f7484613107555761 to your computer and use it in GitHub Desktop.
VM - Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
hostname_prefix = "${var.orchistration_type}_${var.node_type}" | |
hostname_id_format = "%02d" | |
} | |
data "ignition_config" "startup" { | |
users = [ | |
data.ignition_user.user.id | |
] | |
directories = [ | |
data.ignition_directory.storage.id | |
] | |
files = [ | |
data.ignition_file.hostname.id | |
] | |
systemd = [ | |
data.ignition_systemd_unit.storage_unit.id, | |
data.ignition_systemd_unit.qemu_agent.id, | |
data.ignition_systemd_unit.docker_unit.id, | |
] | |
} | |
data "ignition_systemd_unit" "docker_unit" { | |
name = "docker-tcp.socket" | |
enabled = true | |
content = "[Unit]\nDescription=Docker Socket for the API\n\n[Socket]\nListenStream=2375\nBindIPv6Only=both\nService=docker.service\n\n[Install]\nWantedBy=sockets.target" | |
} | |
data "ignition_systemd_unit" "storage_unit" { | |
name = "storage.mount" | |
enabled = true | |
content = file("${path.module}/services/storage.mount") | |
} | |
data "ignition_systemd_unit" "qemu_agent" { | |
name = "qemu-agent.service" | |
enabled = true | |
content = file("${path.module}/services/qemu-agent.service") | |
} | |
# Example configuration for the basic `core` user | |
data "ignition_user" "user" { | |
name = "core" | |
groups = ["sudo"] | |
#Example password: XXX | |
password_hash = "REMOVED" | |
# Preferably use the ssh key auth instead | |
#ssh_authorized_keys = "${list()}" | |
} | |
data "ignition_directory" "storage" { | |
filesystem = "root" | |
path = "/storage" | |
} | |
# Replace the default hostname with our generated one | |
data "ignition_file" "hostname" { | |
filesystem = "root" # default `ROOT` filesystem | |
path = "/etc/hostname" | |
mode = 420 # decimal 0644 | |
content { | |
content = "${local.hostname_prefix}" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
data = { | |
"docker" = { | |
os = "/home/USER/Projects/tftest/coreos_production_qemu_image.img" | |
} | |
} | |
} | |
resource "libvirt_network" "docker" { | |
name = "dockernet" | |
autostart = true | |
addresses = ["10.0.1.0/24"] | |
dns { | |
enabled = true | |
hosts { | |
hostname = "docker_master" | |
ip = "10.0.1.11" | |
} | |
} | |
} | |
resource "libvirt_pool" "main" { | |
name = "core" | |
type = "dir" | |
path = "/storage/fast/vms/newpools" | |
} | |
resource "libvirt_ignition" "ignition" { | |
name = "main_ignition" | |
pool = libvirt_pool.main.name | |
content = data.ignition_config.startup.rendered | |
} | |
# We fetch the latest ubuntu release image from their mirrors | |
resource "libvirt_volume" "os" { | |
name = "os-qcow2" | |
pool = libvirt_pool.main.name | |
source = local.data[var.orchistration_type]["os"] | |
format = "qcow2" | |
} | |
resource "libvirt_domain" "docker_master" { | |
name = "docker_master" | |
coreos_ignition = libvirt_ignition.ignition.id | |
filesystem { | |
source = "/storage" | |
target = "storage" | |
readonly = false | |
} | |
disk { | |
volume_id = libvirt_volume.os.id | |
} | |
boot_device { | |
dev = ["cdrom"] | |
} | |
network_interface { | |
network_name = libvirt_network.docker.name | |
addresses = ["10.0.1.11"] | |
mac = "52:54:00:6c:3c:01" | |
wait_for_lease = true | |
} | |
console { | |
type = "pty" | |
target_port = "0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment