Create a dedicated server of ready-made configuration with a public dedicated IP address
We recommend that you create resources in order. If you create all resources at once, Terraform will take into account the dependencies between resources that you specify in the configuration file. If dependencies are not specified, resources will be created in parallel, which can cause errors. For example, a resource that is required to create another resource may not have been created yet.
- Optional: configure your ISP.
- Connect additional public IP addresses.
- Get the ID of the completed configuration.
- Get the ID of the location.
- Get an image of the OS.
- Select a public subnet.
- Create a dedicated server.
Configuration files
Example file for configuring providers
terraform {
required_providers {
selectel = {
source = "selectel/selectel"
version = "7.0.2-preview"
}
}
}
provider "selectel" {
domain_name = "123456"
username = "user"
password = "password"
auth_region = "ru-1"
auth_url = "https://cloud.api.selcloud.ru/identity/v3/"
}
Example file for creating a dedicated server of a ready-made configuration
data "selectel_dedicated_configuration_v1" "server_config" {
project_id = selectel_vpc_project_v2.project_1.id
deep_filter = <<EOT
{
"name": "CL25-SSD"
}
EOT
}
data "selectel_dedicated_location_v1" "server_location" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
name = "SPB-2"
}
}
data "selectel_dedicated_os_v1" "server_os" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
name = "Ubuntu"
version = "2404"
configuration_id = data.selectel_dedicated_configuration_v1.server_config.configurations[0].id
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
}
}
data "selectel_dedicated_public_subnet_v1" "public_subnets" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
subnet = "203.0.113.0/28"
ip = "203.0.113.12"
}
}
resource "selectel_dedicated_server_v1" "server_1" {
project_id = selectel_vpc_project_v2.project_1.id
configuration_id = data.selectel_dedicated_configuration_v1.server_config.configurations[0].id
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
os_id = data.selectel_dedicated_os_v1.server_os.os[0].id
price_plan_name = "1 day"
}
1. Optional: configure the provider
-
Make sure that in the control panel you have created a service user with the following roles member in the Account and
iam_admin. -
Create a directory to store the configuration files and a separate file with a
.tfextension to configure the providers. -
In the file for configuring providers, add the Selectel provider:
terraform {
required_providers {
selectel = {
source = "selectel/selectel"
version = "7.0.2-preview"
}
}
}Here
version—versions ofproviders. The current version can be found in Selectel documentation (in Terraform Registry and GitHub).Learn more about the products, services, and services that can be managed with providers in the Selectel and OpenStack Providers instruction.
-
Initialize the Selectel provider:
provider "selectel" {
domain_name = "123456"
username = "user"
password = "password"
auth_region = "ru-9"
auth_url = "https://cloud.api.selcloud.ru/identity/v3/"
}Here:
domain_name— Selectel account number. You can look it up in control panel in the upper right hand corner;username— username service user with roles member in the access area Account andiam_admin.Can be viewed in control panel: in the top menu click Account → section Service Users (this section is only available to the Account Owner and the user with the role ofiam_admin);password— password of the service user.Can be viewed when creating a user or change it to a new one;auth_region— pool for authorization, for exampleru-9You can create resources in other pools. The list of available pools can be found in the instructions. Availability matrices.
-
Create a project:
resource "selectel_vpc_project_v2" "project_1" {
name = "project"
}View a detailed description of the selectel_vpc_project_v2 resource.
-
Create a service user to access the project and assign it the role of
memberrole in the Project access area:resource "selectel_iam_serviceuser_v1" "serviceuser_1" {
name = "username"
password = "password"
role {
role_name = "member"
scope = "project"
project_id = selectel_vpc_project_v2.project_1.id
}
}Here:
username— username;password— password of the user.The password must be no shorter than eight characters and contain Latin letters of different cases and digits;project_id— Project ID.Can be viewed in control panel: in the top menu click Products and select Cloud Servers → open the projects menu → in the row of the desired project, click .
View a detailed description of the selectel_iam_serviceuser_v1 resource.
-
Optional: if you want to use a mirror, create a separate Terraform CLI configuration file and add a block to it:
provider_installation {
network_mirror {
url = "https://tf-proxy.selectel.ru/mirror/v1/"
include = ["registry.terraform.io/*/*"]
}
direct {
exclude = ["registry.terraform.io/*/*"]
}
}See the CLI Configuration File instructions in HashiCorp's CLI Configuration File documentation for more information on configuring mirrors.
-
Open the CLI.
-
Initialize the Terraform configuration in the directory:
terraform init -
Check that the configuration files have been compiled without errors:
terraform validate -
Format the configuration files:
terraform fmt -
Check the resources that will be created:
terraform plan -
Apply the changes and create the resources:
terraform apply -
Confirm the creation — type yes and press Enter. The created resources will be displayed in the control panel.
-
If there were not enough quotas to create resources, increase the quotas.
2. Connect additional public IP addresses
Use the instructions Connect additional public IP addresses.
3. Get the ID of the ready configuration
data "selectel_dedicated_configuration_v1" "server_config" {
project_id = selectel_vpc_project_v2.project_1.id
deep_filter = <<EOT
{
"name": "EL50-SSD"
}
EOT
}
Here deep_filter is the filter of the list of fixed configurations:
name— configuration name, e.g.EL50-SSD.You can see it in the control panel: in the top menu click on Products and select Dedicated servers.If there are servers created in the project, under Servers click Order a server.If there are no servers in the project, the order page will open automatically.
View a detailed description of the selectel_dedicated_configuration_v1 data source.
View a detailed description of the selectel_vpc_project_v2.project_1 resource.
4. Get location ID
data "selectel_dedicated_location_v1" "server_location" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
name = "SPB-2"
}
}
Here filter is the filter of the list of locations:
name— pool in which a dedicated server will be created, e.g.SPB-2The list of available pools can be found in the instructions Availability matrices.
See the detailed description of the selectel_dedicated_location_v1 data source.
5. Get an OS image
data "selectel_dedicated_os_v1" "server_os" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
name = "Ubuntu"
version = "2404"
configuration_id = data.selectel_dedicated_configuration_v1.server_config.configurations[0].id
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
}
}
Here filter is the filter of the OS list:
name— OS family name, e.g.Ubuntu.You can create a server without an OS by specifyingnoosand do not specify a version.For a list of available OSes, see the instructions in the manual OS images for installation;version— version of the image.You can view the OS image version using the API method List OS configurations.
See the detailed description of the selectel_dedicated_os_v1 data source.
6. Select a public subnet
data "selectel_dedicated_public_subnet_v1" "public_subnets" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
subnet = "203.0.113.0/28"
ip = "203.0.113.12"
}
}
Here:
location_id— The location ID of the allocated public subnet.The location of the public subnet must match the location for server creation;subnet— (Optional) the address of the dedicated public subnet that you ordered in step 2 If you do not specify a public subnet address, any available public subnet for the location will be selected.You can view this in the control panel: from the top menu, click Products → Dedicated Servers → Network → tab Public subnets;ip— (Optional) a free IP address from the dedicated public subnet that you you ordered in step 2.If you do not specify an IP address, any free IP address from the public subnet will be selected.
7. Create a dedicated server
resource "selectel_dedicated_server_v1" "server_1" {
project_id = selectel_vpc_project_v2.project_1.id
configuration_id = data.selectel_dedicated_configuration_v1.server_config.configurations[0].id
location_id = data.selectel_dedicated_location_v1.server_location.locations[0].id
public_subnet_id = data.selectel_dedicated_public_subnet_v1.public_subnets.subnets[0].id
os_id = data.selectel_dedicated_os_v1.server_os.os[0].id
price_plan_name = "1 day"
}
Here price_plan_name is a pricing plan, for example 1 day.You can view the names of the pricing plans using the Price Plans API method, more information about pricing plans in the Dedicated Server Payment Model and Pricing instructions .Available values:
1 day;1 month;3 months;6 months;12 months;12 months - monthly payment.
View the detailed resource description of selectel_dedicated_server_v1.
View a detailed description of the selectel_dedicated_public_subnet_v1 data source.