VK Cloud logo
Updated at April 15, 2024   08:50 AM

Creating key pairs

To create a key pair, create a keypair.tf file that describes its configuration. Add the text from the example below and correct the settings for your infrastructure. This example describes how to create a key pair with the name test-keypair and display the public and private keys using the output operator.

Create a key pair

To create a key pair, you need the vkcs_compute_keypair resource.

resource "vkcs_compute_keypair" "keypair" {  name = "test-keypair"}output "public_key" {  value = vkcs_compute_keypair.keypair.public_key}output "private_key" {  value = vkcs_compute_keypair.keypair.private_key  sensitive = true}

Here, name is a unique name of the key pair (a required argument). Changing this argument will create a new key pair.

Apply changes

Add the text of the example to the keypair.tf file and run the commands:

terraform init
terraform apply