Connecting Components
Components rarely work in isolation. Your application needs the VPC ID. Your database needs the subnet IDs. Your load balancer needs security group references. Atmos makes it easy to connect components and share data between them.
The key is remote state---components store their outputs in a backend (like S3), and other components read those outputs when needed.
Why Components Need to Connect
Imagine building a typical web application infrastructure:
- VPC creates the network (
vpc_id) - Subnets need the
vpc_idto create subnets - EKS cluster needs subnet IDs to launch in the right network
- Application needs the EKS cluster endpoint to deploy
Each component depends on outputs from previous components. This is called a loosely coupled architecture---components are independent but can reference each other's outputs.
Your First Component Connection
Let's connect a VPC component to an EKS cluster component using !terraform.state.
Step 1: VPC component outputs its ID
components/terraform/vpc/outputs.tf
Step 2: EKS component reads VPC outputs in the stack configuration
stacks/dev.yaml
The !terraform.state function reads outputs directly from the Terraform state backend. It's fast, simple, and the recommended way to connect components.
How It Works
When you deploy a component with atmos terraform apply, Terraform:
- Runs your configuration (plan → apply)
- Stores outputs in the state file
- Saves state to the backend (S3, GCS, Azure, etc.)
Later, when another component needs those outputs:
!terraform.statequeries the backend directly- Reads the state file
- Extracts the outputs
- Makes them available in your stack configuration
Connecting Across Stacks
Components can read outputs from other stacks, not just the current stack:
stacks/prod.yaml
This enables patterns like:
- Shared services account with centralized databases
- Hub-and-spoke networks with VPC peering
- Cross-environment references (staging uses prod DNS zone)
Common Connection Patterns
1. Network Dependencies
VPC → Subnets → EKS → App
2. Shared Services
Prod App reads Shared RDS
3. Cross-Region References
App in us-west-2 reads Route53 from us-east-1
Avoiding Circular Dependencies
Be careful not to create circular references:
# BAD - Circular dependency
components:
terraform:
component-a:
vars:
value_from_b: !terraform.state component-b some_value
component-b:
vars:
value_from_a: !terraform.state component-a other_value
This creates a deadlock---neither component can deploy until the other exists.
Solution: Break the cycle by using explicit values or adding an intermediate component:
# GOOD - No circular dependency
components:
terraform:
shared-config:
vars:
shared_value: "initial-value"
component-a:
vars:
value_from_shared: !terraform.state shared-config value
component-b:
vars:
value_from_shared: !terraform.state shared-config value
Deployment Order
When components depend on each other, deploy them in dependency order:
# 1. Deploy VPC first
atmos terraform apply vpc -s dev
# 2. Deploy subnets (needs VPC)
atmos terraform apply subnets -s dev
# 3. Deploy EKS (needs subnets)
atmos terraform apply eks -s dev
# 4. Deploy app (needs EKS)
atmos terraform apply app -s dev
Atmos doesn't automatically determine order---you control deployment sequence.
Use workflows to automate multi-component deployments in the correct order.
Key Takeaways
- Components share data via remote state - Outputs stored in backend
- Use
!terraform.state- The fastest, recommended way to read outputs - Read across stacks - Specify the stack name as the second parameter
- Avoid circular dependencies - Deploy in correct order
- Loosely coupled architecture - Components independent but connected
Learn More About Sharing State
Explore all the ways to share data between components, including alternative methods. Sharing State Guide
What's Next
You've learned the fundamentals of Atmos! Now you can:
- Explore Next Steps - Advanced topics and resources
- Read the Stack Reference - Deep dive into advanced stack features
- Learn about Workflows - Automate multi-component deployments
- Explore Template Functions - Advanced YAML and Go template functions