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
  1. Validate: Check the stack file for syntax errors, invalid resource kinds, missing required fields, and broken references.
  2. Plan: Compare the desired state (stack file) with the actual state (live resources). Generate a list of create, update, and delete actions.
  3. 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

KindDescription
InstanceCompute instances
DatabaseManaged databases
VPCVirtual Private Clouds
SubnetNetwork subnets
SecurityGroupFirewall rules
LoadBalancerHTTP/TCP load balancers
DNSZoneDNS zones
DNSRecordDNS records
BucketObject storage buckets
K3sClusterKubernetes clusters
RedisClusterRedis clusters
MessageQueueRabbitMQ/NATS queues
FunctionServerless functions