---
title: "Create a prebuilt dedicated server with a public dedicated IP address via Terraform"
sidebar_label: "Create a prebuilt dedicated server with a public dedicated IP address"
description: "How to create a prebuilt dedicated server with a public dedicated IP address"
sidebar_position: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import CreateResourcesAlert from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/create-resources-alert.mdx'
import ConfigureSelectelProviders from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/configure-selectel-providers.mdx'

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

<CreateResourcesAlert />

<br />

1. Optional: [configure the provider](#configure-provider).
2. [Connect additional public IP addresses](#add-additional-ips).
3. [Get the ID of the prebuilt configuration](#get-id-prebuilt-server-configuration).
4. [Get the location ID](#get-location-id).
5. [Get the OS image](#get-image).
6. [Select a public subnet](#select-public-subnet).
7. [Create a dedicated server](#create-dedicated-server).

## Configuration files \{#config}

<details>
  <summary>Example file for provider configuration</summary>

  ```hcl
  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/"
  }
  ```
</details>

<details>
  <summary>Example file for creating a prebuilt dedicated server</summary>

  ```hcl
  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"
  }
  ```
</details>

## 1. Optional: configure the provider \{#configure-provider}

<ConfigureSelectelProviders />

## 2. Connect additional public IP addresses \{#add-additional-ips}

Use the [Connect additional public IP addresses](/dedicated/networks/public-networks-and-subnets/#add-additional-ips) instruction.

## 3. Get the ID of the prebuilt configuration \{#get-id-prebuilt-server-configuration}

```hcl
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](/terraform/selectel-provider-reference/data-sources/dedicated_configuration_v1/) data source.

See the detailed description of the [selectel\_vpc\_project\_v2.project\_1](/terraform/selectel-provider-reference/resources/vpc_project_v2) resource.

## 4. Get the location ID \{#get-location-id}

```hcl
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:

* `name` — [pool](/infrastructure/locations/#pool) where the dedicated server will be created, for example, `SPB-2`. You can view the list of available pools in the instructions on [Product availability by location](/infrastructure/product-availability-by-location/).

See the detailed description of the [selectel\_dedicated\_location\_v1](/terraform/selectel-provider-reference/data-sources/dedicated_location_v1/) data source.

## 5. Get the OS image \{#get-image}

```hcl
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](/dedicated/manage/os-images/);
* `version_value` — image version. You can view the OS image version using the API method [List OS configurations](https://docs.selectel.ru/api/dedicated/#tag/Boot-Manager/operation/get_os_template_list_new_view).

See the detailed description of the [selectel\_dedicated\_os\_v1](/terraform/selectel-provider-reference/data-sources/dedicated_os_v1/) data source.

## 6. Select a public subnet \{#select-public-subnet}

```hcl
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](#add-additional-ips). 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](https://my.selectel.ru/servers/network/subnets): in the top menu, click **Products** → **Dedicated Servers** → **Network** → **Public Subnets tab**;
* `ip` — (Optional) available IP address from the dedicated public subnet that you [ordered in Step 2](#add-additional-ips). If you do not specify an IP address, any available IP address from the public subnet will be selected.

## 7. Create a dedicated server \{#create-dedicated-server}

```hcl
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/dedicated/#tag/Price-Plans) API method; for details on billing plans, see the instructions on [Dedicated server billing model and prices](/dedicated/about/payment/#billing-options). 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](/terraform/selectel-provider-reference/resources/dedicated_server_v1/) resource.

See the detailed description of the [selectel\_dedicated\_public\_subnet\_v1](/terraform/selectel-provider-reference/data-sources/dedicated_public_subnet_v1/) data source.
