> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrating from Terraform

> Convert Terraform HCL files to ubx .iac files using ubx convert.

## Quick Migration

```bash theme={null}
ubx convert --from terraform ./terraform/
ubx convert --from terraform main.tf
ubx convert --from terraform ./tf/ --out ./iac/
```

Generates `.iac` files, a `ubx.yaml` scaffold, and `MIGRATION_NOTES.md` for anything needing manual review.

## Conversion Mapping

| Terraform                              | ubx                                    |
| -------------------------------------- | -------------------------------------- |
| `resource "aws_s3_bucket" "assets" {}` | `unit "aws_s3_bucket_v2" "assets" {}`  |
| `variable "region" {}`                 | `input "region" {}`                    |
| `output "endpoint" {}`                 | `output "endpoint" {}`                 |
| `locals { name = "x" }`                | `local "name" { value = "x" }`         |
| `module "vpc" {}`                      | `component "vpc" {}`                   |
| `${var.region}`                        | `${input.region}`                      |
| `${aws_s3_bucket.assets.bucket}`       | `~unit.aws_s3_bucket_v2.assets.bucket` |
| `data "aws_vpc" "main" {}`             | `data "aws_vpc" "main" {}`             |

## Example

Input (`main.tf`):

```hcl theme={null}
variable "env" {
  default = "staging"
}

resource "aws_s3_bucket" "assets" {
  bucket = "${var.env}-assets"
}

output "bucket_name" {
  value = aws_s3_bucket.assets.bucket
}
```

Output (`main.iac`):

```hcl theme={null}
input "env" {
  default = "staging"
}

unit "aws_s3_bucket_v2" "assets" {
  bucket = "${input.env}-assets"
}

output "bucket_name" {
  value = ~unit.aws_s3_bucket_v2.assets.bucket
}
```

## Key Differences

| Concept            | Terraform                     | ubx                                    |
| ------------------ | ----------------------------- | -------------------------------------- |
| Resource reference | `aws_s3_bucket.assets.bucket` | `~unit.aws_s3_bucket_v2.assets.bucket` |
| Output wiring      | Manual                        | Native `~` sigil                       |
| Modules            | `module` block                | `component` block                      |
| Variables          | `variable` block              | `input` block                          |
| Locals             | `locals {}`                   | `local "name" {}`                      |
| Data sources       | `data` block                  | `data` block                           |

## After Migration

```bash theme={null}
ubx validate          # check for errors
ubx plan              # preview what will deploy
ubx explain           # understand the converted infrastructure
```
