<a id="projects-create"></a>

# How to create and configure projects

You can configure projects at creation time or later.
However, note that it is not possible to modify the features that are enabled for a project when the project contains instances.

## Create a project

CLI

To create a project, use the [`lxc project create`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/project/create/index.html.md#lxc-project-create-md) command.

You can specify configuration options by using the `--config` flag.
See [Project configuration](https://canonical.com/lxd/docs/latest/reference/projects/index.html.md#ref-projects) for the available configuration options.

For example, to create a project called `my-project` that isolates instances, but allows access to the default project’s images and profiles, enter the following command:

```none
lxc project create my-project --config features.images=false --config features.profiles=false
```

To create a project called `my-restricted-project` that blocks access to security-sensitive features (for example, container nesting) but allows snapshots, enter the following command:

```none
lxc project create my-restricted-project --config restricted=true --config restricted.snapshots=allow
```

API

To create a project, send a POST request to the `/1.0/projects` endpoint.

You can specify configuration options under the `"config"` field.
See [Project configuration](https://canonical.com/lxd/docs/latest/reference/projects/index.html.md#ref-projects) for the available configuration options.

For example, to create a project called `my-project` that isolates instances, but allows access to the default project’s images and profiles, send the following request:

```none
lxc query --request POST /1.0/projects --data '{
  "config": {
    "features.images": "false",
    "features.profiles": "false"
  },
  "name": "my-project"
}'
```

To create a project called `my-restricted-project` that blocks access to security-sensitive features (for example, container nesting) but allows snapshots, send the following request:

```none
lxc query --request POST /1.0/projects --data '{
  "config": {
    "restricted": "true",
    "restricted.snapshots": "allow"
  },
  "name": "my-restricted-project"
}'
```

See [`POST /1.0/projects`](/lxd/latest/api/#/projects/projects_post) for more information.

UI

To create a project, expand the Project drop-down and select + Create project at the bottom.

Enter a name and optionally a description for the new project.
You can create the project using the default set of features or select Customised to add or remove specific features.
See [Project features](https://canonical.com/lxd/docs/latest/reference/projects/index.html.md#project-features) for more information about the available features.

For example, to create a project called `my-project` that isolates instances, but allows access to the default project’s images and profiles:

![Create a project](images/UI/create_project.png)

To configure resource limits for the project, select Resource limits.

To restrict a project from accessing security-sensitive features, check Allow custom restrictions on a project level.
You can then configure the restrictions under Restrictions.
See [Project restrictions](https://canonical.com/lxd/docs/latest/reference/projects/index.html.md#project-restrictions) for more information.

For example, to create a project called `my-restricted-project` that blocks access to security-sensitive features (for example, container nesting) but allows snapshots:

1. Check Allow custom restrictions on a project level:
   ![Create a restricted project](images/UI/create_restr_project1.png)
2. Configure the restrictions:
   ![Allow snapshots in a restricted project](images/UI/create_restr_project2.png)

#### TIP
When you create a project with the default options, [`features.profiles`](https://canonical.com/lxd/docs/latest/reference/projects/index.html.md#project-features:features.profiles) is set to `true`, which means that profiles are isolated in the project.

Consequently, the new project does not have access to the `default` profile of the `default` project and therefore misses required configuration for creating instances (like the root disk).
To fix this, add a root disk device to the project’s `default` profile (see [Set specific options for a profile](https://canonical.com/lxd/docs/latest/profiles/index.html.md#profiles-set-options) for instructions).

<a id="projects-configure"></a>

## Configure a project

To configure a project, you can either set a specific configuration option or edit the full project.

Some configuration options can only be set for projects that do not contain any instances.

### Set specific configuration options

CLI

To set a specific configuration option, use the [`lxc project set`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/project/set/index.html.md#lxc-project-set-md) command.

For example, to limit the number of containers that can be created in `my-project` to five, enter the following command:

```none
lxc project set my-project limits.containers=5
```

To unset a specific configuration option, use the [`lxc project unset`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/project/unset/index.html.md#lxc-project-unset-md) command.

#### NOTE
If you unset a configuration option, it is set to its default value.
This default value might differ from the initial value that is set when the project is created.

API

To set a specific configuration option, send a PATCH request to the project.

For example, to limit the number of containers that can be created in `my-project` to five, send the following request:

```none
lxc query --request PATCH /1.0/projects/my-project --data '{
  "config": {
    "limits.containers": "5"
  }
}'
```

See [`PATCH /1.0/projects/{name}`](/lxd/latest/api/#/projects/project_patch) for more information.

UI

To update the project configuration, select the respective project from the Project drop-down.
Then go to Configuration and click Edit configuration to set or unset any configuration options.

### Edit the project

CLI

To edit the full project configuration, use the [`lxc project edit`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/project/edit/index.html.md#lxc-project-edit-md) command.
For example:

```none
lxc project edit my-project
```

API

To update the entire project configuration, send a PUT request to the project.
For example:

```none
lxc query --request PUT /1.0/projects/my-project --data '{
  "config": { ... },
  "description": "<description>"
}'
```

See [`PUT /1.0/projects/{name}`](/lxd/latest/api/#/projects/project_put) for more information.

UI

The UI does not currently support editing the full YAML configuration for a project.
However, you can update several or all configuration options at the same time through the UI.
