Terraform: add flake_ref to allow for branches

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2022-08-26 20:51:11 +02:00
parent ae174de04d
commit 5ed9ee1903
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
19 changed files with 52 additions and 18 deletions

11
main.tf
View file

@ -1,19 +1,19 @@
terraform {
backend "consul" {
address = "http://10.64.0.2:8500"
address = "http://10.64.2.1:8500"
scheme = "http"
path = "team/terraform/state"
}
}
provider "nomad" {
address = "http://10.64.0.2:4646"
address = "http://10.64.2.1:4646"
region = "homelab-1"
alias = "homelab-1"
}
provider "nomad" {
address = "http://10.64.0.2:4646"
address = "http://10.64.2.1:4646"
region = "do-1"
alias = "do-1"
}
@ -26,6 +26,10 @@ variable "flake_rev" {
type = string
}
variable "flake_ref" {
type = string
}
variable "flake_host" {
type = string
}
@ -42,6 +46,7 @@ module "nomad" {
source = "./nomad"
flake_rev = var.flake_rev
flake_ref = var.flake_ref
flake_host = var.flake_host
flake_host_alt = var.flake_host_alt
flake_sha = var.flake_sha

View file

@ -13,6 +13,10 @@ variable "flake_rev" {
type = string
}
variable "flake_ref" {
type = string
}
variable "flake_host" {
type = string
}
@ -29,6 +33,7 @@ module "regions" {
source = "./regions"
flake_rev = var.flake_rev
flake_ref = var.flake_ref
flake_host = var.flake_host
flake_host_alt = var.flake_host_alt
flake_sha = var.flake_sha

View file

@ -15,7 +15,7 @@ resource "nomad_volume" "ingress-letsencrypt" {
}
context = {
server = "10.64.1.201"
server = "10.64.2.1"
share = "/var/nfs/ingress-letsencrypt"
}
@ -31,7 +31,7 @@ resource "nomad_job" "ingress" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host_alt}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host_alt}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
upstreams = data.local_file.ingress-upstreams.content

View file

@ -8,6 +8,10 @@ variable "flake_rev" {
type = string
}
variable "flake_ref" {
type = string
}
variable "flake_sha" {
type = string
}

View file

@ -50,7 +50,7 @@ resource "nomad_job" "baikal" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -13,7 +13,7 @@ resource "nomad_job" "camptules" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -68,7 +68,7 @@ resource "nomad_job" "email" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -59,7 +59,7 @@ resource "nomad_job" "gitea" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host_alt}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host_alt}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -104,7 +104,7 @@ resource "nomad_job" "home-assistant" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -85,7 +85,7 @@ resource "nomad_job" "hydra" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -8,7 +8,7 @@ resource "nomad_job" "ingress" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
upstreams = data.local_file.ingress-upstreams.content

View file

@ -82,6 +82,15 @@ job "gitea" {
flake_ref = "${var.flake_ref}#nixngSystems.gitea.config.system.build.toplevel"
flake_sha = var.flake_sha
entrypoint = [ "init" ]
# mounts = [
# {
# type = "bind"
# target = "/var/nfs/gitea-data"
# source = "/data/gitea"
# options = ["rbind","rw","x-mount.mkdir"]
# }
# ]
}
env {

View file

@ -152,7 +152,7 @@ EOF
memory = 128
memory_max = 256
}
volume_mount {
volume = "home-assistant_mosquitto"
destination = "/var/mosquitto"
@ -246,6 +246,7 @@ LATITUDE={{ .Data.data.latitude }}
LONGTITUDE={{ .Data.data.longtitude }}
ELEVATION={{ .Data.data.elevation }}
TIME_ZONE={{ .Data.data.time_zone }}
ALARM_CODE={{ .Data.data.alarm_code }}
{{ end }}
EOF
destination = "secrets/environment"

View file

@ -84,7 +84,7 @@ job "jellyfin" {
driver = "docker"
config {
image = "jellyfin/jellyfin@sha256:b4500b143d8a0d4383c50721517908d679af1c5ec00e791f0097f8c419b3e853"
image = "jellyfin/jellyfin@sha256:73501b70b0e884e5815d8f03d22973513ae7cadbcd8dba95da60e1d7c82dac7b"
devices = [
{

View file

@ -2,6 +2,10 @@ variable "flake_rev" {
type = string
}
variable "flake_ref" {
type = string
}
variable "flake_sha" {
type = string
}
@ -15,7 +19,7 @@ variable "flake_host_alt" {
}
provider "nomad" {
address = "http://10.64.1.201:4646"
address = "http://10.64.2.1:4646"
region = "homelab-1"
alias = "homelab-1"
}

View file

@ -4,7 +4,7 @@ resource "nomad_job" "reicio" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -73,7 +73,7 @@ resource "nomad_job" "syncthing" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -4,7 +4,7 @@ resource "nomad_job" "website" {
hcl2 {
enabled = true
vars = {
flake_ref = "${var.flake_host}?rev=${var.flake_rev}"
flake_ref = "${var.flake_host}?rev=${var.flake_rev}&ref=${var.flake_ref}"
flake_sha = var.flake_sha
}
}

View file

@ -13,6 +13,10 @@ variable "flake_rev" {
type = string
}
variable "flake_ref" {
type = string
}
variable "flake_sha" {
type = string
}
@ -29,6 +33,7 @@ module "do-1" {
source = "./do-1"
flake_rev = var.flake_rev
flake_ref = var.flake_ref
flake_host = var.flake_host
flake_host_alt = var.flake_host_alt
flake_sha = var.flake_sha
@ -42,6 +47,7 @@ module "homelab-1" {
source = "./homelab-1"
flake_rev = var.flake_rev
flake_ref = var.flake_ref
flake_host = var.flake_host
flake_host_alt = var.flake_host_alt
flake_sha = var.flake_sha