hashicorp / nomad-pack

Mozilla Public License 2.0
398 stars 52 forks source link

Syntax for fileContents #572

Open SirHamburger opened 2 months ago

SirHamburger commented 2 months ago

I try to add files via the fileContents.

My current template is the following:

    template {
      destination = "config/[[var "RETAILER_ID" .]].[[var "SYSTEM_ID" .]]/[[$settings.FILTER_CONFIG_FILE]]"
      data        = <<EOT
        [[ fileContents "../config-files/[[var "RETAILER_ID" .]].[[var "SYSTEM_ID" .]]/[[$settings.FILTER_CONFIG_FILE]]" ]]
        EOT
    }

And I get the following error: Error: template: <file>:25: bad character U+0022 '"'

How can I add variables to the data block (with the new Syntax)?

SirHamburger commented 2 months ago

I have found a hacky solution:

    template {
      destination = "config/[[var "RETAILER_ID" .]].[[var "SYSTEM_ID" .]]/[[$settings.FILTER_CONFIG_FILE]]"
      data        = <<EOT
[[$A:="../config-files/"]]
[[$B:=(var "RETAILER_ID" .)]]
[[$C:="."]]        
[[$D:=(var "SYSTEM_ID" .)]]
[[$E:="/"]]   
[[$F:=($settings.FILTER_CONFIG_FILE)]]
[[$concat:=(print $A $B $C $D $E $F) ]]
[[$concat  | fileContents]]
        EOT
    }

If anyone has a not so hacky solution, it is still appreciated.