Allow binding ports directly to service container
This commit is contained in:
parent
36fa152553
commit
ee6f7bd937
@ -1,3 +1,10 @@
|
||||
locals {
|
||||
port_names = concat(
|
||||
var.service_port != null ? ["main"] : [],
|
||||
[for port in var.ports : port.name if port.task_config],
|
||||
)
|
||||
}
|
||||
|
||||
resource "nomad_job" "service" {
|
||||
jobspec = templatefile("${path.module}/service_template.nomad", {
|
||||
name = var.name
|
||||
@ -20,6 +27,7 @@ resource "nomad_job" "service" {
|
||||
service_port_static = var.service_port_static
|
||||
service_check = var.service_check
|
||||
ports = var.ports
|
||||
port_names = local.port_names
|
||||
sticky_disk = var.sticky_disk
|
||||
resources = var.resources
|
||||
stunnel_resources = var.stunnel_resources
|
||||
|
@ -152,8 +152,8 @@ job "${name}" {
|
||||
%{~if image_pull_timeout != null ~}
|
||||
image_pull_timeout = "${image_pull_timeout}"
|
||||
%{~ endif ~}
|
||||
%{~ if service_port != null ~}
|
||||
ports = ["main"]
|
||||
%{~ if length(try(port_names, [])) > 0 ~}
|
||||
ports = ${jsonencode(port_names)}
|
||||
%{~ endif ~}
|
||||
%{~ if length(try(args, [])) > 0 ~}
|
||||
args = ${jsonencode(args)}
|
||||
|
@ -77,6 +77,19 @@ variable "service_port_static" {
|
||||
description = "Should the port assigned be static"
|
||||
}
|
||||
|
||||
variable "ports" {
|
||||
type = list(object({
|
||||
name = string
|
||||
host_network = optional(string)
|
||||
from = optional(number)
|
||||
to = optional(number)
|
||||
static = optional(number)
|
||||
task_config = optional(bool, false)
|
||||
}))
|
||||
default = []
|
||||
description = "Additional ports (not service_port) to be bound."
|
||||
}
|
||||
|
||||
variable "prometheus" {
|
||||
type = bool
|
||||
default = false
|
||||
@ -155,18 +168,6 @@ variable "service_tags" {
|
||||
description = "Additional tags to be added to the service."
|
||||
}
|
||||
|
||||
variable "ports" {
|
||||
type = list(object({
|
||||
name = string
|
||||
host_network = optional(string)
|
||||
from = optional(number)
|
||||
to = optional(number)
|
||||
static = optional(number)
|
||||
}))
|
||||
default = []
|
||||
description = "Additional ports (not service_port) to be bound."
|
||||
}
|
||||
|
||||
variable "templates" {
|
||||
type = list(object({
|
||||
data = string
|
||||
|
Loading…
Reference in New Issue
Block a user