---
title: "Resource selectel_vpc_keypair_v2"
sidebar_label: "selectel_vpc_keypair_v2"
description: "Creates and manages an SSH key pair for Selectel products using public API v2"
sidebar_position: 33
---

# Resource selectel\_vpc\_keypair\_v2

:::info

This guide is a copy of the Selectel Terraform provider documentation in the [Terraform Registry](https://registry.terraform.io/providers/selectel/selectel/latest/docs).

:::

Creates and manages an SSH key pair using public API v2. For more information about SSH key pairs, see the [official Selectel documentation](/cloud-servers/manage/create-and-place-ssh-key/).

Selectel products support Identity and Access Management (IAM). Only service users can use SSH key pairs. To create a service user, use the [selectel\_iam\_serviceuser\_v1](/terraform/selectel-provider-reference/resources/iam_serviceuser_v1/) resource. For more information about service users, see the [official Selectel documentation](/access-control/access-management/).

## Example Usage \{#example-usage}

```hcl
resource "selectel_vpc_keypair_v2" "keypair_1" {
  name       = "keypair"
  public_key = file("~/.ssh/id_rsa.pub")
  user_id    = selectel_iam_serviceuser_v1.user_1.id
}
```

## Argument Reference \{#argument-reference}

* `name` - (Required) Name of the SSH key pair. Changing this value creates a new key pair.

* `public_key` - (Required) Pregenerated OpenSSH-formatted public key. Changing this value creates a new key pair. Learn more about [creating an SSH key pair](/cloud-servers/manage/create-and-place-ssh-key/#create-ssh-keys).

* `user_id` - (Required) Unique identifier of the associated service user. Changing this value creates a new key pair. Retrieved from the [selectel\_iam\_serviceuser\_v1](/terraform/selectel-provider-reference/resources/iam_serviceuser_v1/) resource.

* `regions` - (Optional) List of pools where the key pair is located, for example, `ru-3`. Changing this value creates a new key pair. Learn more about available pools in the [Availability matrix](/infrastructure/product-availability-by-location/).

## Import \{#import}

You can import an SSH key pair:

```shell
export OS_DOMAIN_NAME=<account_id>
export OS_USERNAME=<username>
export OS_PASSWORD=<password>
terraform import selectel_vpc_keypair_v2.keypair_1 <user_id>/<keypair_name>
```

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.

* `<user_id>` — Unique identifier of the associated service user, for example, `abc1bb378ac84e1234b869b77aadd2ab`. To get the ID, 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.

* `<keypair_name>` — Name of the key pair, for example, `Key`. 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 ⟶ the user page. The SSH key pair name is in the **SSH keys** section.
