VK Cloud logo

Creating a Bare Metal server

Using Terraform, you can create (rent) Bare Metal servers. As an example, a server with a basic network interface configuration will be created.

Also, using the vkcs_baremetal_server resource, you can create servers with the following network interface configurations:

  • with aggregated (bonded) interfaces;
  • with interfaces for working in tagged networks (tagged VLAN).

A new SSH key pair will be used to access the server.

When creating the server, the following are used:

Preparation steps

  1. Contact technical support to enable the ability to rent Bare Metal servers in your project, if this has not been done yet.

  2. Make sure your account balance is sufficient to rent the desired Bare Metal server configuration.

  3. Install Terraform and configure the provider if this has not been done yet.

    Put the provider settings into the Terraform configuration file provider.tf.

1. Create a file describing the server

Create the main.tf file.

Add the following content to the file and edit it if necessary:

resource "vkcs_compute_keypair" "tf_bmaas" {  name       = "terraform-bmaas"  public_key = file("terraform-bmaas.pub")}data "vkcs_baremetal_flavor" "tf_flavor" {  name = "BM_CX301_N_2_nic"  # cpu_model = "Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz"}output "flavor_info" {  value = {    id        = data.vkcs_baremetal_flavor.tf_flavor.id    name      = data.vkcs_baremetal_flavor.tf_flavor.name    cpu_cores = data.vkcs_baremetal_flavor.tf_flavor.cpu_cores    ram_size  = data.vkcs_baremetal_flavor.tf_flavor.ram_size    ssd_size  = data.vkcs_baremetal_flavor.tf_flavor.ssd_size    hdd_size  = data.vkcs_baremetal_flavor.tf_flavor.hdd_size  }}data "vkcs_baremetal_os" "my_os" {  name      = "ubuntu"  version   = "22.04"  raid_type = "NO_RAID"}resource "vkcs_networking_network" "network" {  name        = "tf_test_network"  description = "my network description"}resource "vkcs_networking_subnet" "subnet" {  network_id = vkcs_networking_network.network.id}resource "vkcs_baremetal_server" "server" {  name              = "tf-server"  flavor_id         = data.vkcs_baremetal_flavor.tf_flavor.id  key_pair          = vkcs_compute_keypair.tf_bmaas.name  user_data         = file("cloud-init-user-data.yaml")  availability_zone = "ME1"  os_id             = data.vkcs_baremetal_os.my_os.id  raid_type         = "NO_RAID"  nic {    name = "nic0"    vlan {      native     = true      network_id = vkcs_networking_network.network.id      subnet_id  = vkcs_networking_subnet.subnet.id    }  }}data "vkcs_baremetal_server" "example" {  id    = vkcs_baremetal_server.server.id}

The file describes:

  • server parameters — a server named tf-server in the availability zone ME1 with one physical network interface nic0;

  • resources and data assigned to the server:

    • an SSH key pair for accessing the server — a new key pair named terraform-bmaas is created;
    • the server configuration template (flavor) — a template named BM_CX301_N_2_nic containing a configuration based on the Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz processor;
    • the server OS — Ubuntu version 22.04 installed without using a software array;
    • the network and subnet where the server will be hosted — a new network named tf_test_network and a subnet with default parameters are created.

2. Create resources using Terraform

  1. Place all Terraform configuration files in one directory:

    • provider.tf,
    • main.tf.
  2. Go to this directory.

  3. Run the command:

    terraform init
  4. Run the command:

    terraform apply

    When prompted for confirmation, enter yes.

  5. Wait for the operation to complete.

3. Verify that the server is operational

Connect to the server using the private SSH key from the created key pair terraform-bmaas.

If the connection is successful, the console will show typical Ubuntu output:

Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-46-generic x86_64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/advantageSystem information as of Wed May 10 18:05:44 UTC 2023System load: 0.0078125 Processes: 98Usage of /: 35.2% of 7.42GB Users logged in: 0Memory usage: 9% IPv4 address for ens3: 192.168.199.20Swap usage: 0%...

Delete unused resources

A Bare Metal server consumes resources and is billed. If you no longer need it, delete it:

  1. Go to the directory with the Terraform configuration files.

  2. Run the command:

    terraform destroy

    When prompted for confirmation, enter yes.

  3. Wait for the operation to complete.