Can I combine yaml functions? I have some challeng...
# atmos
p
Can I combine yaml functions? I have some challenges passing JSON via !terraform.state, it gets turned into object, and I just want it as string.
p
The issue is that
!terraform.state
returns a parsed YAML value, so objects come back as objects, not strings. To force it to a string you need to combine it with a template function and `toJson`:
Copy code
my_var: !template '{{ toJson (terraform.state "component" "stack" ".outputs.my_output") }}'
YAML functions and template functions operate at different layers. YAML functions parse into structured data, template functions work on raw text before parsing. When you need the JSON string rather than the object, template + toJson is the way to go.
e
Yes, so understand the use-case; but they are actually very different.
TL;DR: templating works by treating YAML as text, not YAML
"YAML Functions" (YAML explicit tags) are a feature of YAML; not templtaing.
The reality is templating is not ideal for many reasons, chiefly performance and stability. When templating is used, the fact that it's YAML is secondary, and we can't efficiently determine when to render values. We have to render everything.
Also like @Paulo Gomes says, functons return objects (not messing with YAML formatting constraints)
We have a workaround, but it's unfortunately not proved reliable. And it may or may not work for you.
First, we support `locals`; these are idea, but many people report problems with it. Your mileage may vary. We plan to invest more into them, but no ETA.
Then, in the upcoming release
1.221.0
we are introducing
{{ atmos.Resolve ... }
which can resolve any section of atmos stack config that uses a YAML function.
e.g.
Copy code
settings:
  context:
    something: !somefunction
vars:
  foo: {{ atmos.Resolve .settings.context.something }}
The key thing to note, since
!anything
must appear first after the key as a value, you cannot retreat
!anything
as an interpolated value.
p
Thanks for the detail, @Erik Osterman (Cloud Posse). Good to know
atmos.Resolve
is coming, that's a cleaner solution than reaching for templating. Will keep an eye on 1.221.0
e
1.221.0
was released 😃 (
1.221.1
even!)
🙌 1