Be a bit more dynamic with host names

This commit is contained in:
IamTheFij 2022-03-13 10:13:19 -07:00
parent b2c03f1e60
commit 8efadf3d43
10 changed files with 43 additions and 35 deletions

View File

@ -3,12 +3,6 @@ variable "config_data" {
description = "Plain text config file for blocky"
}
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
job "blocky" {
datacenters = ["dc1"]
type = "service"
@ -29,19 +23,18 @@ job "blocky" {
}
service {
name = "dns"
name = "blocky-dns"
port = "dns"
}
service {
name = "web"
name = "blocky-api"
port = "web"
tags = [
"traefik.enable=true",
"traefik.consulcatalog.connect=false",
"traefik.http.routers.blocky.entrypoints=web,websecure",
"traefik.http.routers.blocky.rule=Host(`blocky.${var.base_hostname}`)",
"traefik.http.routers.blocky.tls=true",
]
}

View File

@ -5,7 +5,15 @@ variable "base_hostname" {
}
locals {
config_data = file("${path.module}/config.yml")
config_data = templatefile(
"${path.module}/config.yml",
{
"base_hostname" = "${var.base_hostname}",
# Could get this from consul_service.traefik
# but not sure what happens if it doens't exist yet
"ingress_address" = "192.168.2.106",
}
)
}
resource "nomad_job" "blocky" {
@ -13,7 +21,6 @@ resource "nomad_job" "blocky" {
enabled = true
vars = {
"config_data" = "${local.config_data}",
"base_hostname" = "${var.base_hostname}",
}
}

View File

@ -13,8 +13,7 @@ blocking:
customDNS:
customTTL: 1h
mapping:
# TODO: Use a variable for this
dev.homelab: 192.168.2.41
${base_hostname}: ${ingress_address}
port: 53
httpPort: 4000

View File

@ -13,7 +13,13 @@ job "grafana" {
}
}
ephemeral_disk {
migrate = true
sticky = true
}
service {
name = "grafana"
port = "web"
connect {
@ -47,8 +53,6 @@ job "grafana" {
tags = [
"traefik.enable=true",
"traefik.http.routers.grafana.entrypoints=web,websecure",
"traefik.http.routers.grafana.rule=Host(`grafana.dev.homelab`)",
"traefik.subdomain=grafana-sub",
"traefik.http.routers.grafana.tls=true",
]
}

View File

@ -1,9 +1,3 @@
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
variable "consul_address" {
type = string
description = "address of consul server for dynamic scraping"
@ -17,11 +11,19 @@ variable "consul_address" {
# jobspec = file("${path.module}/exporters.nomad")
# }
data "consul_nodes" "all-nodes" {
query_options {
datacenter = "dc1"
}
}
resource "nomad_job" "prometheus" {
hcl2 {
enabled = true
vars = {
"consul_address" = "${var.consul_address}",
# "consul_address" = "${var.consul_address}",
# TODO: Should this be a list?
"consul_address" = "http://${data.consul_nodes.all-nodes.nodes[0].address}:8500",
}
}

View File

@ -19,6 +19,11 @@ job "prometheus" {
}
}
ephemeral_disk {
migrate = true
sticky = true
}
service {
name = "prometheus"
port = "web"
@ -50,7 +55,6 @@ job "prometheus" {
tags = [
"traefik.enable=true",
"traefik.http.routers.prometheus.entrypoints=web,websecure",
"traefik.http.routers.prometheus.rule=Host(`prometheus.dev.homelab`)",
"traefik.http.routers.prometheus.tls=true",
]
}

View File

@ -1,9 +1,3 @@
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
variable "nextcloud_db" {
type = string
default = "nextcloud"
@ -64,7 +58,6 @@ job "nextcloud" {
tags = [
"traefik.enable=true",
"traefik.http.routers.nextcloud.entrypoints=web,websecure",
"traefik.http.routers.nextcloud.rule=Host(`nextcloud.${var.base_hostname}`)",
"traefik.http.routers.nextcloud.tls=true",
]
@ -126,4 +119,4 @@ job "nextcloud" {
}
}
}
}
}

View File

@ -20,7 +20,7 @@ data "consul_service" "read-nomad-cluster" {
}
locals {
nomad_node = data.consul_service.read-nomad-cluster.service[0]
nomad_node = data.consul_service.read-nomad-cluster.service[0]
nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}"
}
@ -55,7 +55,6 @@ module "metrics" {
source = "./metrics"
consul_address = var.consul_address
base_hostname = var.base_hostname
}
module "nextcloud" {

View File

@ -9,11 +9,18 @@ variable "consul_address" {
description = "address of consul server for dynamic routes"
}
data "consul_nodes" "all-nodes" {
query_options {
datacenter = "dc1"
}
}
resource "nomad_job" "traefik" {
hcl2 {
enabled = true
vars = {
"consul_address" = "${var.consul_address}",
# "consul_address" = "${var.consul_address}",
"consul_address" = "http://${data.consul_nodes.all-nodes.nodes[0].address}:8500",
"base_hostname" = "${var.base_hostname}",
}
}

View File

@ -27,6 +27,7 @@ job "whoami" {
}
service {
name = "whoami"
port = "web"
connect {
@ -55,7 +56,6 @@ job "whoami" {
tags = [
"traefik.enable=true",
"traefik.http.routers.whoami.entrypoints=web,websecure",
"traefik.http.routers.whoami.rule=Host(`whoami.${var.base_hostname}`)",
"traefik.http.routers.whoami.tls=true",
]
}