73 lines
1.4 KiB
HCL
73 lines
1.4 KiB
HCL
# Configure Consul provider
|
|
variable "consul_address" {
|
|
type = string
|
|
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
|
|
}
|
|
|
|
# Get Nomad client from Consul
|
|
data "consul_service" "read-nomad-cluster" {
|
|
name = "nomad-client"
|
|
}
|
|
|
|
locals {
|
|
nomad_node = data.consul_service.read-nomad-cluster.service[0]
|
|
nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}"
|
|
}
|
|
|
|
# Configure the Nomad provider
|
|
provider "nomad" {
|
|
address = local.nomad_node_address
|
|
region = "global"
|
|
}
|
|
|
|
# Define services as modules
|
|
|
|
module "mysql-server" {
|
|
source = "./mysql"
|
|
|
|
base_hostname = var.base_hostname
|
|
}
|
|
|
|
module "blocky" {
|
|
source = "./blocky"
|
|
|
|
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]
|
|
}
|
|
|
|
resource "nomad_job" "whoami" {
|
|
hcl2 {
|
|
enabled = true
|
|
vars = {
|
|
"count" = "${2 * length(data.consul_service.read-nomad-cluster.service)}",
|
|
"base_hostname" = "${var.base_hostname}",
|
|
}
|
|
}
|
|
|
|
jobspec = file("${path.module}/whoami.nomad")
|
|
}
|