orchestration-tests/nomad/services.tf

67 lines
1.3 KiB
Terraform
Raw Normal View History

2022-02-16 17:56:18 +00:00
# Configure Consul provider
variable "consul_address" {
2022-02-17 22:03:42 +00:00
type = string
2022-02-16 17:56:18 +00:00
default = "http://192.168.2.41:8500"
}
2022-02-28 20:07:25 +00:00
variable "base_hostname" {
type = string
description = "Base hostname to serve content from"
default = "dev.homelab"
}
2022-02-16 17:56:18 +00:00
provider "consul" {
2022-02-17 22:03:42 +00:00
address = var.consul_address
2022-02-16 17:56:18 +00:00
}
# Get Nomad client from Consul
data "consul_service" "read-nomad-cluster" {
2022-02-17 22:03:42 +00:00
name = "nomad-client"
2022-02-16 17:56:18 +00:00
}
locals {
2022-02-17 22:03:42 +00:00
nomad_node = data.consul_service.read-nomad-cluster.service[0]
2022-02-16 17:56:18 +00:00
nomad_node_address = "http://${local.nomad_node.node_address}:${local.nomad_node.port}"
}
2022-02-27 23:22:09 +00:00
# Configure the Nomad provider
2022-02-16 17:56:18 +00:00
provider "nomad" {
2022-02-17 22:03:42 +00:00
address = local.nomad_node_address
2022-02-16 17:56:18 +00:00
region = "global"
}
2022-02-27 23:22:09 +00:00
# Define services as modules
2022-02-16 17:56:18 +00:00
2022-02-27 23:22:09 +00:00
module "mysql-server" {
source = "./mysql"
2022-02-28 20:07:25 +00:00
base_hostname = var.base_hostname
2022-02-16 17:56:18 +00:00
}
2022-02-27 23:22:09 +00:00
module "traefik" {
source = "./traefik"
2022-02-16 17:56:18 +00:00
2022-02-27 23:22:09 +00:00
consul_address = var.consul_address
2022-02-28 20:07:25 +00:00
base_hostname = var.base_hostname
2022-02-16 17:56:18 +00:00
}
2022-02-27 23:22:09 +00:00
module "nextcloud" {
source = "./nextcloud"
2022-02-16 17:56:18 +00:00
2022-02-28 20:07:25 +00:00
base_hostname = var.base_hostname
2022-02-27 23:22:09 +00:00
depends_on = [module.mysql-server]
2022-02-16 17:56:18 +00:00
}
resource "nomad_job" "whoami" {
hcl2 {
enabled = true
vars = {
2022-02-28 20:07:25 +00:00
"count" = "${2 * length(data.consul_service.read-nomad-cluster.service)}",
"base_hostname" = "${var.base_hostname}",
}
2022-02-16 17:56:18 +00:00
}
jobspec = file("${path.module}/whoami.nomad")
}