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:
-
resources:
- vkcs_networking_network — creates a network to host the server;
- vkcs_networking_subnet — creates a subnet in this network;
- vkcs_compute_keypair — creates an SSH key pair;
- vkcs_baremetal_server — creates a Bare Metal server;
-
data sources:
- vkcs_baremetal_flavor — allows you to get information about the Bare Metal server configuration template;
- vkcs_baremetal_flavors — allows you to get information about configuration templates available for a Bare Metal server;
- vkcs_baremetal_os — allows you to get information about the Bare Metal server operating system;
- vkcs_baremetal_oses — allows you to get information about OSes available for a Bare Metal server;
- vkcs_baremetal_server — allows you to get information about a Bare Metal server.
-
Contact technical support to enable the ability to rent Bare Metal servers in your project, if this has not been done yet.
-
Make sure your account balance is sufficient to rent the desired Bare Metal server configuration.
-
Install Terraform and configure the provider if this has not been done yet.
Put the provider settings into the Terraform configuration file
provider.tf.
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.idname = data.vkcs_baremetal_flavor.tf_flavor.namecpu_cores = data.vkcs_baremetal_flavor.tf_flavor.cpu_coresram_size = data.vkcs_baremetal_flavor.tf_flavor.ram_sizessd_size = data.vkcs_baremetal_flavor.tf_flavor.ssd_sizehdd_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.idkey_pair = vkcs_compute_keypair.tf_bmaas.nameuser_data = file("cloud-init-user-data.yaml")availability_zone = "ME1"os_id = data.vkcs_baremetal_os.my_os.idraid_type = "NO_RAID"nic {name = "nic0"vlan {native = truenetwork_id = vkcs_networking_network.network.idsubnet_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-serverin the availability zone ME1 with one physical network interfacenic0; -
resources and data assigned to the server:
- an SSH key pair for accessing the server — a new key pair named
terraform-bmaasis created; - the server configuration template (flavor) — a template named
BM_CX301_N_2_niccontaining 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_networkand a subnet with default parameters are created.
- an SSH key pair for accessing the server — a new key pair named
-
Place all Terraform configuration files in one directory:
provider.tf,main.tf.
-
Go to this directory.
-
Run the command:
terraform init -
Run the command:
terraform applyWhen prompted for confirmation, enter
yes. -
Wait for the operation to complete.
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%...
A Bare Metal server consumes resources and is billed. If you no longer need it, delete it:
-
Go to the directory with the Terraform configuration files.
-
Run the command:
terraform destroyWhen prompted for confirmation, enter
yes. -
Wait for the operation to complete.