Be a bit more dynamic with host names

This commit is contained in:
IamTheFij 2022-03-13 10:13:19 -07:00
parent 99889f032d
commit 535dba941b
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" description = "Plain text config file for blocky"
} }
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
job "blocky" { job "blocky" {
datacenters = ["dc1"] datacenters = ["dc1"]
type = "service" type = "service"
@ -29,19 +23,18 @@ job "blocky" {
} }
service { service {
name = "dns" name = "blocky-dns"
port = "dns" port = "dns"
} }
service { service {
name = "web" name = "blocky-api"
port = "web" port = "web"
tags = [ tags = [
"traefik.enable=true", "traefik.enable=true",
"traefik.consulcatalog.connect=false", "traefik.consulcatalog.connect=false",
"traefik.http.routers.blocky.entrypoints=web,websecure", "traefik.http.routers.blocky.entrypoints=web,websecure",
"traefik.http.routers.blocky.rule=Host(`blocky.${var.base_hostname}`)",
"traefik.http.routers.blocky.tls=true", "traefik.http.routers.blocky.tls=true",
] ]
} }

View File

@ -5,7 +5,15 @@ variable "base_hostname" {
} }
locals { 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" { resource "nomad_job" "blocky" {
@ -13,7 +21,6 @@ resource "nomad_job" "blocky" {
enabled = true enabled = true
vars = { vars = {
"config_data" = "${local.config_data}", "config_data" = "${local.config_data}",
"base_hostname" = "${var.base_hostname}",
} }
} }

View File

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

View File

@ -13,7 +13,13 @@ job "grafana" {
} }
} }
ephemeral_disk {
migrate = true
sticky = true
}
service { service {
name = "grafana"
port = "web" port = "web"
connect { connect {
@ -47,8 +53,6 @@ job "grafana" {
tags = [ tags = [
"traefik.enable=true", "traefik.enable=true",
"traefik.http.routers.grafana.entrypoints=web,websecure", "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", "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" { variable "consul_address" {
type = string type = string
description = "address of consul server for dynamic scraping" description = "address of consul server for dynamic scraping"
@ -17,11 +11,19 @@ variable "consul_address" {
# jobspec = file("${path.module}/exporters.nomad") # jobspec = file("${path.module}/exporters.nomad")
# } # }
data "consul_nodes" "all-nodes" {
query_options {
datacenter = "dc1"
}
}
resource "nomad_job" "prometheus" { resource "nomad_job" "prometheus" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 { service {
name = "prometheus" name = "prometheus"
port = "web" port = "web"
@ -50,7 +55,6 @@ job "prometheus" {
tags = [ tags = [
"traefik.enable=true", "traefik.enable=true",
"traefik.http.routers.prometheus.entrypoints=web,websecure", "traefik.http.routers.prometheus.entrypoints=web,websecure",
"traefik.http.routers.prometheus.rule=Host(`prometheus.dev.homelab`)",
"traefik.http.routers.prometheus.tls=true", "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" { variable "nextcloud_db" {
type = string type = string
default = "nextcloud" default = "nextcloud"
@ -64,7 +58,6 @@ job "nextcloud" {
tags = [ tags = [
"traefik.enable=true", "traefik.enable=true",
"traefik.http.routers.nextcloud.entrypoints=web,websecure", "traefik.http.routers.nextcloud.entrypoints=web,websecure",
"traefik.http.routers.nextcloud.rule=Host(`nextcloud.${var.base_hostname}`)",
"traefik.http.routers.nextcloud.tls=true", "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 { 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}" nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}"
} }
@ -55,7 +55,6 @@ module "metrics" {
source = "./metrics" source = "./metrics"
consul_address = var.consul_address consul_address = var.consul_address
base_hostname = var.base_hostname
} }
module "nextcloud" { module "nextcloud" {

View File

@ -9,11 +9,18 @@ variable "consul_address" {
description = "address of consul server for dynamic routes" description = "address of consul server for dynamic routes"
} }
data "consul_nodes" "all-nodes" {
query_options {
datacenter = "dc1"
}
}
resource "nomad_job" "traefik" { resource "nomad_job" "traefik" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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}", "base_hostname" = "${var.base_hostname}",
} }
} }

View File

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