# Azion CLI config

The Azion CLI `config` commands manage Azion resources from manifest files: `init` creates an empty `azion.json` file, `apply` creates or updates the resources that an [azion.config](/en/documentation/devtools/cli/azion-config-js/) file declares, and `delete` deletes the resources that `azion.json` lists. The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Usage

`azion config` groups the `init`, `apply`, and `delete` subcommands:

```bash
azion config [flags]
```

The command takes no flags of its own. Run it with a subcommand.

The `config` subcommands read and write `azion.json` in the current directory by default. The `azion init`, `azion link`, and `azion deploy` commands keep the same file in the `azion` folder instead. To point a `config` subcommand at another folder, use `--config-dir`.

---

## Init

`azion config init` creates an `azion.json` file to store the state of your application:

```bash
azion config init [flags]
```

| Flag           | Short | Type   | Default | Description                                                |
| -------------- | ----- | ------ | ------- | ---------------------------------------------------------- |
| `--config-dir` | —     | string | `"."`   | Path to the folder where the command creates `azion.json`. |
| `--force`      | —     | —      | —       | Overwrites an `azion.json` file that already exists.       |

This command creates the file in an empty folder:

```bash
azion config init
```

The command prints the path of the file it created:

```text
Creating azion.json file
Configuration file created successfully: <project-dir>/azion.json
For more information on azion.config, visit: https://github.com/aziontech/lib?tab=readme-ov-file#config/
```

The new `azion.json` holds every key with an empty value:

```json
{
  "name": "",
  "bucket": "",
  "preset": "",
  "env": "",
  "prefix": "",
  "function": null,
  "application": {
    "id": 0,
    "name": ""
  },
  "domain": {
    "id": 0,
    "name": "",
    "domain_name": "",
    "url": ""
  },
  "rt-purge": {
    "purge_on_publish": false
  },
  "origin": null,
  "rules-engine": {
    "created": false,
    "rules": null
  },
  "cache-settings": null,
  "workloads": {
    "id": 0,
    "name": "",
    "domains": null,
    "url": "",
    "deployment_id": null
  },
  "connectors": null
}
```

When the folder already holds an `azion.json` file, the command keeps the file and stops with `Error: Configuration file already exists`. To replace the file, add `--force`.

---

## Apply

`azion config apply` reads the `azion.config` file of the folder and creates or updates the resources it declares on your account:

```bash
azion config apply [flags]
```

| Flag            | Short | Type   | Default | Description                                                                                                                                                                                                                                                                                                                           |
| --------------- | ----- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--config-dir`  | —     | string | `"."`   | Path to the folder that holds `azion.json` and the `azion.config` file.                                                                                                                                                                                                                                                               |
| `--config-file` | —     | string | —       | Path to the `azion.config` file to apply, such as `azion.staging.config.cjs`. Where `--config-dir` names a folder, the one that holds `azion.json` and the `azion.config` file, `--config-file` names the configuration file itself. A relative path resolves from the current directory. A path to a missing file fails the command. |

This `azion.config.mjs` file declares an application with a cache setting and a request rule, and a workload that deploys the application:

```javascript
export default {
  applications: [
    {
      name: 'my-app',
      active: true,
      cache: [
        {
          name: 'my-app-cache',
          browser: { maxAgeSeconds: 600 },
          edge: { maxAgeSeconds: 600 }
        }
      ],
      rules: {
        request: [
          {
            name: 'Set cache policy',
            active: true,
            criteria: [[{ variable: '${uri}', conditional: 'if', operator: 'starts_with', argument: '/' }]],
            behaviors: [{ type: 'set_cache_policy', attributes: { value: 'my-app-cache' } }]
          }
        ]
      }
    }
  ],
  workloads: [
    {
      name: 'my-app',
      active: true,
      infrastructure: 1,
      deployments: [
        {
          name: 'my-app',
          current: true,
          active: true,
          strategy: { type: 'default', attributes: { application: 'my-app' } }
        }
      ]
    }
  ]
}
```

This command applies the file from the folder that holds it and the `azion.json` file that `config init` created:

```bash
azion config apply
```

The command generates `.edge/manifest.json` from the file, then prints one line per resource it creates:

```text
…
[Azion] [IaC] › ✔  success   Manifest generated successfully at <project-dir>/.edge/manifest.json
Reading manifest.json file
Edge Application my-app with id 1234567894 successfully created
Cache Setting my-app-cache with id 123469 successfully created
Rule Engine Set cache policy with id 123462 successfully created
Rules Engine of Application with id 1234567894 successfully ordered (request phase)
Workload my-app with id 1234567904 successfully created
Workload Deployment my-app with id 123474 successfully created
Configuration applied successfully: 3 resource(s) applied
```

The command records the ID of each resource in `azion.json`. A second run with the same file updates the same resources by ID instead of creating new ones:

```bash
azion config apply
```

The command prints one line per resource it updates:

```text
…
[Azion] [IaC] › ✔  success   Manifest generated successfully at <project-dir>/.edge/manifest.json
Reading manifest.json file
Edge Application my-app with id 1234567894 successfully updated
Cache Setting my-app-cache with id 123469 successfully updated
Rule Engine Set cache policy with id 123462 successfully updated
Rules Engine of Application with id 1234567894 successfully ordered (request phase)
Workload my-app with id 1234567904 successfully updated
Workload Deployment my-app with id 123474 successfully updated
Configuration applied successfully: 3 resource(s) applied
```

---

## Delete

`azion config delete` deletes every resource that `azion.json` lists, then resets `azion.json` to the empty file that `config init` creates:

```bash
azion config delete [flags]
```

| Flag           | Short | Type   | Default | Description                                                    |
| -------------- | ----- | ------ | ------- | -------------------------------------------------------------- |
| `--config-dir` | —     | string | `"."`   | Relative path to the folder that holds your `azion.json` file. |
| `--force`      | —     | —      | —       | Deletes the resources without asking for confirmation.         |

Without `--force`, the command asks `This will delete all resources defined in azion.json. Continue? (y/N)` before it deletes anything.

---

## Related resources

- [Global options](/en/documentation/devtools/cli/globals.md): The options every command accepts, such as `--format`, `--out`, and `-y`.
- [azion.config.js](/en/documentation/devtools/cli/azion-config-js.md): The keys an `azion.config` file declares, which `config apply` turns into resources.
- [Azion CLI deploy](/en/documentation/devtools/cli/deploy.md): How a project is built and deployed, with the IDs it writes into `azion/azion.json`.
- [Workloads](/en/documentation/platform/workloads.md): What a workload and its deployment do with the application that `config apply` creates.
