---
title: "Create a network volume via Terraform"
sidebar_label: "Create a network volume"
sidebar_position: 10
description: "How to create a network volume from an image or an empty network volume"
toc_max_heading_level: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import CreateResourcesAlert from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/create-resources-alert.mdx'
import ConfigureProvidersConfig from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/configure-providers-config.mdx'
import ConfigureProviders from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/configure-providers.mdx'
import GetImage from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/get-image.mdx'
import CreateBootVolume from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/create-boot-volume.mdx'
import CreateAdditionalVolume from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/create-additional-volume.mdx'

# Create a network volume via Terraform

<CreateResourcesAlert />

<br />

1. Optional: [configure providers](#configure-providers).
2. [Create a network volume](#create-volume).

   For all [network volume types](/cloud-servers/volumes/about-network-volumes/#network-volume-types) except Universal v2, the number of IOPS is fixed and depends on the volume type. For Universal v2 network volumes, you can change the total volume IOPS — increase and decrease it. The number of IOPS changes is unlimited. You can check the available number of IOPS in different volume types in the [Network volume limits](/cloud-servers/volumes/about-network-volumes/#network-volume-limits).

   You can create a volume:

   * from an image — can be used as a cloud server boot volume;
   * or empty — can be used as an additional volume.

## Configuration files \{#config}

<details>
  <summary>Example file for configuring providers</summary>

  <ConfigureProvidersConfig />
</details>

<details>
  <summary>Example file for creating a network volume from an image</summary>

  ```hcl
  data "openstack_images_image_v2" "image_1" {
    name        = "Ubuntu 20.04 LTS 64-bit"
    most_recent = true
    visibility  = "public"
  }

  resource "openstack_blockstorage_volume_v3" "volume_1" {
    name                 = "boot-volume-for-server"
    size                 = "5"
    image_id             = data.openstack_images_image_v2.image_1.id
    volume_type          = "fast.ru-9a"
    availability_zone    = "ru-9a"
    enable_online_resize = true

    lifecycle {
      ignore_changes = [image_id]
    }

  }
  ```
</details>

<details>
  <summary>Example file for creating an empty network volume</summary>

  ```hcl
  resource "openstack_blockstorage_volume_v3" "volume_2" {
    name                 = "additional-volume-for-server"
    size                 = "7"
    volume_type          = "universal.ru-9a"
    availability_zone    = "ru-9a"
    enable_online_resize = true
  }
  ```
</details>

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

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

<ConfigureProviders />

## 2. Create a network volume \{#create-volume}

<Tabs queryString="create-volume">
  <TabItem value="Сетевой диск with неизменяемыми IOPS" default>
    <TabItemLabel>
      Network volume with fixed IOPS
    </TabItemLabel>

    For all [network volume types](/cloud-servers/volumes/about-network-volumes/#network-volume-types) except Universal v2, the number of IOPS is fixed and depends on the volume type. You can check the available number of IOPS in different volume types in the subsection [Network volume limits](/cloud-servers/volumes/about-network-volumes/#network-volume-limits).

    <Tabs queryString="crete-volume-with-unchangeable-iops">
      <TabItem value="from-image" default>
        <TabItemLabel>
          Network volume from an image
        </TabItemLabel>

        1. [Get an image](#get-image).
        2. [Create a network volume](#create-volume-from-image).

        ### 1. Get an image \{#get-image}

        <GetImage />

        ### 2. Create a network volume from an image \{#create-volume-from-image}

        <CreateBootVolume />
      </TabItem>

      <TabItem value="empty">
        <TabItemLabel>
          Empty network volume
        </TabItemLabel>

        <CreateAdditionalVolume />
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="Network volume with scalable IOPS" default>
    <TabItemLabel>
      Network volume with custom IOPS
    </TabItemLabel>

    For [network volumes of type](/cloud-servers/volumes/about-network-volumes/#network-volume-types) Universal v2, you can change the total number of IOPS — decrease or increase it. Available values are from 2,000 to 16,000 IOPS. The number of IOPS changes is unlimited.

    <Tabs queryString="crete-volume-with-changeable-iops">
      <TabItem value="from-image" default>
        <TabItemLabel>
          Network volume from an image
        </TabItemLabel>

        1. [Get an image](#get-image).
        2. [Create a network volume](#create-volume-from-image).

        ### 1. Get an image \{#get-image}

        <GetImage />

        ### 2. Create a network volume from an image \{#create-volume-from-image}

        ```hcl
        resource "openstack_blockstorage_volume_v3" "volume_1" {
          name                 = "boot-volume-for-server"
          size                 = "5"
          image_id             = data.openstack_images_image_v2.image_1.id
          volume_type          = "universal2.ru-9a"
          availability_zone    = "ru-9a"
          enable_online_resize = true
          metadata             = {"total_iops_sec": "4500"}

          lifecycle {
            ignore_changes = [image_id]
          }

        }
        ```

        Where:

        * `size` — volume size in GB. Consider the [network volume limits](/cloud-servers/volumes/about-network-volumes/#network-volume-limits) on the maximum size;
        * `volume_type` — ID or name [of the network volume type](/cloud-servers/volumes/about-network-volumes/#network-volume-types). For example, `universal2.ru-9a` is the name to create a network volume with the Universal SSD v2 type in the [pool segment](/infrastructure/locations/#pool) ru-9a. You can view the list of types in the table [List of network volume types in all pool segments](/cloud-servers/volumes/about-network-volumes/#network-volume-types-full-list);
        * `availability_zone` — [pool segment](/infrastructure/locations/#pool) where the network volume will be created, for example `ru-9a`. You can view the list of available pool segments in the instructions [Product availability by location](/infrastructure/product-availability-by-location/#network-volumes);
        * `metadata` — key/value pairs for storing additional volume information:

          * `total_iops_sec` — total number of read and write operations in IOPS. Available values are from 2,000 to 16,000 IOPS. If no value is specified, the default value of 2,000 IOPS will be used.

        See the detailed description of the resource [openstack\_blockstorage\_volume\_v3](/terraform/openstack-provider-reference/block-storage-cinder/resources/openstack_blockstorage_volume_v3/).
      </TabItem>

      <TabItem value="empty">
        <TabItemLabel>
          Empty network volume
        </TabItemLabel>

        ```hcl
        resource "openstack_blockstorage_volume_v3" "volume_3" {
          name                 = "volume-with-custom-iops"
          size                 = "7"
          volume_type          = "universal2.ru-9a"
          availability_zone    = "ru-9a"
          enable_online_resize = true
          metadata             = {"total_iops_sec": "4500"}
        }
        ```

        Where:

        * `size` — volume size in GB. Consider the [network volume limits](/cloud-servers/volumes/about-network-volumes/#network-volume-limits) on the maximum size;
        * `volume_type` — ID or name [of the network volume type](/cloud-servers/volumes/about-network-volumes/#network-volume-types) Universal v2. For example, `universal2.ru-9a` is the name to create a network volume with the Universal SSD v2 type in the [pool segment](/infrastructure/locations/#pool) ru-9a. You can view the list of types in the table [List of network volume types in all pool segments](/cloud-servers/volumes/about-network-volumes/#network-volume-types-full-list);
        * `availability_zone` — [pool segment](/infrastructure/locations/#pool) where the network volume will be created, for example `ru-9a`. You can view the list of available pool segments in the instructions [Product availability by location](/infrastructure/product-availability-by-location/#network-volumes);
        * `metadata` — key/value pairs for storing additional volume information:

          * `total_iops_sec` — total number of read and write operations in IOPS. Available values are from 2,000 to 16,000 IOPS. If no value is specified, the default value of 2,000 IOPS will be used.

        See the detailed description of the resource [openstack\_blockstorage\_volume\_v3](/terraform/openstack-provider-reference/block-storage-cinder/resources/openstack_blockstorage_volume_v3/).
      </TabItem>
    </Tabs>
  </TabItem>
</Tabs>

<Formbricks />
