Opensearch/elasticsearch job env variables

I am trying to create a nomad job for opensearch/elasticsearch and that requires several environment variables to be set but it uses a peculiar naming convention (it allows for dots in the key name). While running the job below nomad throws an error, I havent been able to escape the name in such a way that nomad accepts the job configuration.

task "server" {
      driver = "docker"

      config {
        image   = "opensearchproject/opensearch:latest"
        ports   = ["http","performance"]
      }

      env {
        discovery.type = "single-node"
      }

      resources {
        cpu    = 200
        memory = 4096
      }
    }
Parse Error
input.hcl:49,9-18: Argument or block definition required; An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

hi
Could you show the whole configuration of the job you are trying to use?
I want to see if there are any issues outside of the task area.

Hi @attachmentgenie,

I believe that error is pointing to that env block instantiation and that it requires an equals sign. I just tested this locally and got the results I believe you are looking for using the example below.

env = {
  "discovery.type" = "single-node"
}
$ nomad alloc exec 40e00887 env |grep "discovery.type"
discovery.type=single-node

As described in the Nomad env block documentation:

Environment variables that aren’t valid HCLv2 identifiers, like ones containing . , require an alternative map assignment syntax.

Thanks,
jrasell and the Nomad team

if i update to your suggestion nomad (v1.2.6) throws the following error, going to check on a more recent 1.4 if that setup will work.

Parse Error
input.hcl:49,9-10: Invalid argument name; Argument names must not be quoted.

nope my bad missed the env { switching to env = { now it works! thanks

2 Likes