Hi all, I have a question on datasources/templates...
# atmos
l
Hi all, I have a question on datasources/templates I have this datasource defined:
settings:
templates:
settings:
gomplate:
datasources:
env:
url: "stacks/data/{{ .vars.environment }}.yaml"
And I use it as described in the documentation: `ami: '{{
{{ (index (datasource "env").ami .vars.aws_region) }}
}}'` It works great if
aws_region
contains directly a
string
value but is not working if it reference another variable, for example
aws_region: {{ .vars.region }}
I have templates evaluation set to 3 and as far as I understood, in the first evaluation
aws_region
should be resolved to the actual value of
region
and
ami
to
'{{ (index (datasource "env").ami .vars.aws_region) }}'
so in the second evaluation it should be evaluated correctly with the value originally contained into
region
. Am I assuming something wrong? Is there any way to make it works if I'm doing something wrong? Thanks in advance
e
Can we take a step back and first understand what you want to accomplish before we evaluate the proposed solution?
Generally, we try to avoid reliance on complex template expressions, if we can avoid it.
l
Thanks for the answer. What I would like to achieve is to have a dynamic aws_region variable that changes value depending on the content of another variable. For example something like:
aws_region:
'{{ if and .vars.disaster_recovery.enabled }}
{{- .vars.disaster_recovery.target_region -}}
{{ else }}
{{- .vars.disaster_recovery.original_region -}}
{{ end }}'
This works if I use aws_region with !terraform.state but not with datasources.