diff --git a/mysql/mysql.tf b/mysql/mysql.tf index 2edfb74..21775d9 100644 --- a/mysql/mysql.tf +++ b/mysql/mysql.tf @@ -1,4 +1,9 @@ -# Create mysql server +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + resource "nomad_job" "mysql-server" { hcl2 { enabled = true @@ -10,6 +15,9 @@ resource "nomad_job" "mysql-server" { resource "nomad_job" "adminer" { hcl2 { enabled = true + vars = { + "base_hostname" = "${var.base_hostname}", + } } jobspec = file("${path.module}/adminer.nomad") diff --git a/nextcloud/nextcloud.tf b/nextcloud/nextcloud.tf index 0e7430f..2ee5ef2 100644 --- a/nextcloud/nextcloud.tf +++ b/nextcloud/nextcloud.tf @@ -1,3 +1,9 @@ +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + resource "nomad_job" "nextcloud-bootstrap" { hcl2 { enabled = true @@ -9,6 +15,9 @@ resource "nomad_job" "nextcloud-bootstrap" { resource "nomad_job" "nextcloud" { hcl2 { enabled = true + vars = { + "base_hostname" = "${var.base_hostname}", + } } jobspec = file("${path.module}/nextcloud.nomad") diff --git a/services.tf b/services.tf index b60539a..5270cb0 100644 --- a/services.tf +++ b/services.tf @@ -4,6 +4,12 @@ variable "consul_address" { default = "http://192.168.2.41:8500" } +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + provider "consul" { address = var.consul_address } @@ -26,20 +32,24 @@ provider "nomad" { # Define services as modules -# Create mysql server module "mysql-server" { source = "./mysql" + + base_hostname = var.base_hostname } module "traefik" { source = "./traefik" consul_address = var.consul_address + base_hostname = var.base_hostname } module "nextcloud" { source = "./nextcloud" + base_hostname = var.base_hostname + depends_on = [module.mysql-server] } @@ -47,7 +57,8 @@ resource "nomad_job" "whoami" { hcl2 { enabled = true vars = { - "count" = "${2 * length(data.consul_service.read-nomad-cluster.service)}" + "count" = "${2 * length(data.consul_service.read-nomad-cluster.service)}", + "base_hostname" = "${var.base_hostname}", } } diff --git a/traefik/traefik.tf b/traefik/traefik.tf index 0843057..3fac5e6 100644 --- a/traefik/traefik.tf +++ b/traefik/traefik.tf @@ -1,3 +1,9 @@ +variable "base_hostname" { + type = string + description = "Base hostname to serve content from" + default = "dev.homelab" +} + variable "consul_address" { type = string } @@ -7,6 +13,7 @@ resource "nomad_job" "traefik" { enabled = true vars = { "consul_address" = "${var.consul_address}", + "base_hostname" = "${var.base_hostname}", } }