# IaC Projects

Source: https://docs.ops0.com/docs/iac/projects

Create and manage Infrastructure as Code projects for Terraform, OpenTofu, Oxid, or CloudFormation. Pulumi support is upcoming.

## Creating a Project

### Navigate to IaC
Click **IaC** in the sidebar to view your projects.

### Click New Project
Select the **+ New Project** button.

### Configure
Enter project name, select IaC type (Terraform, etc.), and add a description.

### Create and Edit
Click **Create** to launch the editor and start building.

## Supported IaC Types

- **Terraform**: HashiCorp's infrastructure provisioning tool. Most widely used.

- **OpenTofu**: Open-source Terraform fork. Drop-in compatible.

- **Oxid**: Rust-based IaC engine.

- **CloudFormation**: AWS-native infrastructure templates with change sets, multi-region deployments, and StackSet support.

- **Pulumi (Upcoming)**: Infrastructure in TypeScript, Python, Go, or C#.

## Filtering Projects

The projects list has three filters:

| Filter | Options |
|--------|---------|
| **Deployment Status** | All / Deployed / Never Deployed |
| **Cloud Provider** | All / AWS / GCP / Azure / Oracle |
| **IaC Type** | All / Terraform / OpenTofu / Oxid / CloudFormation / Pulumi |

Use these together to quickly find, for example, all Terraform projects on AWS that have never been deployed.

---

## Project Card

Each project card displays:

| Field | Description |
|-------|-------------|
| **Title** | Project name |
| **Type** | Terraform, OpenTofu, Oxid, CloudFormation, or Pulumi (Upcoming) |
| **Last Updated** | Relative timestamp (hover for exact date/time) |
| **Files** | Number of files in the project |
| **Est. Cost** | Monthly cost estimate with ↑ or ↓ delta vs previous deployment |
| **Policies** | Attached compliance policies with severity badges |
| **Recommendations** | AI-generated improvement suggestions (count badge; click to expand) |

---

## Project Actions

| Action | Description |
|--------|-------------|
| **Open** | Open in the editor |
| **Edit** | Update name/description |
| **Duplicate** | Create a copy (same files, no state, no deployment history) |
| **Replicate** | Clone to a different cloud provider, region, or account via the Replication Wizard |
| **Resource Graph** | View Terraform resource dependency graph (requires a completed deployment) |
| **Variable Graph** | View cross-project variable dependency graph |
| **Migrate IaC Type** | Switch between Terraform ↔ OpenTofu, or migrate from CloudFormation to Terraform/OpenTofu |
| **Enable/Edit/Disable Oxid** | Configure a PostgreSQL backend for Oxid projects |
| **View Recommendations** | See AI-generated recommendations for this project |
| **View Incidents** | Jump to incidents linked to this project |
| **Delete** | Permanently remove the project |

### Migrate IaC Type

The **Migrate** action converts a project between engines:

| Conversion | What happens |
|-----------|-------------|
| **Terraform → OpenTofu** | Updates the executor to `tofu`; code remains unchanged (fully compatible) |
| **OpenTofu → Terraform** | Updates the executor to `terraform` |
| **CloudFormation → Terraform** | AI converts the CloudFormation template to equivalent HCL resources — a progress modal streams the conversion |
| **CloudFormation → OpenTofu** | Same as above using OpenTofu syntax |

## Policy Badges

| Color | Severity | Effect |
|-------|----------|--------|
| Red | Error | Blocks deployment |
| Yellow | Warning | Shows warning, allows deploy |
| Blue | Info | Informational only |

---

## Example: Creating a VPC Project

Here's a complete example of creating a production VPC.

### Create Project
- **Name:** `production-vpc`
- **Type:** Terraform
- **Description:** "Production VPC with public/private subnets"

### Ask AI to Write Code
In the chat panel, type:

```
Create a VPC in us-east-1 with:
- CIDR 10.0.0.0/16
- 2 public subnets in different AZs
- 2 private subnets in different AZs
- Internet gateway and NAT gateway
- Proper route tables
```

### Produced Code

**main.tf**
```hcl
resource "aws_vpc" "main" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name        = "production-vpc"
    Environment = "production"
  }
}

resource "aws_subnet" "public_1" {
  vpc_id                  = aws_vpc.main.id
  cidr_block              = "10.0.1.0/24"
  availability_zone       = "us-east-1a"
  map_public_ip_on_launch = true

  tags = { Name = "public-subnet-1" }
}

resource "aws_subnet" "private_1" {
  vpc_id            = aws_vpc.main.id
  cidr_block        = "10.0.10.0/24"
  availability_zone = "us-east-1a"

  tags = { Name = "private-subnet-1" }
}

resource "aws_internet_gateway" "main" {
  vpc_id = aws_vpc.main.id
  tags   = { Name = "production-igw" }
}

resource "aws_nat_gateway" "main" {
  allocation_id = aws_eip.nat.id
  subnet_id     = aws_subnet.public_1.id
  tags          = { Name = "production-nat" }
}
```

**outputs.tf**
```hcl
output "vpc_id" {
  description = "ID of the VPC"
  value       = aws_vpc.main.id
}

output "public_subnet_ids" {
  description = "IDs of public subnets"
  value       = [aws_subnet.public_1.id, aws_subnet.public_2.id]
}

output "private_subnet_ids" {
  description = "IDs of private subnets"
  value       = [aws_subnet.private_1.id, aws_subnet.private_2.id]
}
```

### Deploy
- Click **Validate** → Check syntax
- Click **GitHub** → Push to repository
- Click **Deploy** → Review plan → **Apply**

---

## Project Structure

```
├── main.tf          # Primary resources
├── variables.tf     # Input variables
├── outputs.tf       # Output values
├── providers.tf     # Provider configuration
└── terraform.tfvars # Variable values (gitignored)
```

**Tips**

  - Use descriptive names like "prod-eks-cluster" or "staging-database"
  - Organize files by purpose: networking.tf, compute.tf, database.tf
  - Add descriptions to help teammates understand the project
