# Applications resources

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

An application carries the content delivery logic of the Azion Platform: its [cache settings](/en/documentation/platform/applications/cache/cache-settings/), the [Rules Engine](/en/documentation/platform/applications/rules-engine/) rules that process each request, its [device groups](/en/documentation/platform/applications/device-groups/), and the [function instances](/en/documentation/platform/applications/functions-instances/) it runs. The Azion Terraform Provider manages [Applications](/en/documentation/platform/applications/) with five resources and reads them with nine data sources. To move a v1.x configuration to these resources, refer to [Migrate from provider v1.x to v2.0](/en/documentation/devtools/terraform/terraform-migration-v3-to-v4/).

---

## Application resources

| Resource                                                                                                                                               | Description                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| [`azion_application_main_setting`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/application_main_setting)             | Creates and manages the main settings of an application.   |
| [`azion_application_cache_setting`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/application_cache_setting)           | Creates and manages a cache setting.                       |
| [`azion_application_device_group`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/application_device_group)             | Creates and manages a device group.                        |
| [`azion_application_rule_engine`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/application_rule_engine)               | Creates and manages a Rules Engine rule.                   |
| [`azion_application_functions_instance`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/resources/application_functions_instance) | Creates and manages a function instance in an application. |

`azion_application_main_setting` requires `name`, a string that holds the name of the application. A cache setting, a Rules Engine rule, and a function instance belong to one application, so each of their resources takes the ID of that application in `application_id`. Cache settings and rules also take a `name`, and a rule takes the `phase` it runs in. `azion_application_functions_instance` takes `function_id`, the ID of a function that the `azion_function` resource manages. The Terraform Registry page of each resource lists every argument.

---

## Data sources

| Data source                                                                                                                                                | Description                                |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [`azion_application_main_settings`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_main_settings)            | Queries the main settings of applications. |
| [`azion_application_cache_settings`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_cache_settings)          | Lists cache settings.                      |
| [`azion_application_cache_setting`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_cache_setting)            | Reads one cache setting.                   |
| [`azion_application_device_groups`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_device_groups)            | Lists device groups.                       |
| [`azion_application_device_group`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_device_group)              | Reads one device group.                    |
| [`azion_application_rules_engine`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_rules_engine)              | Lists Rules Engine rules.                  |
| [`azion_application_rule_engine`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_rule_engine)                | Reads one Rules Engine rule.               |
| [`azion_application_functions_instances`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_functions_instance) | Lists function instances.                  |
| [`azion_application_functions_instance`](https://registry.terraform.io/providers/aziontech/azion/latest/docs/data-sources/application_functions_instance)  | Reads one function instance.               |

---

## Example

This configuration pins the provider to version 2.0.0, creates an application, adds a cache setting and a Rules Engine rule in the `request` phase, instantiates a function in the application, and outputs the ID of the application. It reads your personal token from the `api_token` variable that the [Azion Terraform Provider quickstart](/en/documentation/devtools/terraform/getting-started/) declares. The function instance reads `function_id` from an `azion_function` resource named `my_function`, which this configuration does not declare. To look up that resource, refer to [Resources and data sources](/en/documentation/devtools/terraform/examples/#functions).

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

provider "azion" {
  api_token = var.api_token
}

# Create main application
resource "azion_application_main_setting" "my_app" {
  name = "my-application"
}

# Configure cache
resource "azion_application_cache_setting" "my_cache" {
  application_id = azion_application_main_setting.my_app.id
  name           = "static-cache"

  # Cache configuration
}

# Create rule in Rules Engine
resource "azion_application_rule_engine" "my_rule" {
  application_id = azion_application_main_setting.my_app.id
  name           = "redirect-rule"
  phase          = "request"

  # Criteria and behaviors
}

# Instantiate a function
resource "azion_application_functions_instance" "my_function" {
  application_id = azion_application_main_setting.my_app.id
  function_id    = azion_function.my_function.id

  # Instance configuration
}

output "application_id" {
  value = azion_application_main_setting.my_app.id
}
```

---

## Related resources

- [Resources and data sources](/en/documentation/devtools/terraform/examples.md): Every resource and data source of the provider, including the Functions resource that a function instance references.
- [Workloads resources](/en/documentation/devtools/terraform/workloads.md): The resources that create and deploy workloads.
- [Connectors resources](/en/documentation/devtools/terraform/connectors.md): The resource that manages connectors to origins.
- [Migrate from provider v1.x to v2.0](/en/documentation/devtools/terraform/terraform-migration-v3-to-v4.md): The steps that move a v1.x configuration of application resources to provider v2.0.
