Component Catalog with Mixins
The Component Catalog with Mixins Design Pattern is a variation of the Component Catalog pattern, with the difference being that we first create parts of a component's configuration related to different environments (e.g. in mixins
folder), then assemble environment-specific manifests from the parts, and then import the environment-specific manifests themselves into the top-level stacks.
It's similar to how Helm and helmfile handle environments.
Use-cases
Use the Component Catalog pattern when:
-
You have many components that are provisioned in multiple stacks (many OUs, accounts, regions) with different configurations for each stack
-
You need to make the component configurations reusable across different environments
-
You want to keep the configurations DRY
Benefits
The Component Catalog with Mixins pattern provides the following benefits:
-
Easy to see where the configuration for each environment is defined
-
Easy to manage different variations of the configurations
-
The defaults for the components are defined in just one place (in the catalog) making the entire configuration DRY
-
The defaults for the components are reusable across many environments by using hierarchical imports
Design Pattern
The Component Catalog with Mixins Design Pattern prescribes the following:
-
For a Terraform component, create a folder with the same name in
stacks/catalog
to make it symmetrical and easy to find. For example, thestacks/catalog/vpc
folder should mirror thecomponents/terraform/vpc
folder. -
In the component's catalog folder, in the
mixins
sub-folder, add manifests with component configurations for specific environments (organizations, tenants, regions, accounts). For example:File Path Description stacks/catalog/vpc/mixins/defaults.yaml
Component manifest with default values stacks/catalog/vpc/mixins/dev.yaml
Component manifest with settings for dev
accountstacks/catalog/vpc/mixins/prod.yaml
Component manifest with settings for prod
accountstacks/catalog/vpc/mixins/staging.yaml
Component manifest with settings for staging
accountstacks/catalog/vpc/mixins/ue2.yaml
Component manifest with settings for us-east-2
regionstacks/catalog/vpc/mixins/uw2.yaml
Component manifest with settings for us-west-2
regionstacks/catalog/vpc/mixins/core.yaml
Component manifest with settings for core
tenantstacks/catalog/vpc/mixins/plat.yaml
Component manifest with settings for plat
tenantstacks/catalog/vpc/mixins/org1.yaml
Component manifest with settings for org1
organizationstacks/catalog/vpc/mixins/org2.yaml
Component manifest with settings for org2
organizationnoteHaving the environment-specific manifests in the component's catalog makes the most sense for multi-Org, multi-OU and/or multi-region architectures, such that there will be multiple dev/staging/prod or region configurations, which get imported into multiple Org/OU top-level stack manifests.
-
In the component's catalog folder, add manifests for specific environments by assembling the corresponding mixins together (using imports). For example:
File Path Description stacks/catalog/vpc/org1-plat-ue2-dev.yaml
Manifest for the org1
organization,plat
tenant,ue2
region,dev
accountstacks/catalog/vpc/org1-plat-ue2-prod.yaml
Manifest for the org1
organization,plat
tenant,ue2
region,prod
accountstacks/catalog/vpc/org1-plat-ue2-staging.yaml
Manifest for the org1
organization,plat
tenant,ue2
region,staging
accountstacks/catalog/vpc/org1-plat-uw2-dev.yaml
Manifest for the org1
organization,plat
tenant,uw2
region,dev
accountstacks/catalog/vpc/org1-plat-uw2-prod.yaml
Manifest for the org1
organization,plat
tenant,uw2
region,prod
accountstacks/catalog/vpc/org1-plat-uw2-staging.yaml
Manifest for the org1
organization,plat
tenant,uw2
region,staging
accountstacks/catalog/vpc/org2-plat-ue2-dev.yaml
Manifest for the org2
organization,plat
tenant,ue2
region,dev
accountstacks/catalog/vpc/org2-plat-ue2-prod.yaml
Manifest for the org2
organization,plat
tenant,ue2
region,prod
accountstacks/catalog/vpc/org2-plat-ue2-staging.yaml
Manifest for the org2
organization,plat
tenant,ue2
region,staging
accountstacks/catalog/vpc/org2-plat-uw2-dev.yaml
Manifest for the org2
organization,plat
tenant,uw2
region,dev
accountstacks/catalog/vpc/org2-plat-uw2-prod.yaml
Manifest for the org2
organization,plat
tenant,uw2
region,prod
accountstacks/catalog/vpc/org2-plat-uw2-staging.yaml
Manifest for the org2
organization,plat
tenant,uw2
region,staging
account -
Import the environment manifests into the top-level stacks. For example:
Action Top-Level Stack Import the stacks/catalog/vpc/org1-plat-ue2-dev.yaml
manifeststacks/orgs/org1/plat/dev/us-east-2.yaml
Import the stacks/catalog/vpc/org1-plat-ue2-prod.yaml
manifeststacks/orgs/org1/plat/prod/us-east-2.yaml
Import the stacks/catalog/vpc/org1-plat-uw2-staging.yaml
manifeststacks/orgs/org1/plat/staging/us-west-2.yaml
Import the stacks/catalog/vpc/org2-plat-ue2-dev.yaml
manifeststacks/orgs/org2/plat/dev/us-east-2.yaml
etc.
Example
The following example shows the Atmos stack and component configurations to provision the vpc
component into
a multi-org, multi-tenant, multi-account, multi-region environment. The component's configuration for each organization, tenant, account and region
are defined as mixins in the component's catalog. The mixins then combined into the environment manifests, and the environment manifests are imported
into the top-level Atmos stacks.
│ # Centralized stacks configuration (stack manifests)
├── stacks
│ └── catalog # component-specific defaults
│ └── vpc
│ ├── mixins
│ │ ├── defaults.yaml
│ │ ├── dev.yaml