Has the `tpl` function (`tmpl.Inline`) from gompla...
# atmos
w
Has the
tpl
function (
tmpl.Inline
) from gomplate been disabled in Atmos? We have tried using both but it complains that the function does not exist so we had to resort to this abomination that renders a template to be rendered on the second pass:
Copy code
{{- print `{{ toJson (data.YAML ` "`" }}
#build a template to render on the second pass
{{- print "`" `) }}` }}
The fact that
data.YAML
works proves that we have gomplate enabled, as well as sprig's
toJson
.
a
if you have
Copy code
sprig:
      # Enable Sprig functions in `Go` templates in Atmos stack manifests
      enabled: true
    # https://docs.gomplate.ca
    # https://docs.gomplate.ca/functions
    gomplate:
      # Enable Gomplate functions and data sources in `Go` templates in Atmos stack manifests
      enabled: true
in
atmos.yaml
, then all gomplate and Sprig functions are enabled - Atmos does not disable anything from the libs. But it might be not supported by the Go gomplate lib that Atmos uses
the docs shows that the func exists https://docs.gomplate.ca/functions/tmpl/
we did not test that particular function, can you show your template so we could test it
⏳ 1
w
this is the simplest proof of concept
Copy code
vars:
  test: |-
    {{ tpl "test" $ }}
    {{ tmpl.Inline "test" $ }}
if you put that anywhere in your stack it will error with
Copy code
template: templates-all-atmos-sections:1689: function "tpl" not defined
for the first line and
Copy code
template: templates-all-atmos-sections:1689: function "tmpl" not defined
for the second line
r
also trying to use
template
won't work either, atmos includes the section more than once so the golang template sees it being defined more than once
ala
{{define "T1"}}hello, world!{{end}}{{ tmpl.Exec "T1" | strings.ToUpper }}
compounded in all of this, the error messages are horrid for debugging, because this could be a single line in any file of the repo for atmos
this 1
same for if you disable sprig but are using something like
dig
which doesn't have an overlapping function in gomplate
the only line number mentioned is the line number of the deep merged YAML document, which turns the entire experience into a binary search. So it'd be nice if the line itself and a few lines around were shown as well, because then I have a basic chance of finding the broken line
also we do need the template to be delayed by one render pass, otherwise the inside values don't get created properly
For context, I wrote said abomination to get the desired output
regarding "the only line number mentioned is the line number of the deep merged YAML document, which turns the entire experience into a binary search" valid point, and we need to improve it. This is how it works now: • Atmos processes all YAML files, deep-merges all sections, and finds the final values for the component in the stack - then processes the templates • Template processing is the last step b/c templates need context, and the context is the values of the component in the stack itself • At this point, the information about the physical files is "lost" (but we might be able to improve the parser to keep the information about the files), Atmos just has the data structure representing the final values after all the imports, inheritance and deep-merging • To be able to detect "invalid" templates and know what files they are in, some other mechanisms to validate it need to be used
this can't be done in one way for all possible cases b/c of this: • Templates like
{{define "T1"}}hello, world!{{end}}{{ tmpl.Exec "T1" | strings.ToUpper }}
don't need any context, they can be evaluated by just reading the YAML stack config file where the template is defined. But this is usually not the case since almost all templates need context (unless we read from external sources like files or ENV variables) • Templates like
{{ .vars.vpc_id }}
or
{{ .settings.context.stage }}
requite context, which in this case is the final values of all Atmos sections after Atmos finds the component in the stack - these templates are used all the time in stack config
the first type can be validated (e.g. if the template function exists or not) and evaluated even when reading the file where the template is the second type can be validated and evaluated only as the last step in the pipeline when Atmos has the final values for the component in the stack
we can prob improve the
atmos validate stacks
command (https://atmos.tools/cli/commands/validate/stacks) to do template validation, and detect the first type of templates and any issues related to them (e.g. a template function does not exist) and show the exact file name/path
r
"the first type can be validated" That is false, atmos makes the template defined more than once, causing an error inside the template engine