From 6d378b2d1fca05adaf5af4122353ca2eeefd7f02 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Sun, 27 Feb 2022 15:22:09 -0800 Subject: [PATCH] Move jobs to modules --- adminer.nomad => mysql/adminer.nomad | 0 mysql.nomad => mysql/mysql.nomad | 0 mysql/mysql.tf | 16 +++++ .../nextcloud-bootstrap.nomad | 0 nextcloud.nomad => nextcloud/nextcloud.nomad | 0 nextcloud/nextcloud.tf | 15 +++++ packer/ubuntu-cloud-init.hcl | 27 +++++++++ services.tf | 58 +++++-------------- traefik.nomad => traefik/traefik.nomad | 0 traefik/traefik.tf | 15 +++++ 10 files changed, 86 insertions(+), 45 deletions(-) rename adminer.nomad => mysql/adminer.nomad (100%) rename mysql.nomad => mysql/mysql.nomad (100%) create mode 100644 mysql/mysql.tf rename nextcloud-bootstrap.nomad => nextcloud/nextcloud-bootstrap.nomad (100%) rename nextcloud.nomad => nextcloud/nextcloud.nomad (100%) create mode 100644 nextcloud/nextcloud.tf create mode 100644 packer/ubuntu-cloud-init.hcl rename traefik.nomad => traefik/traefik.nomad (100%) create mode 100644 traefik/traefik.tf diff --git a/adminer.nomad b/mysql/adminer.nomad similarity index 100% rename from adminer.nomad rename to mysql/adminer.nomad diff --git a/mysql.nomad b/mysql/mysql.nomad similarity index 100% rename from mysql.nomad rename to mysql/mysql.nomad diff --git a/mysql/mysql.tf b/mysql/mysql.tf new file mode 100644 index 0000000..2edfb74 --- /dev/null +++ b/mysql/mysql.tf @@ -0,0 +1,16 @@ +# Create mysql server +resource "nomad_job" "mysql-server" { + hcl2 { + enabled = true + } + + jobspec = file("${path.module}/mysql.nomad") +} + +resource "nomad_job" "adminer" { + hcl2 { + enabled = true + } + + jobspec = file("${path.module}/adminer.nomad") +} diff --git a/nextcloud-bootstrap.nomad b/nextcloud/nextcloud-bootstrap.nomad similarity index 100% rename from nextcloud-bootstrap.nomad rename to nextcloud/nextcloud-bootstrap.nomad diff --git a/nextcloud.nomad b/nextcloud/nextcloud.nomad similarity index 100% rename from nextcloud.nomad rename to nextcloud/nextcloud.nomad diff --git a/nextcloud/nextcloud.tf b/nextcloud/nextcloud.tf new file mode 100644 index 0000000..0e7430f --- /dev/null +++ b/nextcloud/nextcloud.tf @@ -0,0 +1,15 @@ +resource "nomad_job" "nextcloud-bootstrap" { + hcl2 { + enabled = true + } + + jobspec = file("${path.module}/nextcloud-bootstrap.nomad") +} + +resource "nomad_job" "nextcloud" { + hcl2 { + enabled = true + } + + jobspec = file("${path.module}/nextcloud.nomad") +} diff --git a/packer/ubuntu-cloud-init.hcl b/packer/ubuntu-cloud-init.hcl new file mode 100644 index 0000000..1f9eb5e --- /dev/null +++ b/packer/ubuntu-cloud-init.hcl @@ -0,0 +1,27 @@ +packer { + required_plugins { + docker = { + version = ">= 0.0.7" + source = "github.com/hashicorp/docker" + } + } +} + + +source "qemu" "focal-arm64" { + iso_url = "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-arm64.img" + iso_checksum = "sha256:fee6bc4fcce3267b6a03a2449d5b471b7edf6ef990d6761607bd3960e2df4d9d" + output_directory = "focal_arm64" + shutdown_command = "echo 'packer' | sudo -S shutdown -P now" + disk_size = "5000M" + format = "qcow2" + ssh_username = "root" + ssh_password = "s0m3password" + ssh_timeout = "20m" + boot_wait = "10s" + boot_command = [] +} + +build { + sources = ["source.qemu.example"] +} diff --git a/services.tf b/services.tf index 2e1cd48..b60539a 100644 --- a/services.tf +++ b/services.tf @@ -11,7 +11,6 @@ provider "consul" { # Get Nomad client from Consul data "consul_service" "read-nomad-cluster" { name = "nomad-client" - # name = "nomad-clients" } locals { @@ -19,44 +18,31 @@ locals { nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}" } -# Configure the Consul provider +# Configure the Nomad provider provider "nomad" { - # address = "http://services.thefij:4646" address = local.nomad_node_address region = "global" } -# Create mysql server -resource "nomad_job" "mysql-server" { - hcl2 { - enabled = true - } - - jobspec = file("${path.module}/mysql.nomad") -} +# Define services as modules # Create mysql server -resource "nomad_job" "adminer" { - hcl2 { - enabled = true - } - - jobspec = file("${path.module}/adminer.nomad") +module "mysql-server" { + source = "./mysql" } -# Create Traefik -resource "nomad_job" "traefik" { - hcl2 { - enabled = true - vars = { - "consul_address" = "${var.consul_address}", - } - } +module "traefik" { + source = "./traefik" - jobspec = file("${path.module}/traefik.nomad") + consul_address = var.consul_address +} + +module "nextcloud" { + source = "./nextcloud" + + depends_on = [module.mysql-server] } -# Create a sample host resource "nomad_job" "whoami" { hcl2 { enabled = true @@ -67,21 +53,3 @@ resource "nomad_job" "whoami" { jobspec = file("${path.module}/whoami.nomad") } - -# Create a sample host -resource "nomad_job" "nextcloud-bootstrap" { - hcl2 { - enabled = true - } - - jobspec = file("${path.module}/nextcloud-bootstrap.nomad") -} - -# Create a sample host -resource "nomad_job" "nextcloud" { - hcl2 { - enabled = true - } - - jobspec = file("${path.module}/nextcloud.nomad") -} diff --git a/traefik.nomad b/traefik/traefik.nomad similarity index 100% rename from traefik.nomad rename to traefik/traefik.nomad diff --git a/traefik/traefik.tf b/traefik/traefik.tf new file mode 100644 index 0000000..0843057 --- /dev/null +++ b/traefik/traefik.tf @@ -0,0 +1,15 @@ +variable "consul_address" { + type = string +} + +resource "nomad_job" "traefik" { + hcl2 { + enabled = true + vars = { + "consul_address" = "${var.consul_address}", + } + } + + jobspec = file("${path.module}/traefik.nomad") +} +