Mixins
Mixins are reusable configuration fragments that encapsulate settings you want to apply consistently. Instead of repeating the same values across multiple stacks, define them once in a mixin and import where needed.
Use-cases
Use Mixins when:
-
You repeat the same configuration across multiple stacks
-
You want region-specific defaults (availability zones, region name)
-
You want stage-specific defaults (instance sizes, feature flags)
-
Different teams should share consistent settings
Two Places for Mixins
Mixins can live in two locations depending on their scope:
| Location | Scope | Examples |
|---|---|---|
stacks/mixins/ | Global settings that apply across many components | Region defaults, stage defaults, tenant defaults |
stacks/catalog/<component>/mixins/ | Component-specific feature flags and versions | vpc/mixins/multi-az, eks/mixins/1.27 |
Common Global Mixin Types
| Mixin Type | Contains | Example |
|---|---|---|
| Region | Region name, AZs, environment abbreviation | mixins/region/us-east-2.yaml |
| Stage | Stage name, stage-specific defaults | mixins/stage/prod.yaml |
| Tenant | Team/OU name, team-specific settings | mixins/tenant/platform.yaml |
Example: Region Mixins
Region mixins encapsulate everything that's consistent for a region:
stacks/mixins/region/us-east-2.yaml
stacks/mixins/region/us-west-2.yaml
Now stacks import the region mixin instead of repeating these values:
stacks/deploy/us-east-2/dev.yaml
Example: Stage Mixins
Stage mixins define defaults for each environment:
stacks/mixins/stage/dev.yaml
stacks/mixins/stage/prod.yaml
Example: Catalog Mixins (Feature Flags)
Mixins inside a component's catalog folder enable optional features:
stacks/catalog/vpc/mixins/multi-az.yaml
stacks/catalog/vpc/mixins/nat-gateway.yaml
Stack files pick the features they need:
stacks/deploy/prod.yaml
Example: Catalog Mixins (Versions)
Version mixins are perfect for components like EKS where different clusters may run different versions:
stacks/catalog/eks/mixins/1.27.yaml
stacks/catalog/eks/mixins/1.28.yaml
Upgrade clusters independently by changing which version mixin they import:
stacks/deploy/prod/us-east-2.yaml
stacks/deploy/prod/us-west-2.yaml
Import Order Matters
Later imports override earlier ones. Order from general to specific:
import:
- catalog/vpc/defaults # 1. Component defaults (most general)
- catalog/vpc/mixins/multi-az # 2. Feature flags
- mixins/region/us-east-2 # 3. Region settings
- mixins/stage/prod # 4. Stage settings (most specific)
Directory Structure
stacks/
├── catalog/ # Component defaults
│ ├── vpc/
│ │ ├── defaults.yaml
│ │ └── mixins/ # Component-specific mixins
│ │ ├── multi-az.yaml
│ │ └── nat-gateway.yaml
│ └── eks/
│ ├── defaults.yaml
│ └── mixins/ # Version mixins
│ ├── 1.27.yaml
│ └── 1.28.yaml
├── mixins/ # Global mixins
│ ├── region/
│ │ ├── us-east-2.yaml
│ │ └── us-west-2.yaml
│ └── stage/
│ ├── dev.yaml
│ ├── staging.yaml
│ └── prod.yaml
└── deploy/ # Top-level stacks
└── us-east-2/
├── dev.yaml
└── prod.yaml
Before and After
Without mixins (repetitive):
vars:
region: us-east-2
environment: ue2
stage: dev
components:
terraform:
vpc:
vars:
availability_zones: [us-east-2a, us-east-2b, us-east-2c]
nat_gateway_enabled: false
vars:
region: us-east-2
environment: ue2
stage: prod
components:
terraform:
vpc:
vars:
availability_zones: [us-east-2a, us-east-2b, us-east-2c]
map_public_ip_on_launch: false
With mixins (DRY):
import:
- mixins/region/us-east-2
- mixins/stage/dev
- catalog/vpc/defaults
import:
- mixins/region/us-east-2
- mixins/stage/prod
- catalog/vpc/defaults
Related Patterns
- Multi-Region Configuration - Uses region mixins
- Organizational Hierarchy - Uses tenant mixins
- Component Catalog - Component defaults (different from mixins)