Skip to content

List specific value from datasource depending on env var #1634

Answered by hairyhenderson
v-v18 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @viet-ng95! I've converted this to a discussion since this is a usage question and not a bug report.

What you need here is the index function, and its usage for accessing maps (such as was provided by your datasource) is documented here.

What might work is something like:

{{ $config := datasource "config" -}}
{{ $region := index $config .Env.ENVIRONMENT -}}
{{ $region.value }}

Or, if you want to be less verbose and do it on a single line:

{{ (index (ds "config") .Env.ENVIRONMENT).value }}

Hope that helps!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@v-v18
Comment options

Answer selected by v-v18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1632 on February 16, 2023 16:15.