Infrastructure as Code
Declarative infrastructure management with JSON stacks, plan/apply workflow, and dependency resolution.
Infrastructure as Code
Overview
The AgentMetal IaC engine provides declarative resource management through JSON stack files. Define your desired infrastructure state, and the engine handles creation, updates, and deletion of resources to match your specification.
Key Features
- Declarative: Define what you want, not how to build it
- Plan before apply: Preview all changes before execution
- Dependency resolution: Automatic topological sorting ensures correct ordering
- Validation: Schema and cross-reference validation before any changes
- Idempotent: Applying the same stack twice produces no changes
Workflow
The standard IaC workflow consists of three stages:
validate → plan → apply
- Validate: Check the stack file for syntax errors, invalid resource kinds, missing required fields, and broken references.
- Plan: Compare the desired state (stack file) with the actual state (live resources). Generate a list of create, update, and delete actions.
- Apply: Execute the planned actions in dependency order. Resources are created in topological order and deleted in reverse order.
Additionally, destroy removes all resources defined in a stack.
Quick Start
# Write your stack file
cat > stack.json << EOF
{
"name": "my-app",
"description": "Web application infrastructure",
"resources": [
{
"apiVersion": "v1",
"kind": "VPC",
"metadata": {"name": "app-vpc"},
"spec": {"cidr": "10.0.0.0/16"}
},
{
"apiVersion": "v1",
"kind": "Instance",
"metadata": {"name": "web-01"},
"spec": {"type": "cx31", "image": "ubuntu-22.04"},
"dependsOn": ["app-vpc"]
}
]
}
EOF
Validate
agentmetal iac validate stack.json
Plan
agentmetal iac plan stack.json
Apply
agentmetal iac apply stack.json
Tear down
agentmetal iac destroy stack.json
Supported Resource Kinds
| Kind | Description |
|---|---|
| Instance | Compute instances |
| Database | Managed databases |
| VPC | Virtual Private Clouds |
| Subnet | Network subnets |
| SecurityGroup | Firewall rules |
| LoadBalancer | HTTP/TCP load balancers |
| DNSZone | DNS zones |
| DNSRecord | DNS records |
| Bucket | Object storage buckets |
| K3sCluster | Kubernetes clusters |
| RedisCluster | Redis clusters |
| MessageQueue | RabbitMQ/NATS queues |
| Function | Serverless functions |