---
title: 'Ресурс selectel_vpc_subnet_v2'
sidebar_label: "selectel_vpc_subnet_v2"
description: 'Creates and manages a public subnet for Selectel products using public API v2'
sidebar_position: 36
---

# Ресурс selectel\_vpc\_subnet\_v2

:::info

Эта инструкция — копия документации Selectel Terraform-провайдера в [Terraform Registry](https://registry.terraform.io/providers/selectel/selectel/latest/docs).

:::

Creates and manages a public subnet using public API v2. For more information about public subnets, see the [official Selectel documentation](/cloud-servers/cloud-networks/about-networks/).

For private networks and subnets, use [openstack\_networking\_network\_v2](/terraform/openstack-provider-reference/networking-neutron/resources/openstack_networking_network_v2/) and [openstack\_networking\_subnet\_v2](/terraform/openstack-provider-reference/networking-neutron/resources/openstack_networking_subnet_v2/) resources of the OpenStack provider.

Resource creates a public OpenStack subnet in a service OpenStack network. You cannot select a network during subnet creation, and you cannot modify service network settings.

## Example Usage \{#example-usage}

```hcl
resource "selectel_vpc_subnet_v2" "subnet_1" {
  project_id    = selectel_vpc_project_v2.project_1.id
  region        = "ru-3"
  ip_version    = "ipv4"
  prefix_length = 29
}
```

## Argument Reference \{#argument-reference}

* `project_id` - (Required) Unique identifier of the associated project. Changing this creates a new public subnet. Retrieved from the [selectel\_vpc\_project\_v2](/terraform/selectel-provider-reference/resources/vpc_project_v2) resource. Learn more about [Projects](/access-control/projects/about-projects/).

* `region` - (Required) Pool where the public subnet is located, for example, `ru-3`. Changing this creates a new public subnet. Learn more about available pools in [Product availability by location](/infrastructure/product-availability-by-location/).

* `ip_version` - (Optional) Internet protocol version supported in the public subnet. The only available value is `ipv4`.

* `prefix_length` - (Optional) Prefix length of the public subnet. The default value is `29`. Changing this creates a new public subnet.

## Attributes Reference \{#attributes-reference}

* `cidr` - CIDR of the public subnet.

* `network_id` - Unique identifier of the parent network (a service OpenStack network).

* `subnet_id` - Unique identifier of the public subnet.

* `status` - Status of the public subnet.

* `servers` - List of cloud servers that are located in the public subnet.

  * `id` - Unique identifier of the cloud server.

  * `name` - Name of the cloud server.

  * `status` - Status of the cloud server.

## Import \{#import}

You can import a public subnet:

```shell
export OS_DOMAIN_NAME=<account_id>
export OS_USERNAME=<username>
export OS_PASSWORD=<password>
terraform import selectel_vpc_subnet_v2.subnet_1 <public_subnet_id>
```

where:

* `<account_id>` — Selectel account ID. The account ID is in the top right corner of the [Control panel](https://my.selectel.ru/). Learn more about [Registration](/account/registration/).

* `<username>` — Name of the service user. To get the name, in the [Control panel](https://my.selectel.ru/iam/users_management/users?type=service), go to **Identity & Access Management** ⟶ **User management** ⟶ the **Service users** tab ⟶ copy the name of the required user. Learn more about [Service users](/access-control/access-management/).

* `<password>` — Password of the service user.

* `<public_subnet_id>` — Unique identifier of the public subnet. To get public subnet ID, use the [Get list of subnets](https://docs.selectel.ru/en/api/cloud-projects-and-resources/#tag/Subnets/operation/listSubnets) method in [Cloud Platform Projects and Resources API](https://docs.selectel.ru/api/cloud-projects-and-resources/).
