-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Atmos Go
template functions. Add atmos.Component
function to read values from other Atmos components including outputs (remote state)
#628
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
what
Go
template functionsatmos.Component
template function to read values from other Atmos components including outputs (remote state)atmos.Component
functionwhy
Atmos now supports custom
Go
template functions similar to Sprig and GomplateIn
Go
templates in Atmos stack manifests, you can use the following functions and datasources:text/template
functionsdescription
The
atmos.Component
template function allows you to read any Atmos section or any attribute from a section for an Atmos component in a stack, and use it inGo
templates in Atmos component configurations.Usage
{{ (atmos.Component "<component>" "<stack>").<section>.<attribute> }}
Arguments
component
- Atmos component namestack
- Atmos stack namesection
- Atmos section name. Any section returned by the CLI commandatmos describe component
can be used. A specialoutputs
section is also supported to get the outputs (remote state) of Terraform/OpenTofu components.NOTE: Using the
outputs
section in theatmos.Component
command is an alternative way to read the outputs (remote state) of a component in a stack directly in Atmos stack manifests instead of using theremote-state
module and configuring Terraform/OpenTofu components to use theremote-state
module as described in Component Remote Stateattribute
- attribute name (field) from thesection
.attribute
is optional, you can use thesection
itself if it's a simple type (e.g.string
). Any number of attributes can be chained using the dot (.
) notation. For example, if the first two attributes are maps, you can chain them and get a field from the last map:{{ (atmos.Component "<component>" "<stack>").<section>.<attribute1>.<attribute2>.<field1> }}
Specifying Atmos
stack
stack
is the second argument of theatmos.Component
function, and it can be specified in a few different ways:Hardcoded stack name. Use it if you want to get an output from a component from a different (well-known and static) stack. For example, you have a
tgw
component in a stackplat-ue2-dev
that requires thevpc_id
output from thevpc
component from the stackplat-ue2-prod
:Use the
.stack
(or.atmos_stack
) template identifier to specify the same stack as the current component (for which theatmos.Component
function is executed):For example, you have a
tgw
component that requires thevpc_id
output from thevpc
component in the same stack:Use the
printf
template function to construct stack names using static strings and dynamic identifiers:For example, you have a
tgw
component deployed in the stackplat-ue2-dev
. Thetgw
component requires thevpc_id
output from thevpc
component from the same environment (ue2
) and same stage (dev
), but from a different tenantnet
(instead ofplat
):NOTE: By using the
printf "%s-%s-%s"
function, you are constructing stack names using the stack context variables/identifiers. For more information on Atmos stack names and how to define them, refer tostacks.name_pattern
andstacks.name_template
sections inatmos.yaml
CLI config fileExamples
The following configurations show different ways of using the
atmos.Component
template function to read values from different Atmos sections directly in Atmos stack manifests, including the outputs of other (already provisioned) components.