-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add stacks.name_template
section to atmos.yaml
. Add Go
templating to Atmos stack manifests
#560
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
mcalhoun
approved these changes
Mar 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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
stacks.name_template
section toatmos.yaml
Go
templating to Atmos stack manifestswhy
Add
stacks.name_template
section toatmos.yaml
-stacks.name_template
section allows greater flexibility in defining the naming convention for the top-level Atmos stacksstacks.name_pattern
configures the name pattern for the top-level Atmos stacks using the context variablesnamespace
,tenant
,environment
andstage
as the tokens. Depending on the structure of your organization, OUs, accounts and regions, setstacks.name_pattern
to the following:name_pattern: {stage}
- if you use just one region and a few accounts (stages) in just one organization and one OU. In this case, the top-level Atmos stacks will use just thestage
(account) in their names, and to provision the Atmos components in the top-level stacks, you will be executing Atmos commands likeatmos terraform apply <component> --stack dev
,atmos terraform apply <component> --stack staging
andatmos terraform apply <component> --stack prod
name_pattern: {environment}-{stage}
- if you have multiple regions and accounts (stages) in just one organization and one OU. In this case, the top-level Atmos stacks will use theenvironment
(region) andstage
(account) in their names, and to provision the Atmos components in the top-level stacks, you will be executing Atmos commands likeatmos terraform apply <component> --stack ue2-dev
,atmos terraform apply <component> --stack uw2-staging
andatmos terraform apply <component> --stack ue1-prod
. Note that thename_pattern
can also be defined as{stage}-{environment}
, in which case the Atmos commands will look likeatmos terraform apply <component> --stack dev-ue2
name_pattern: {tenant}-{environment}-{stage}
- if you have multiple regions, OUs (tenants) and accounts (stages) in just one organization. In this case, the top-level Atmos stacks will use thetenant
,environment
(region) andstage
(account) in their names, and to provision the Atmos components in the top-level stacks, you will be executing Atmos commands likeatmos terraform apply <component> --stack plat-ue2-dev
,atmos terraform apply <component> --stack core-uw2-staging
andatmos terraform apply <component> --stack plat-ue1-prod
, whereplat
andcore
are the OUs/tenants in your organizationname_pattern: {namespace}-{tenant}-{environment}-{stage}
- if you have a multi-org, multi-tenant, multi-account and multi-region architecture. In this case, the top-level Atmos stacks will use thenamespace
,tenant
,environment
(region) andstage
(account) in their names, and to provision the Atmos components in the top-level stacks, you will be executing Atmos commands likeatmos terraform apply <component> --stack org1-plat-ue2-dev
,atmos terraform apply <component> --stack org2-core-uw2-staging
andatmos terraform apply <component> --stack org2-plat-ue1-prod
, whereorg1
andorg2
are the organization names (defined asnamespace
in the corresponding_defaults.yaml
config files for the organizations)stacks.name_template
serves the same purpose asstacks.name_pattern
(defines the naming convention for the top-level Atmos stacks), but provides much more functionality. Instead of using the predefined context variables as tokens, it uses Go templates. Sprig Functions are supported as wellFor the
Go
template tokens, and you can use any Atmos sections (e.g.vars
,providers
,settings
)that the Atmos command
atmos describe component <component> -s <stack>
generates for a component in a stack.name_template: "{{.vars.tenant}}-{{.vars.environment}}-{{.vars.stage}}"
defines the same name pattern for the top-level Atmos stacks asname_pattern: "{tenant}-{environment}-{stage}"
doesSince
stacks.name_template
allows using any variables form thevars
section (and other sections), you can defineyour own naming convention for your organization or for different clouds (AWS, Azure, GCP). For example, in the
corresponding
_defaults.yaml
stack manifests, you can use the following variables:org
instead ofnamespace
division
instead oftenant
region
instead ofenvironment
account
instead ofstage
Then define the following
stacks.name_template
inatmos.yaml
:You will be able to execute all Atmos commands using the newly defined naming convention:
NOTE:
Use either
stacks.name_pattern
orstacks.name_template
to define the naming convention for the top-level Atmos stacks.stacks.name_template
has higher priority. Ifstacks.name_template
is specified,stacks.name_pattern
will be ignored.Add
Go
templating to Atmos stack manifestsAtmos supports Go templates in stack manifests. Sprig Functions are supported as well.
You can use
Go
templates in the following Atmos section to refer to values in the same or other sections:vars
settings
env
metadata
providers
overrides
backend
backend_type
NOTE:
In the template tokens, you can refer to any value in any section that the Atmos command
atmos describe component <component> -s <stack>
generates.For example, let's say we have the following component configuration using
Go
templates:When executing Atmos commands like
atmos describe component
andatmos terraform plan/apply
, Atmos processes all the template tokens in the manifest and generates the final configuration for the component in the stack:While
Go
templates in Atmos stack manifests offer great flexibility for various use-cases, one of the obvious use-casesis to add a standard set of tags to all the resources in the infrastructure.
For example, by adding this configuration to the
stacks/orgs/acme/_defaults.yaml
Org-level stack manifest:the tags will be processed and automatically added to all the resources provisioned in the infrastructure.