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

View file

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

View file

@ -15,7 +15,7 @@ resource "nomad_volume" "ingress-letsencrypt" {
} }
context = { context = {
server = "10.64.1.201" server = "10.64.2.1"
share = "/var/nfs/ingress-letsencrypt" share = "/var/nfs/ingress-letsencrypt"
} }
@ -31,7 +31,7 @@ resource "nomad_job" "ingress" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
upstreams = data.local_file.ingress-upstreams.content upstreams = data.local_file.ingress-upstreams.content

View file

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

View file

@ -50,7 +50,7 @@ resource "nomad_job" "baikal" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -13,7 +13,7 @@ resource "nomad_job" "camptules" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -68,7 +68,7 @@ resource "nomad_job" "email" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -59,7 +59,7 @@ resource "nomad_job" "gitea" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -104,7 +104,7 @@ resource "nomad_job" "home-assistant" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -85,7 +85,7 @@ resource "nomad_job" "hydra" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -8,7 +8,7 @@ resource "nomad_job" "ingress" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
upstreams = data.local_file.ingress-upstreams.content 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_ref = "${var.flake_ref}#nixngSystems.gitea.config.system.build.toplevel"
flake_sha = var.flake_sha flake_sha = var.flake_sha
entrypoint = [ "init" ] entrypoint = [ "init" ]
# mounts = [
# {
# type = "bind"
# target = "/var/nfs/gitea-data"
# source = "/data/gitea"
# options = ["rbind","rw","x-mount.mkdir"]
# }
# ]
} }
env { env {

View file

@ -246,6 +246,7 @@ LATITUDE={{ .Data.data.latitude }}
LONGTITUDE={{ .Data.data.longtitude }} LONGTITUDE={{ .Data.data.longtitude }}
ELEVATION={{ .Data.data.elevation }} ELEVATION={{ .Data.data.elevation }}
TIME_ZONE={{ .Data.data.time_zone }} TIME_ZONE={{ .Data.data.time_zone }}
ALARM_CODE={{ .Data.data.alarm_code }}
{{ end }} {{ end }}
EOF EOF
destination = "secrets/environment" destination = "secrets/environment"

View file

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

View file

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

View file

@ -4,7 +4,7 @@ resource "nomad_job" "reicio" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -73,7 +73,7 @@ resource "nomad_job" "syncthing" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

@ -4,7 +4,7 @@ resource "nomad_job" "website" {
hcl2 { hcl2 {
enabled = true enabled = true
vars = { 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 flake_sha = var.flake_sha
} }
} }

View file

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