Move jobs to modules

This commit is contained in:
IamTheFij 2022-02-27 15:22:09 -08:00
parent 50ecca2b06
commit 6d378b2d1f
10 changed files with 86 additions and 45 deletions

16
mysql/mysql.tf Normal file
View File

@ -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")
}

15
nextcloud/nextcloud.tf Normal file
View File

@ -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")
}

View File

@ -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"]
}

View File

@ -11,7 +11,6 @@ provider "consul" {
# Get Nomad client from Consul # Get Nomad client from Consul
data "consul_service" "read-nomad-cluster" { data "consul_service" "read-nomad-cluster" {
name = "nomad-client" name = "nomad-client"
# name = "nomad-clients"
} }
locals { locals {
@ -19,44 +18,31 @@ locals {
nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}" nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}"
} }
# Configure the Consul provider # Configure the Nomad provider
provider "nomad" { provider "nomad" {
# address = "http://services.thefij:4646"
address = local.nomad_node_address address = local.nomad_node_address
region = "global" region = "global"
} }
# Create mysql server # Define services as modules
resource "nomad_job" "mysql-server" {
hcl2 {
enabled = true
}
jobspec = file("${path.module}/mysql.nomad")
}
# Create mysql server # Create mysql server
resource "nomad_job" "adminer" { module "mysql-server" {
hcl2 { source = "./mysql"
enabled = true
}
jobspec = file("${path.module}/adminer.nomad")
} }
# Create Traefik module "traefik" {
resource "nomad_job" "traefik" { source = "./traefik"
hcl2 {
enabled = true
vars = {
"consul_address" = "${var.consul_address}",
}
}
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" { resource "nomad_job" "whoami" {
hcl2 { hcl2 {
enabled = true enabled = true
@ -67,21 +53,3 @@ resource "nomad_job" "whoami" {
jobspec = file("${path.module}/whoami.nomad") 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")
}

15
traefik/traefik.tf Normal file
View File

@ -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")
}