---
title: "Create a prebuilt dedicated server using Terraform"
sidebar_label: "Create a prebuilt dedicated server"
description: "How to create a prebuilt dedicated server"
sidebar_position: 1
---

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 using Terraform

<CreateResourcesAlert />

To assign a public dedicated IP address to a server, use the instructions [Create a prebuilt dedicated server with a public dedicated IP address](/terraform/examples/dedicated/create-prebuilt-dedicated-servers-with-public-subnet/).

<br />

1. Optional: [configure the provider](#configure-provider).
2. [Get the ID of the prebuilt configuration](#get-id-prebuilt-server-configuration).
3. [Get the location ID](#get-location-id).
4. [Get the OS image](#get-image).
5. [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    
    }
  }

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

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

<ConfigureSelectelProviders />

## 2. 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 prebuilt configurations:

* `name` — the name of the prebuilt configuration, for example `EL50-SSD`.Can be viewed in the Control Panel: in the top menu, click **Products** and select **Dedicated Servers**.If there are created servers in the project, in the **Servers** section click **Order server**.If there are no servers in the project, the order page will open automatically.

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

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

## 3. 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) in which the dedicated server will be created, for example `SPB-2`. The list of available pools can be viewed in the [Availability Matrix](/infrastructure/product-availability-by-location/).

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

## 4. 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 a version. The list of available OSs can be viewed in the [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 data source [selectel\_dedicated\_os\_v1](/terraform/selectel-provider-reference/data-sources/dedicated_os_v1/).

## 5. 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
  os_id            = data.selectel_dedicated_os_v1.server_os.os[0].id
  price_plan_name  = "1 day"
}
```

Here `price_plan_name` — price plan, for example `1 day`.Price plan names can be viewed using the API method [Price Plans](/api/dedicated/#tag/Price-Plans), more details about price plans in the [Payment model and prices of a dedicated server](/dedicated/about/payment/#billing-options) instruction.Available values:

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

See the detailed description of the resource [selectel\_dedicated\_server\_v1](/terraform/selectel-provider-reference/resources/dedicated_server_v1/).
