Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified _examples/coredns.tf
100644 → 100755
Empty file.
Empty file modified _examples/grafana.tf
100644 → 100755
Empty file.
Empty file modified _examples/influxdb.tf
100644 → 100755
Empty file.
Empty file modified _examples/mongodb.tf
100644 → 100755
Empty file.
Empty file modified _examples/mosquitto.tf
100644 → 100755
Empty file.
Empty file modified _examples/nginx-default.conf
100644 → 100755
Empty file.
Empty file modified _examples/nginx.tf
100644 → 100755
Empty file.
25 changes: 24 additions & 1 deletion _examples/openldap.tf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Example LDAP server, using the bitnami/openldap docker image
// Example LDAP server
module "openldap" {
source = "github.com/mutablelogic/tf-nomad//openldap"

Expand All @@ -19,3 +19,26 @@ module "openldap" {
replication_hosts = ["ldap://server1:389/", "ldap://server2:389/"] // LDAP urls for replication
data = "/var/lib/ldap" // Directory for data persistence
}

// Example LDAP admin
module "openldap-admin" {
source = "github.com/mutablelogic/tf-nomad//openldap-admin"

// Required parameters
dc = var.dc
hosts = ["server1", "server2"] // Host constraint for the job
organization = "My Organization" // Distinquished name for the LDAP server
domain = "example.com" // Domain for the LDAP server
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user

// Other parameters
enabled = true
namespace = var.namespace
docker_tag = "latest" // Pull the latest version of the docker image every job restart
port = 5000 // plaintext port to expose

// LDAP details
service_dns = ["192.168.86.11", "192.168.86.12"]
url = "ldap://openldap-ldap.default.nomad/"
basedn = "dc=mutablelogic,dc=com"
}
Empty file modified _examples/postgresql.tf
100644 → 100755
Empty file.
Empty file modified _examples/seaweedfs.tf
100644 → 100755
Empty file.
Empty file modified _examples/telegraf.tf
100644 → 100755
Empty file.
Empty file modified coredns/config/Corefile
100644 → 100755
Empty file.
Empty file modified coredns/input.tf
100644 → 100755
Empty file.
Empty file modified coredns/locals.tf
100644 → 100755
Empty file.
Empty file modified coredns/main.tf
100644 → 100755
Empty file.
Empty file modified coredns/nomad/coredns.hcl
100644 → 100755
Empty file.
Empty file modified coredns/providers.tf
100644 → 100755
Empty file.
52 changes: 52 additions & 0 deletions github-action-runner/input.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

variable "dc" {
type = string
description = "Data center name"
}

variable "namespace" {
type = string
description = "Nomad namespace"
default = "default"
}

variable "enabled" {
type = bool
description = "If false, then no job is deployed"
default = true
}

variable "docker_tag" {
type = string
description = "Version of the docker image to use, defaults to latest"
default = "latest"
}

variable "service_dns" {
description = "Service discovery DNS"
type = list(string)
default = []
}

variable "service_type" {
description = "Run as a service or system"
type = string
default = "service"
}

variable "hosts" {
type = list(string)
description = "List of hosts to deploy on. If empty, one allocation will be created"
default = []
}

variable "access_token" {
description = "Github access token"
type = string
sensitive = true
}

variable "organization" {
description = "Github organization"
type = string
}
5 changes: 5 additions & 0 deletions github-action-runner/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

locals {
docker_image = "ghcr.io/actions/actions-runner:${var.docker_tag}"
docker_always_pull = var.docker_tag == "latest" ? true : false
}
20 changes: 20 additions & 0 deletions github-action-runner/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

resource "nomad_job" "github-action-runner" {
count = var.enabled ? 1 : 0
jobspec = file("${path.module}/nomad/github-action-runner.hcl")

hcl2 {
vars = {
dc = jsonencode([var.dc])
namespace = var.namespace
hosts = jsonencode(var.hosts)
docker_image = local.docker_image
docker_always_pull = jsonencode(local.docker_always_pull)
service_dns = jsonencode(var.service_dns)
service_type = var.service_type

access_token = var.access_token
organization = var.organization
}
}
}
113 changes: 113 additions & 0 deletions github-action-runner/nomad/github-action-runner.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

// github action runner
// Docker Image: ghcr.io/actions/actions-runner

///////////////////////////////////////////////////////////////////////////////
// VARIABLES

variable "dc" {
description = "data centers that the job is eligible to run in"
type = list(string)
}

variable "namespace" {
description = "namespace that the job runs in"
type = string
default = "default"
}

variable "hosts" {
description = "host constraint for the job, defaults to one host"
type = list(string)
default = []
}

variable "service_dns" {
description = "Service discovery DNS"
type = list(string)
default = []
}

variable "service_type" {
description = "Run as a service or system"
type = string
default = "service"
}

variable "docker_image" {
description = "Docker image"
type = string
}

variable "docker_always_pull" {
description = "Pull docker image on every job restart"
type = bool
default = false
}

///////////////////////////////////////////////////////////////////////////////

variable "access_token" {
description = "Github access token"
type = string
}

variable "organization" {
description = "Github organization"
type = string
}

///////////////////////////////////////////////////////////////////////////////
// JOB

job "github-action-runner" {
type = var.service_type
datacenters = var.dc
namespace = var.namespace

update {
min_healthy_time = "10s"
healthy_deadline = "5m"
health_check = "task_states"
}

/////////////////////////////////////////////////////////////////////////////////

group "github-action-runner" {
count = (length(var.hosts) == 0 || var.service_type == "system") ? 1 : length(var.hosts)

dynamic "constraint" {
for_each = length(var.hosts) == 0 ? [] : [join(",", var.hosts)]
content {
attribute = node.unique.name
operator = "set_contains_any"
value = constraint.value
}
}

// token task runs to obtain a runner token
task "token" {
driver = "docker"

lifecycle {
hook = "prestart"
sidecar = false
}

env {
ACCESS_TOKEN = var.access_token
ORGANIZATION = var.organization
}

config {
image = "curlimages/curl"
dns_servers = var.service_dns
args = [
"sh",
"-c",
"curl -s -X \"POST\" -H \"Authorization: token ${ACCESS_TOKEN}\" https://api.github.com/orgs/${ORGANIZATION}/actions/runners/registration-token"
]
}
} // task "token"
} // group "grafana"
} // job "grafana"
Empty file modified grafana/input.tf
100644 → 100755
Empty file.
Empty file modified grafana/locals.tf
100644 → 100755
Empty file.
Empty file modified grafana/main.tf
100644 → 100755
Empty file.
Empty file modified grafana/nomad/grafana.hcl
100644 → 100755
Empty file.
Empty file modified influxdb/input.tf
100644 → 100755
Empty file.
Empty file modified influxdb/locals.tf
100644 → 100755
Empty file.
Empty file modified influxdb/main.tf
100644 → 100755
Empty file.
Empty file modified influxdb/nomad/influxdb.hcl
100644 → 100755
Empty file.
Empty file modified influxdb/providers.tf
100644 → 100755
Empty file.
Empty file modified mongodb/input.tf
100644 → 100755
Empty file.
Empty file modified mongodb/locals.tf
100644 → 100755
Empty file.
Empty file modified mongodb/main.tf
100644 → 100755
Empty file.
Empty file modified mongodb/nomad/mongodb.hcl
100644 → 100755
Empty file.
Empty file modified mongodb/providers.tf
100644 → 100755
Empty file.
Empty file modified mosquitto/input.tf
100644 → 100755
Empty file.
Empty file modified mosquitto/locals.tf
100644 → 100755
Empty file.
Empty file modified mosquitto/main.tf
100644 → 100755
Empty file.
Empty file modified mosquitto/nomad/mosquitto.hcl
100644 → 100755
Empty file.
Empty file modified mosquitto/providers.tf
100644 → 100755
Empty file.
Empty file modified nginx/config/fastcgi.conf
100644 → 100755
Empty file.
Empty file modified nginx/config/mimetypes.conf
100644 → 100755
Empty file.
Empty file modified nginx/config/nginx.conf
100644 → 100755
Empty file.
Empty file modified nginx/input.tf
100644 → 100755
Empty file.
Empty file modified nginx/locals.tf
100644 → 100755
Empty file.
Empty file modified nginx/main.tf
100644 → 100755
Empty file.
Empty file modified nginx/nomad/nginx.hcl
100644 → 100755
Empty file.
Empty file modified nginx/providers.tf
100644 → 100755
Empty file.
85 changes: 85 additions & 0 deletions openldap-admin/input.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

variable "dc" {
type = string
description = "Data center name"
}

variable "namespace" {
type = string
description = "Nomad namespace"
default = "default"
}

variable "enabled" {
type = bool
description = "If false, then no job is deployed"
default = true
}

variable "docker_tag" {
type = string
description = "Version of the docker image to use, defaults to latest"
default = "latest"
}

variable "service_provider" {
description = "Service provider, either consul or nomad"
type = string
default = "nomad"
}

variable "service_name" {
description = "Service name"
type = string
default = "openldap-admin"
}

variable "service_dns" {
description = "Service discovery DNS"
type = list(string)
default = []
}

variable "service_type" {
description = "Run as a service or system"
type = string
default = "service"
}

variable "hosts" {
type = list(string)
description = "List of hosts to deploy on. If empty, one allocation will be created"
default = []
}

variable "port" {
type = number
description = "Port to expose plaintext service"
default = 5000
}

variable "url" {
description = "LDAP server url"
type = string
}

variable "basedn" {
description = "LDAP base distinguished name"
type = string
}

variable "admin_password" {
description = "LDAP admin password"
type = string
sensitive = true
}

variable "organization" {
description = "Organization name"
type = string
}

variable "domain" {
description = "Organization domain"
type = string
}
5 changes: 5 additions & 0 deletions openldap-admin/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

locals {
docker_image = "wheelybird/ldap-user-manager:${var.docker_tag}"
docker_always_pull = var.docker_tag == "latest" ? true : false
}
27 changes: 27 additions & 0 deletions openldap-admin/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

resource "nomad_job" "openldap" {
count = var.enabled ? 1 : 0
jobspec = file("${path.module}/nomad/openldap-admin.hcl")

hcl2 {
allow_fs = true
vars = {
dc = jsonencode([var.dc])
namespace = var.namespace
hosts = jsonencode(var.hosts)
docker_image = local.docker_image
docker_always_pull = jsonencode(local.docker_always_pull)
service_provider = var.service_provider
service_name = var.service_name
service_dns = jsonencode(var.service_dns)
service_type = var.service_type

port = var.port
url = var.url
basedn = var.basedn
admin_password = var.admin_password
organization = var.organization
domain = var.domain
}
}
}
Loading