# Workloads - Terraform Resources

import DocButton from '~/components/webkit/DocButton.vue';

<DocButton href="https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload" label="View in Terraform Registry" kind="secondary" size="medium" />

Workloads are the fundamental deployment unit on the Azion Platform. They represent your applications and services that are delivered through the global network of edge nodes.

---

The `azion_workload` resource allows you to manage workloads through Terraform. Each workload can have multiple deployments, managed by the `azion_workload_deployment` resource.

### Available Resources

| Resource | Description |
|---------|-------------|
| [`azion_workload`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload) | Creates and manages workloads |
| [`azion_workload_deployment`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload_deployment) | Creates and manages workload deployments |

### Available Data Sources

| Data Source | Description |
|--------------|-------------|
| [`azion_workloads`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/workloads) | Query existing workloads |

---

## azion_workload

### Basic Example

```hcl
resource "azion_workload" "example" {
  name = "my-workload"
  
  # Workload configuration
}
```

### Main Arguments

| Argument | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | Unique workload name |

For the complete list of arguments, see the [Terraform Registry](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload).

### Exported Attributes

| Attribute | Type | Description |
|----------|------|-------------|
| `id` | string | Unique workload ID |

---

## azion_workload_deployment

### Basic Example

```hcl
resource "azion_workload" "example" {
  name = "my-workload"
}

resource "azion_workload_deployment" "example" {
  workload_id = azion_workload.example.id
  
  # Deployment configuration
}
```

### Main Arguments

| Argument | Type | Required | Description |
|-----------|------|----------|-------------|
| `workload_id` | string | Yes | ID of the associated workload |

For the complete list of arguments, see the [Terraform Registry](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload_deployment).

---

## Complete Example

```hcl
terraform {
  required_providers {
    azion = {
      source  = "aziontech/azion"
      version = "2.0.0"
    }
  }
}

provider "azion" {
  api_token = var.api_token
}

# Create a workload
resource "azion_workload" "my_app" {
  name = "my-application"
}

# Create a deployment for the workload
resource "azion_workload_deployment" "my_app_deployment" {
  workload_id = azion_workload.my_app.id
  
  # Additional deployment configuration
}

# Query existing workloads
data "azion_workloads" "all" {}

output "workload_id" {
  value = azion_workload.my_app.id
}
```

---

## Migrating from Domains (V3 to V4)

If you're migrating from API v3, the `azion_domain` resource has been replaced by `azion_workload` and `azion_workload_deployment`.

### Before (V3)

```hcl
resource "azion_domain" "example" {
  name             = "my-domain"
  edge_application = 12345
  domain_name      = "example.com"
}
```

### After (V4)

```hcl
resource "azion_workload" "example" {
  name = "my-workload"
}

resource "azion_workload_deployment" "example" {
  workload_id = azion_workload.example.id
}
```

See the [Migration Guide](/en/documentation/products/terraform-provider/terraform-migration-v3-to-v4/) for more details.

---

## Next Steps

- [Connectors](/en/documentation/products/terraform-provider/resources/connectors/) - Manage origin connectors
- [Applications](/en/documentation/products/terraform-provider/resources/applications/) - Manage applications