Repository navigation
Update Atmos Stack imports. Add imports schema with context. Allow using Go templates in imported configurations - #312
Merged
Conversation
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 30, 2023 20:40 — with
GitHub Actions
Inactive
Member
Author
Hierarchical (nested) imports are supported, contexts for all imports are deep-merged. The rest of the features (if any), we can review later (not in this PR). |
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 30, 2023 20:48 — with
GitHub Actions
Inactive
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 30, 2023 23:15 — with
GitHub Actions
Inactive
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 31, 2023 15:09 — with
GitHub Actions
Inactive
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 31, 2023 15:53 — with
GitHub Actions
Inactive
Andriy Knysh (aknysh)
temporarily deployed
to
preview
January 31, 2023 16:12 — with
GitHub Actions
Inactive
Andriy Knysh (aknysh)
requested a review
from Erik Osterman (Cloud Posse) (osterman)
January 31, 2023 16:14
Max Lobur (max-lobur)
approved these changes
Jan 31, 2023
RB (nitrocode)
approved these changes
Jan 31, 2023
This branch was previously deployed
This file contains hidden or 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
why
and is very useful when creating stacks and components for EKS blue-green deployment
Imports Schema
The
importsection supports the following two formats:a list of paths to the imported files, for example:
a list of objects with the following schema:
where:
path- the path to the imported filecontext- an optional freeform map of context variables that are applied as template variables to the imported file (if the imported file is a Go template)Go Templates in Imported Stacks
Atmos supports all the functionality of the Go templates in imported stack configurations (including functions). Stack configurations can be templatized and then reused with different settings provided via the import
contextsection.For example, we can define the following configuration for EKS Atmos components in the
catalog/terraform/eks_cluster_tmpl.yamltemplate file:NOTE: Since
Goprocesses templates as text files, we can parameterize the Atmos component nameeks-{{ .flavor }}/clusterand any values in any sections (vars,settings,env,backend, etc.), and even theimportsection in the imported file (if the file imports other configurations).Then we can import the template into a top-level stack multiple times providing different context variables to each import:
Now we can execute the following Atmos commands to describe and provision the dynamically generated EKS components into the stack:
All the parameterized variables will get their values from the
context:The dynamically generated Atmos components are visible in
atmos describe affectedcommand as well:{ "component": "eks-blue/cluster", "component_type": "terraform", "stack": "tenant1-uw2-test-1", "affected": "stack.metadata" }, { "component": "eks-green/cluster", "component_type": "terraform", "stack": "tenant1-uw2-test-1", "affected": "stack.metadata" }Hierarchical Imports with Context
Atmos supports hierarchical imports with context.
This will allow you to parameterize the entire chain of stack configurations and dynamically generate components in stacks.
For example, let's create the configuration
stacks/catalog/terraform/eks_cluster_tmpl_hierarchical.yamlwith the following content:Then we can import the template into a top-level stack multiple times providing different context variables to each import and to the imports for the entire inheritance chain (which
catalog/terraform/eks_cluster_tmpl_hierarchicalimports itself):In the case of hierarchical imports, Atmos performs the following steps:
Processes all the imports in the
importsection in the current configuration in the order they are specified providing thecontextto all imported filesFor each imported file, Atmos deep-merges the parent
contextwith the current context. Note that the currentcontext(in the current file) takes precedence over the parentcontextand will override items with the same keys. Atmos does this hierarchically for all imports in all files, effectively processing a graph of imports and deep-merging the contexts on all levelsFor example, in the
stacks/orgs/cp/tenant1/test1/us-west-1.yamlconfiguration above, we first importthe
catalog/terraform/eks_cluster_tmpl_hierarchicaland provide it with thecontextwhich includes the context variables for the EKS component itself, as well as the context variables for all the hierarchical imports. Then, when processing thestacks/catalog/terraform/eks_cluster_tmpl_hierarchicalconfiguration, Atmos deep-merges the parentcontext(fromstacks/orgs/cp/tenant1/test1/us-west-1.yaml) with the currentcontextand processes theGotemplates.We are now able to dynamically generate the components
eks-blue/clusterandeks-green/clusterin the stacktenant1-uw1-test1and can execute the following Atmos commands to provision the components into the stack:All the parameterized variables get their values from the all the hierarchical
contextsettings:related