Skip to content

support 'path variables' in nomad job files #10938

@kevinschoonover

Description

@kevinschoonover

Proposal

Add support for getting absolute path to job file via a path.X variable such as in:

Use-cases

I am running tempo in microservices mode in which each microservice shares a configuration across multiple groups/jobs. Instead of copying an pasting the configuration into a template stanza, I use the file function to share it:

# tempo.hcl
template {
  data        = file("tempo.yml.j2")
  destination = "${NOMAD_TASK_DIR}/tempo.yaml"
}

; however, this requires me to run nomad run tempo.hcl in the same directory as tempo.hcl where as something like

# tempo.hcl
template {
  data        = file("${path.job_file}/tempo.yml.j2")
  destination = "${NOMAD_TASK_DIR}/tempo.yaml"
}

would allow me to run it in any arbitrary directory such as ../../.

Attempted Solutions

I tried using the abspath function since it mentions

abspath takes a string containing a filesystem path and converts it to an absolute path. That is, if the path is not absolute, it will be joined with the job file directory.

but it returns the absolute path to the directoy I am running the nomad cli in and not to the jobfile.

# tempo.hcl
template {
  data        = file(abspath("${path.job_file}/tempo.yml.j2") # 
  destination = "${NOMAD_TASK_DIR}/tempo.yaml"
}
$ nomad run jobs/observability/tempo.hcl
tempo.hcl:877,23-28: Error in function call; Call to function "file" failed: no file exists at ${pwd}\tempo.yml.j2.
tempo.hcl:877,23-28: Unsuitable value type; Unsuitable value: value must be known

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Needs Roadmapping

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions