Terraform Generation & Deployment
AIVory Architect generates production-ready Terraform code from your visual designs and can deploy infrastructure directly from your IDE.
- Production-ready code generated from visual designs
- Dependency resolution automatically orders resources correctly
- Diff viewer shows changes before overwriting files
- One-click deployment directly from your IDE (Premium)
- State tracking shows deployed status on canvas
Code Generation
Generated Files
When you click Generate Terraform, Architect creates:
| File | Contents |
|---|---|
main.tf |
All resource definitions |
variables.tf |
Input variables for configuration |
outputs.tf |
Output values (IPs, endpoints, etc.) |
providers.tf |
Provider configuration blocks |
terraform.tfvars.example |
Example variable values |
Files are saved to .aivory/terraform/ by default.
Generation Process
Diff Viewer
Before overwriting existing files, Architect shows a diff view:
- Green lines: New additions
- Red lines: Removed content
- Yellow lines: Modified content
Generated Code Example
Visual Design
Generated Terraform
View full generated code example
# providers.tf
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.45"
}
}
}
provider "hcloud" {
token = var.hcloud_token
}
# variables.tf
variable "hcloud_token" {
description = "Hetzner Cloud API token"
type = string
sensitive = true
}
variable "server_type" {
description = "Server type for web server"
type = string
default = "cx21"
}
# main.tf
resource "hcloud_network" "main" {
name = "main-network"
ip_range = "10.0.0.0/8"
}
resource "hcloud_network_subnet" "main" {
network_id = hcloud_network.main.id
type = "cloud"
network_zone = "eu-central"
ip_range = "10.0.1.0/24"
}
resource "hcloud_server" "web" {
name = "web-server"
server_type = var.server_type
image = "ubuntu-22.04"
location = "nbg1"
network {
network_id = hcloud_network.main.id
ip = "10.0.1.2"
}
depends_on = [hcloud_network_subnet.main]
}
resource "hcloud_volume" "data" {
name = "data-volume"
size = 50
location = "nbg1"
}
resource "hcloud_volume_attachment" "data" {
volume_id = hcloud_volume.data.id
server_id = hcloud_server.web.id
automount = true
}
# outputs.tf
output "server_ip" {
description = "Public IP of the web server"
value = hcloud_server.web.ipv4_address
}
output "server_private_ip" {
description = "Private IP of the web server"
value = hcloud_server.web.network[*].ip
}
Deployment (Premium)
Deployment Workflow
terraform applyDeployment Panel
The deployment panel shows:
- Status: Current operation (init/plan/apply)
- Progress: Visual progress indicator
- Logs: Streaming Terraform output
- Resources: List of resources being managed
- Outputs: Values from
outputs.tfafter apply
Cancel Operations
Long-running operations can be cancelled:
- Click Cancel in the deployment panel
- Terraform gracefully stops
- Partial changes may remain - check state
terraform plan after cancellation.
State Management
State File
Terraform tracks deployed resources in terraform.tfstate:
- Architect reads this file to show deployed status
- Never edit the state file manually
- Back up state files before major changes
Deployed Resource Tracking
After deployment, the canvas shows:
Refresh State
Click Refresh to update the canvas from current state:
- Reads
terraform.tfstate - Updates resource status indicators
- Detects any drift from design
Advanced Configuration
Custom Backend
Add backend configuration for remote state:
# backend.tf (create manually)
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "project/terraform.tfstate"
region = "us-east-1"
}
}
Variable Files
Create terraform.tfvars for environment-specific values:
hcloud_token = "your-token-here"
server_type = "cx31"
Or use separate files per environment:
terraform apply -var-file="production.tfvars"
Workspaces
Terraform workspaces let you manage multiple environments:
terraform workspace new staging
terraform workspace select staging
terraform apply
Troubleshooting
Provider not found
terraform init manually or click Initialize in Architect.
Resource already exists
The resource exists but isn’t in state. Either:
- Import it:
terraform import resource_type.name id - Delete it manually and re-apply
Cycle detected
Permission denied
.env or credential vault.
Best Practices
.tf files to git. Don’t commit state or credentials.terraform plan to preview.