Skip to main content

Create a prebuilt dedicated server with a public dedicated IP address via Terraform

We recommend creating resources in order. If you create all resources at once, Terraform will account for dependencies between resources that you specified in the configuration file. If dependencies are not specified, resources will be created in parallel, which may lead to errors. For instance, a resource required for creating another resource might not have been created yet.


  1. Optional: configure the provider.
  2. Connect additional public IP addresses.
  3. Get the ID of the prebuilt configuration.
  4. Get the location ID.
  5. Get the OS image.
  6. Select a public subnet.
  7. Create a dedicated server.

Configuration files

Example file for provider configuration
terraform {
required_providers {
selectel = {
source = "selectel/selectel"
version = "~> 7.1.0"
}
}
}

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 prebuilt dedicated server
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_value = "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
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"
}

1. Optional: configure the provider

  1. Make sure that in the control panel you have created a service user with the member role in the Account access scope and iam.admin.

  2. Create a directory to store configuration files and a separate file with the .tf extension to configure providers.

  3. Add the Selectel provider to the provider configuration file:

    terraform {
    required_providers {
    selectel = {
    source = "selectel/selectel"
    version = "~> 7.1.0"
    }
    }
    }

    Here, version is provider versions. You can find the current version in the Selectel documentation (in the Terraform Registry and on GitHub).

    Learn more about products, services, and features that can be managed using providers in the Selectel and OpenStack Providers guide.

  4. 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/"
    }

    Where:

    • domain_name — Selectel account number. You can find it in the control panel in the upper right corner;
    • username — name of the service user with the member role in the Account scope and the iam.admin role. You can find it in the control panel: in the top menu, click IAM → the Service Users section (the section is available only to the Account Owner and a user with the iam.admin role);
    • password — service user password. You can view it when creating the user or change it to a new one;
    • auth_regionpool for authorization in the ru-9 format; do not use pools in the SPB-2 format. The pool for authorization may differ from the pool where you create resources. You can view the list of available pools in the Product availability by location.
  5. Create a project:

    resource "selectel_vpc_project_v2" "project_1" {
    name = "project"
    }

    See the detailed description of the selectel_vpc_project_v2 resource.

  6. Optional: if you want to use a mirror, create a separate Terraform CLI configuration file and add the following block to it:

    provider_installation {
    network_mirror {
    url = "https://tf-proxy.selectel.ru/mirror/v1/"
    include = ["registry.terraform.io/*/*"]
    }
    direct {
    exclude = ["registry.terraform.io/*/*"]
    }
    }

    Read more about mirror settings in the CLI Configuration File guide in the HashiCorp documentation.

  7. Open the CLI.

  8. Initialize the Terraform configuration in the directory:

    terraform init
  9. Check that the configuration files are free of errors:

    terraform validate
  10. Format the configuration files:

    terraform fmt
  11. Check which resources will be created:

    terraform plan
  12. Apply the changes and create the resources:

    terraform apply
  13. Confirm creation — enter yes and press Enter. The created resources will be displayed in the control panel.

  14. If there are insufficient quotas to create the resources, increase the quotas.

2. Connect additional public IP addresses

Use the Connect additional public IP addresses instruction.

3. Get the ID of the prebuilt 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 a filter for the list of fixed configurations:

  • name — configuration name, for example, EL50-SSD. You can view it in the control panel: in the top menu, click Products and select Dedicated Servers. If there are servers created in the project, in the Servers section, click Order server. If there are no servers in the project, the order page opens automatically.

See the detailed description of the selectel_dedicated_configuration_v1 data source.

See the detailed description of the selectel_vpc_project_v2.project_1 resource.

4. Get the 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 a filter for the list of locations:

See the detailed description of the selectel_dedicated_location_v1 data source.

5. Get the OS image

data "selectel_dedicated_os_v1" "server_os" {
project_id = selectel_vpc_project_v2.project_1.id
filter {
name = "Ubuntu"
version_value = "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 a filter for the list of OSs:

  • name — OS family name, for example, Ubuntu. You can create a server without an OS; to do this, specify noos and do not specify the version. You can view the list of available OSs in the instructions on OS images for installation;
  • version_value — image version. 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"
}
}

Where:

  • location_id — ID of the dedicated public subnet location. The location of the public subnet must match the location for creating the server;
  • subnet — (Optional) 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 it in the control panel: in the top menu, click ProductsDedicated ServersNetworkPublic Subnets tab;
  • ip — (Optional) available IP address from the dedicated public subnet that you ordered in Step 2. If you do not specify an IP address, any available 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"
}

Where price_plan_name — billing plan, for example, 1 day. You can view billing plan names using the Price Plans API method; for details on billing plans, see the instructions on Dedicated server billing model and prices. Available values:

  • 1 day;
  • 1 month;
  • 3 months;
  • 6 months;
  • 12 months;
  • 12 months • monthly payment.

See the detailed description of the selectel_dedicated_server_v1 resource.

See the detailed description of the selectel_dedicated_public_subnet_v1 data source.