From b6988ce53f09665a17fff43901de46521b7b266a Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sat, 24 Feb 2024 23:26:12 +0100 Subject: [PATCH 1/6] feat(job): add option to pass in variables to job using the job_variables variable --- main.tf | 1 + variables.tf | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/main.tf b/main.tf index 4e2b9a5..0d08b95 100644 --- a/main.tf +++ b/main.tf @@ -12,6 +12,7 @@ resource "nomad_job" "this" { purge_on_destroy = true hcl2 { allow_fs = true + vars = contains(keys(var.jobs_variables), each.key) ? jobs_variables[each.key] : {} } } diff --git a/variables.tf b/variables.tf index d1ba18f..948b738 100644 --- a/variables.tf +++ b/variables.tf @@ -5,6 +5,12 @@ variable "jobs" { default = {} } +variable "jobs_variables" { + type = map(object({})) + default = {} + description = "Map of object to pass variables to the nomad job(s). Key is the job's name, value is a map of variables and their values" +} + variable "volumes" { type = map(object({ plugin_id = string From 8a8cc7c793891fbff30e5651692217c925e1fff1 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sat, 24 Feb 2024 23:26:56 +0100 Subject: [PATCH 2/6] chore(lint): linting --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 0d08b95..aa3d6dc 100644 --- a/main.tf +++ b/main.tf @@ -12,7 +12,7 @@ resource "nomad_job" "this" { purge_on_destroy = true hcl2 { allow_fs = true - vars = contains(keys(var.jobs_variables), each.key) ? jobs_variables[each.key] : {} + vars = contains(keys(var.jobs_variables), each.key) ? jobs_variables[each.key] : {} } } From 7d683b2a6acf4688b0138931e9b32f79408f9649 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sun, 25 Feb 2024 00:05:59 +0100 Subject: [PATCH 3/6] fix(job): wrong variable use in nomad job --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index aa3d6dc..ab14d77 100644 --- a/main.tf +++ b/main.tf @@ -12,7 +12,7 @@ resource "nomad_job" "this" { purge_on_destroy = true hcl2 { allow_fs = true - vars = contains(keys(var.jobs_variables), each.key) ? jobs_variables[each.key] : {} + vars = contains(keys(var.jobs_variables), each.key) ? var.jobs_variables[each.key] : {} } } From 439675a4a2e2a9e90d7d7acc09a5501e502acdfb Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sun, 25 Feb 2024 00:19:46 +0100 Subject: [PATCH 4/6] test(job): test passing the variables anyways --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index ab14d77..cb7df80 100644 --- a/main.tf +++ b/main.tf @@ -12,7 +12,7 @@ resource "nomad_job" "this" { purge_on_destroy = true hcl2 { allow_fs = true - vars = contains(keys(var.jobs_variables), each.key) ? var.jobs_variables[each.key] : {} + vars = var.jobs_variables[each.key] # contains(keys(var.jobs_variables), each.key) ? var.jobs_variables[each.key] : {} } } From 90641db7033100025bb8aa746fc33b53f1847e86 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sun, 25 Feb 2024 00:20:40 +0100 Subject: [PATCH 5/6] fix(job): revert testing --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index cb7df80..ab14d77 100644 --- a/main.tf +++ b/main.tf @@ -12,7 +12,7 @@ resource "nomad_job" "this" { purge_on_destroy = true hcl2 { allow_fs = true - vars = var.jobs_variables[each.key] # contains(keys(var.jobs_variables), each.key) ? var.jobs_variables[each.key] : {} + vars = contains(keys(var.jobs_variables), each.key) ? var.jobs_variables[each.key] : {} } } From 2830930c3c0203a172a7c8eaa1896422da6e03d1 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sun, 25 Feb 2024 12:11:48 +0100 Subject: [PATCH 6/6] fix(job): change jobs_variables type from map(object({})) to map(map(string)) to accept arbitrary values --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 948b738..dc9b6f6 100644 --- a/variables.tf +++ b/variables.tf @@ -6,7 +6,7 @@ variable "jobs" { } variable "jobs_variables" { - type = map(object({})) + type = map(map(string)) default = {} description = "Map of object to pass variables to the nomad job(s). Key is the job's name, value is a map of variables and their values" }