-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
42 lines (37 loc) · 1.46 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
locals {
environment_variables = contains(keys(var.applications), var.waypoint_application) ? merge({
NAME = var.waypoint_application
MESSAGE = var.applications[var.waypoint_application].nomad_clues
}, var.environment_variables) : var.environment_variables
metadata = contains(keys(var.applications), var.waypoint_application) ? merge({
"waypoint.provisioned" = "true"
"waypoint.additional_details" = var.applications[var.waypoint_application].waypoint_clues
}, var.metadata) : var.metadata
}
data "nomad_job_parser" "application" {
hcl = templatefile("${path.module}/templates/jobspec.hcl", {
application_name = var.waypoint_application
application_port = var.application_port
application_count = var.application_count
node_pool = var.node_pool
driver = var.driver
command = var.command
args = var.args
cpu = var.cpu
memory = var.memory
image = var.image
service_provider = var.service_provider
metadata = local.metadata
has_nomad_vars = length(nomad_variable.application) > 0
})
canonicalize = false
}
resource "nomad_variable" "application" {
count = length(local.environment_variables) != 0 ? 1 : 0
path = "nomad/jobs/${var.waypoint_application}"
items = local.environment_variables
}
resource "nomad_job" "application" {
jobspec = data.nomad_job_parser.application.json
json = true
}