# Nomad Vault Integration

**URL:** <https://discuss.hashicorp.com/t/nomad-vault-integration/40077>\
**Category:** Nomad\
**Tags:** vault\
**Created:** [May 27, 2022, 3:47am UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077 "2022-05-27T03:47:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas.saroha](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/vikas.saroha/32/22026_2.png) [@vikas.saroha](https://discuss.hashicorp.com/u/vikas.saroha)\
**Post date:** [May 27, 2022, 3:47am UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077/1 "2022-05-27T03:47:47Z")

</div>

Hi,

I am trying to inject secrets from Vault into my Nomad task via template.

While I have had success with this template -

```auto
template {
  data = <<EOH
    {{ with secret "aws/data/s3" }}
      SECRET1 = {{ .Data.data.secret1 }}
      SECRET2 = {{ .Data.data.secret2 }}
    {{ end }}
  EOH

  destination = "secrets/env"
  env = true
}

```

This pattern becomes a bit tedious when there are over 100 secrets at this path.

Is there a way to iterate over the returned secrets and get the key and value like so -

```auto
{{ with secret "aws/data/s3" }}
   {{ range $k,$v := .Data.data }}
     {{ $k }} = {{ $v }}
   {{end}}
{{ end }}

```

This template with `range` throws an error `Template failed: (dynamic): parse: template: :13: unexpected "," in range`

To me it looks to be valid syntax but Nomad doesn’t like it.

I have also tried this pattern ([Using Hashicorp Nomad’s Vault integration | by Amanda Edades | Medium](https://medium.com/@amandaedades/using-nomads-vault-integration-80574d14c6c))

```auto
template {
  data = <<EOH
{{ range secrets "aws/metadata/" }}
{{ (printf "%s" .) | toUpper }}={{ with secret (printf "aws/data/%s" .) }}{{ .Data.data.value }}{{ end }}
{{ end }}
EOH

  destination = "secrets/file.env"
  env = true
}

```

But I get this error `Template Missing: vault.list(aws/metadata)`

Appreciate any help on this.

Thanks,  
Vikas

---

<div class="post-metadata">

**Author:** ![jrasell](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jrasell/32/5500_2.png) [@jrasell](https://discuss.hashicorp.com/u/jrasell)\
**Post date:** [May 27, 2022, 9:18am UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077/2 "2022-05-27T09:18:24Z")

</div>

Hi @vikas.saroha,

What secrets engine is this path using? Some engines do not support listing.

According to the [consul-template docs](https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md#secrets) the syntax should look as follows:

```auto
{{ range secrets "aws/metadata/" }}
{{ with secret (printf "secret/%s" .) }}{{ range $k, $v := .Data }}
{{ $k }}: {{ $v }}
{{ end }}{{ end }}{{ end }}

```

Thanks,  
jrasell and the Nomad team

---

<div class="post-metadata">

**Author:** ![vikas.saroha](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/vikas.saroha/32/22026_2.png) [@vikas.saroha](https://discuss.hashicorp.com/u/vikas.saroha)\
**Post date:** [May 27, 2022, 12:45pm UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077/3 "2022-05-27T12:45:59Z")

</div>

Thanks for your reply @jrasell .

This is for the `V2 KV secrets engine`

Unfortunately I am still seeing the same error

```auto
Template Missing: vault.list(aws/metadata)

```

The list command on this path is working from vault cli, so listing on this engine/path is supported.

```auto
$ vault kv list aws  ✔  
Keys
----
s3

```

I am using the same policy for the cli as the job, so doesn’t look like its an issue with permissions either.

```auto
Vault v1.10.1
Nomad v1.3.1

```

---

<div class="post-metadata">

**Author:** ![jrasell](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jrasell/32/5500_2.png) [@jrasell](https://discuss.hashicorp.com/u/jrasell)\
**Post date:** [May 27, 2022, 1:03pm UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077/4 "2022-05-27T13:03:03Z")

</div>

Hi @vikas.saroha,

`.Data` should be replaced with `.Data.data` for KV-V2 secrets engines.

The Vault CLI list only shows `s3` and not `metadata` which you are calling from the template. Is the CLI output you’ve shown cut short? What does `vault kv list aws/metadata/` show?

Thanks,  
jrasell and the Nomad team

---

<div class="post-metadata">

**Author:** ![vikas.saroha](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/vikas.saroha/32/22026_2.png) [@vikas.saroha](https://discuss.hashicorp.com/u/vikas.saroha)\
**Post date:** [May 27, 2022, 1:41pm UTC](https://discuss.hashicorp.com/t/nomad-vault-integration/40077/5 "2022-05-27T13:41:42Z")

</div>

Thanks for replying.

Finally got it working with this template -

```auto
{{ with secret "aws/data/s3/" }}{{ range $k, $v := .Data.data }}
{{ $k }} = {{ $v }}
{{ end }}{{ end }}

```

This is what I tried initially too. The problem I think was an invisible character in the template.

The cli output wasn’t cut short. Here’s the output for `metadata`

```auto
❯ vault kv list aws/metadata/
No value found at aws/metadata/metadata

```

it seems cli adds the metadata.

Thanks for your help.

Cheers.
