Component Library
Components are the building blocks of your infrastructure. They are opinionated, reusable units of infrastructure-as-code that solve specific problemsβTerraform root modules, Helmfiles, or Packer templates.
What are Components?β
In Atmos, a component consists of two parts:
- Implementation β The infrastructure code itself (a Terraform root module, Helmfile, or Packer template)
- Configuration β The settings that customize how the component is deployed in each environment
This separation of concerns is fundamental to Atmos. You write the implementation once, then configure it differently for each environment through stacks.
Component Configurationβ
Components are configured in the components section of stack files. Here's what component configuration looks like:
stacks/deploy/prod/us-east-1.yaml
Each component configuration includes:
| Section | Purpose |
|---|---|
metadata | Component location, inheritance, and Atmos behavior |
vars | Input variables passed to the component |
settings | Atmos and integration settings (not passed to the component) |
Component Instancesβ
A component instance is a specific deployment of a component in a stack. The same component implementation can have many instances across your infrastructure:
# Same "vpc" component, different instances
components:
terraform:
# Instance: "vpc" in prod/us-east-1
vpc:
vars:
cidr_block: "10.0.0.0/16"
# Instance: "vpc-secondary" in prod/us-east-1 (using same component)
vpc-secondary:
metadata:
component: vpc # Same implementation
vars:
cidr_block: "10.1.0.0/16"
Each instance:
- Has its own Terraform state (or Helmfile release, Packer build)
- Can have different variable values
- Is independently deployable
Implementation vs Configurationβ
| Aspect | Implementation | Configuration |
|---|---|---|
| Location | components/terraform/vpc/ | stacks/prod/us-east-1.yaml |
| Contains | Terraform code, resources, modules | Variables, settings, metadata |
| Changes | When infrastructure logic changes | When environment needs differ |
| Reuse | Single implementation | Many configurations |
This separation allows you to:
- Write a component once and deploy it across many environments
- Customize behavior through configuration, not code duplication
- Maintain consistency while supporting environment-specific requirements
- Update all instances by changing the implementation
Component Typesβ
Atmos natively supports three component types:
| Type | Implementation | Description |
|---|---|---|
| Terraform/OpenTofu | Terraform root modules | Provision cloud infrastructure |
| Helmfile | Helmfile configurations | Deploy Helm charts to Kubernetes |
| Packer | Packer templates | Build machine images |
Each type has its own configuration schema, but they share common patterns for metadata and settings.
Directory Structureβ
Components are stored in your project's components/ directory:
components/
βββ terraform/ # Terraform root modules
β βββ vpc/
β βββ eks/
β β βββ cluster/
β βββ rds/
βββ helmfile/ # Helmfile configurations
β βββ nginx-ingress/
β βββ cert-manager/
βββ packer/ # Packer templates
βββ ubuntu-base/
Get a head start by utilizing Cloud Posse's free Terraform components for AWS, available on GitHub.
Use-casesβ
- Developer Productivity Create a component library of vetted terraform root modules that should be used by teams anytime they need to spin up infrastructure for VPCs, clusters, and databases.
- Compliance and Governance: Establish a component library to enforce infrastructure standards, security policies, and compliance requirements. By using pre-approved modules, organizations can maintain control over their infrastructure's configuration, reducing the risk of non-compliance.
- Rapid Prototyping and Scalability: Utilize a component library to quickly prototype and scale applications. Pre-built modules for common infrastructure patterns allow teams to focus on application development rather than infrastructure setup, accelerating time-to-market and ensuring scalability from the outset.
Organizing Componentsβ
There's no "one way" to organize your componentsβit's configurable based on your needs. Here's a simple example organizing by toolchain:
βββ components/
βββ helmfile/
β βββ example-app/
β βββ helmfile.yaml
βββ terraform/
βββ vpc/
βββ main.tf
βββ outputs.tf
βββ variables.tf
For detailed guidance on folder structure including multi-cloud layouts, version management strategies, and enterprise patterns, see Project Layout.
Terraform Conventionsβ
For terraform, we recommend placing the terraform "root" modules in the components/terraform folder. If the root modules depend on other child modules that are not hosted by a registry, we recommend placing them in a subfolder called modules/.
Make your Terraform components small, so they are easily reusable, but not so small that they only do to provide a single resource, which results in large, complicated configurations. A good rule of thumb is they should do one thing well. For example, provision a VPC along with all the subnets, NAT gateways, Internet gateways, NACLs, etc.
Use multiple component to break infrastructure apart into smaller pieces based on how their lifecycles are connected. For example, a single component seldom provides a VPC and a Kubernetes cluster. That's because we should be able to destroy the Kubernetes cluster without destroying the VPC and all the other resources provisioned inside of the VPC (e.g. databases). The VPC, Kubernetes cluster and Databases all have different lifecycles. Similarly, we should be able to deploy a database and destroy it without also destroying all associated backups. Therefore the backups of a database should be a separate component from the database itself.
Describing Componentsβ
When working with complex configurations that use imports and inheritance, it can be challenging to understand the final deep-merged configuration for a component. Use the atmos describe component command to view the fully resolved configuration:
atmos describe component vpc -s ue2-prod
This is especially helpful when:
- Debugging configuration issues
- Understanding inherited values
- Developing validation policies
- Verifying the final configuration before deployment
For more powerful filtering options, consider describing stacks instead.
Next Stepsβ
- Terraform Components β Terraform root modules
- Helmfile Components β Helmfile configurations
- Packer Components β Packer templates