---
title: "Create a Container Registry and an authorization token using Terraform"
sidebar_label: "Create a registry and an authorization token"
description: "How to create a Container Registry and add an authorization token"
sidebar_position: 1
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import ConfigureProviders from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/configure-providers.mdx'
import ConfigureProvidersConfig from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/configure-providers-config.mdx'
import CreateResourcesAlert from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/create-resources-alert.mdx'

# Create a Container Registry and an authorization token via Terraform

<CreateResourcesAlert />

<br />

1. Optional: [configure providers](#configure-providers).
2. [Create a registry](#create-registry).
3. [Create an authorization token](#create-token).

## Configuration files \{#config}

<details>
  <summary>An example file for configuring providers</summary>

  <ConfigureProvidersConfig />
</details>

<details>
  <summary>An example file for creating a registry and an authorization token</summary>

  ```hcl
  resource "selectel_craas_registry_v1" "registry_1" {
    name       = "my-first-registry"
    project_id = selectel_vpc_project_v2.project_1.id
  }

  resource "selectel_craas_token_v2" "token_1" {
    project_id = selectel_vpc_project_v2.project_1.id
    name           = "token-name"
    mode_rw        = true
    all_registries = true
    registry_ids   = []
    is_set         = true
    expires_at     = "2029-01-01T00:00:00Z"
  }
  ```
</details>

## 1. Optional: configure providers \{#configure-providers}

If you have [configured the Selectel and OpenStack providers](/terraform/configure-terraform-environment/#configure-providers), skip this step.

<ConfigureProviders />

## 2. Create a registry \{#create-registry}

```hcl
resource "selectel_craas_registry_v1" "registry_1" {
  name       = "my-first-registry"
  project_id = selectel_vpc_project_v2.project_1.id
}
```

See the detailed description of the [selectel\_craas\_registry\_v1](/terraform/selectel-provider-reference/resources/craas_registry_v1/) resource.

## 3. Create a token \{#create-token}

```hcl
resource "selectel_craas_token_v2" "token_1" {
  project_id = selectel_vpc_project_v2.project_1.id
  name           = "token-name"
  mode_rw        = true
  all_registries = true
  registry_ids   = []
  is_set         = true
  expires_at     = "2029-01-01T00:00:00Z"
}
```

Where:

* `mode_rw` — access rights:

  * `true` — read and write. You will be able to add, download, and delete images and charts from the registry; ;
  * `false` — read-only. You will be able to download images and charts from the registry; ;

* `all_registries` — indicates whether the token grants access to all registries:

  * `true` — access to all registries. The token will also be valid for new registries you create in this project; ;
  * `false` — access to specific registries. Specify the registry IDs you want to grant access to in the argument `registry_ids`;

* optional: `registry_ids` — registry IDs to which the token grants access can be viewed in the [Control panel](https://my.selectel.ru/vpc/default/craas/): in the top menu, click **Products** and select **Container Registry** → copy the ID below the registry name; ;

* `is_set` — indicates whether the token has an expiration date:

  * `true` — the token has no expiration date. The token will also be valid for new registries you create in this project; ;
  * `false` — the token has an expiration date. Specify the token expiration date in the argument `expires_at`;

* optional: `expires_at` — token expiration date in RFC3339 format, for example, `2029-01-01T00:00:00Z`.

See the detailed description of the [selectel\_craas\_token\_v2](/terraform/selectel-provider-reference/resources/craas_token_v2/) resource.

<Formbricks />
