-
-
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
Update gomplate
datasources. Add env
and evaluations
sections to Go
template configurations
#599
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
osterman
reviewed
May 9, 2024
osterman
reviewed
May 9, 2024
osterman
reviewed
May 9, 2024
osterman
reviewed
May 9, 2024
osterman
reviewed
May 9, 2024
osterman
reviewed
May 9, 2024
Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
aknysh
changed the title
Update
Update May 9, 2024
gomplate
datasources. Add env
section to Go
template configurationsgomplate
datasources. Add env
and evaluations
sections to Go
template configurations
osterman
approved these changes
May 9, 2024
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
gomplate
datasourcesenv
section toGo
template configurationsevaluations
config toGo
template configurationswhy
Go
templates to access cloud resources fromdatasources
description
Atmos supports configuring the number of evaluations/passes for template processing in
atmos.yaml
CLI config file. It effectively allows you to define template processing pipelines.For example:
templates.settings.evaluations
- number of evaluations/passes to processGo
templates. If not defined,num_steps
is automatically set to1
Template evaluations are useful in the following scenarios:
datasources
Combining templates from different sections in Atmos stack manifests
You can define more than one step/pass of template processing to use and combine the results from each step.
For example:
When executing an Atmos command like
atmos terraform plan vpc -s <stack>
, the above template will be processed in three phases:Evaluation 1
settings.test
is set tovpc
settings.test2
is set to{{ .atmos_component }}
vpc.vars.tags.tag1
is set to{{ .atmos_component }}-{{ .settings.test }}
vpc.vars.tags.tag2
is set to{{<backtick>{{ .atmos_component }}<backtick>}}
Evaluation 2
settings.test
isvpc
settings.test2
is set tovpc
vpc.vars.tags.tag1
is set tovpc-vpc
vpc.vars.tags.tag2
is set to{{ .atmos_component }}
Evaluation 3
settings.test
isvpc
settings.test2
isvpc
vpc.vars.tags.tag1
isvpc-vpc
vpc.vars.tags.tag2
is set tovpc
WARNING:
The above example shows the supported functionality in Atmos templating. You can use it for some use-cases, but it does not mean that you should use it just for the sake of using, since it's not easy to read and understand what data we have after each evaluation step.
The following use-case describes a practical approach to using steps and pipelines in Atmos templates to work
with
datasources
.Using templates in the URLs of
datasources
Let's suppose that your company uses a centralized software catalog to consolidate all tags for tagging all the cloud resources. The tags can include tags per account, per team, per service, billing tags, etc.
NOTE: An example of such a centralized software catalog could be https://backstage.io
Let's also suppose that you have a service to read the tags from the centralized catalog and write them into an S3 bucket in one of your accounts. The bucket serves as a cache to not hit the external system's API with too many requests and not to trigger rate limiting.
And finally, let's say that in the bucket, you have folders per account (
dev
,prod
,staging
). Each folder has a JSON file with all the tags defined for all the cloud resources in the accounts.We can then use the Gomplate S3 datasource to read the JSON file with the tags for each account and assign the tags to all cloud resources.
In
atmos.yaml
, we can figure 2 evaluation steps of template processing:In an Atmos stack manifest, we define the environment variables in the
env
section (AWS profile with permissions to access the S3 bucket), and thes3-tags
Gomplate datasource.In the
terraform.vars.tags
section, we define all the tags that are returned from the call to the S3 datasource.When executing an Atmos command like
atmos terraform apply vpc/1 -s plat-ue2-dev
, the above template will be processed in two steps:Evaluation 1:
datasources.s3-tags.url
is set tos3://mybucket/dev/tags.json
the tags that use the
datasource
templates are set to the following:Evaluation 2:
s3-tags
datasources get executed, the JSON files3://mybucket/dev/tags.json
with the tagsfor the
dev
account is downloaded from the S3 bucket, and the tags are parsed and assigned in theterraform.vars.tags
sectionAfter executing the two evaluation steps, the resulting tags for the Atmos component
vpc/1
in the stackplat-ue2-dev
would look like this:The tags will be added to all the AWS resources provisioned by the
vpc
Terraform component in theplat-ue2-dev
stack.