---
title: "openstack_compute_keypair_v2"
description: ""
sidebar_position: 6
---

# openstack\_compute\_keypair\_v2

:::info

This instruction is an adapted copy of the official OpenStack Terraform provider documentation in the [Terraform Registry](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs).

:::

The private key generated by this resource will be stored *unencrypted* in your Terraform state file. **Use of this resource for production deployments is *not* recommended**. Instead, generate a private key file outside of Terraform and distribute it securely to the system where Terraform will be run.

## Example Usage \{#example-usage}

### Import an Existing Public Key \{#import-an-existing-public-key}

```hcl
resource "openstack_compute_keypair_v2" "test-keypair" {
  name       = "my-keypair"
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCfeXP/9p4ffqe+yfGOP4a53nFdAkkJj0sFUg8z1KxLonuhF2hBRI5hWZFa7af40ShJGNaRD1IJUMtpUSltyUwLYNsBSPpnrJ56YhCZFu5X+GPgGmzegR1T7m7MlL6zjsrLdVRaVyj944CWjEOL0iF0Is3VmgdYQxkb77GXGSwsd6rr8s1LZwayuyM+bPqbi2e91aODMGre6uTI/4D6u2p9upwwEPs80bMOVFk8T3foRGE0euYWbUqgi1zV/yzBoOSUJ6OxI+CMlR7k2jzl0Ld1ZlUNoIutrLhMmRtBWHlHSZfPSWlv7xtcWqD8pe8JVi5acrHFLV4hSqtLm6/m+hscKKtEMZikM3rEaO1qMTuXdj2eyxk/tY83KEk4RnS656w/y6JuZ35Uhu2/3diKfuNEUe7GQeYxSCVmFShoOtjuSnoDG67PKHbmw0buC5CZ7A2e6GyvktmYMqmSPXGR6gv1hL5F9WKoQZaSsOuzgFnBG1dLJ9a2AD4mCjfIy4+HbHk="
}
```

### Generate a Public/Private Key Pair \{#generate-a-publicprivate-key-pair}

```hcl
resource "openstack_compute_keypair_v2" "test-keypair" {
  name = "my-keypair"
}
```

## Argument Reference \{#argument-reference}

The following arguments are supported:

* `region` - (Optional) The region in which to obtain the V2 Compute client. Key pairs are associated with accounts, but a Compute client is needed to create one. If omitted, the `region` argument of the provider is used. Changing this creates a new key pair.

* `name` - (Required) A unique name for the keypair. Changing this creates a new keypair.

* `public_key` - (Optional) A pregenerated OpenSSH-formatted public key. Changing this creates a new key pair. If a public key is not specified, then a public/private key pair will be automatically generated. If a pair is created, then destroying this resource means you will lose access to that key pair forever.

* `user_id` - (Optional) This allows administrative users to operate key-pairs of specified user ID. For this feature, you need to have OpenStack microversion 2.10 (Liberty) or later.

* `value_specs` - (Optional) Map of additional options.

## Attributes Reference \{#attributes-reference}

The following attributes are exported:

* `region` - See Argument Reference above.
* `name` - See Argument Reference above.
* `public_key` - See Argument Reference above.
* `fingerprint` - The fingerprint of the public key.
* `private_key` - The generated private key when no public key is specified.

## Import \{#import}

Keypairs can be imported using the `name`, e.g.

```bash
$ terraform import openstack_compute_keypair_v2.my-keypair test-keypair
```
