# Workloads resources

[View in Terraform Registry](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/workload)

A workload is the deployment unit of the Azion Platform: it represents an application or a service that Azion's distributed infrastructure delivers. The Azion Terraform Provider manages [Workloads](/en/documentation/platform/workloads/) with two resources and reads them with four data sources. One workload can have several deployments, and each deployment is a separate `azion_workload_deployment` resource. In provider v1.x, a single domain resource did the work of these two resources. To move a v1.x configuration to them, refer to [Migrate from provider v1.x to v2.0](/en/documentation/devtools/terraform/terraform-migration-v3-to-v4/).

---

## Workload resources

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

`azion_workload` requires `name`, a string that holds the unique name of the workload, and exports `id`, a string that holds the unique ID of the workload. `azion_workload_deployment` requires `workload_id`, a string that holds the ID of the workload it deploys. The Terraform Registry page of each resource lists every argument.

---

## Data sources

| Data source                                                                                                                           | Description                 |
| ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| [`azion_workloads`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/workloads)                       | Lists workloads.            |
| [`azion_workload`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/workload)                         | Reads one workload.         |
| [`azion_workload_deployments`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/workload_deployments) | Lists workload deployments. |
| [`azion_workload_deployment`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/workload_deployment)   | Reads one deployment.       |

---

## Example

This configuration pins the provider, creates a workload and one deployment of it, reads the existing workloads, and outputs the ID of the workload. It reads your personal token from the `api_token` variable that the [Azion Terraform Provider quickstart](/en/documentation/devtools/terraform/getting-started/) declares.

```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
}
```

---

## Related resources

- [Workloads](/en/documentation/platform/workloads.md): The platform page for workloads and their deployments.
- [Resources and data sources](/en/documentation/devtools/terraform/examples.md): Every resource and data source of the provider, with an example per family.
- [Applications resources](/en/documentation/devtools/terraform/applications.md): The resources that manage applications, their cache settings, rules, device groups, and function instances.
- [Connectors resources](/en/documentation/devtools/terraform/connectors.md): The resource that manages connectors to origins.
