---
title: "Create a fixed configuration cloud server with dedicated cores and a bootable network volume via Terraform"
sidebar_label: "Create a fixed configuration server with dedicated cores and a bootable network volume"
sidebar_position: 5
description: "How to create a Standard lineup fixed configuration cloud server with dedicated cores and a bootable network volume"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import CreateRouter from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-networks/create-router.mdx'
import CreateNetworks from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-networks/create-networks.mdx'
import AddPublicSsh from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/add-public-ssh-key.mdx'
import CreatePort from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/create-port.mdx'
import GetImage from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-servers/get-image.mdx'
import CreateResourcesAlert from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/common/create-resources-alert.mdx'
import CreatePublicIp from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-networks/create-public-ip.mdx'
import AssociateIp from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-networks/associate-ip.mdx'
import GetIp from '@site/i18n/en/docusaurus-plugin-content-docs-terraform/current/_partials/cloud-networks/get-ip.mdx'
import CopyIcon from '@selectel/docux/icons/copy'

# Create a fixed configuration cloud server with dedicated cores and a bootable network volume via Terraform

<CreateResourcesAlert />

<br />

1. Optional: [configure providers](#configure-providers).

2. [Add a public SSH key](#create-ssh-keypair).

3. [Create a private network and a subnet](#create-networks).

4. [Create a cloud router connected to the internet](#create-router).

5. [Create a port for the cloud server](#create-port).

6. [Get an image](#get-image).

7. [Create a bootable network volume](#create-boot-volume).

8. [Create a cloud server](#create-server).

9. [Create a public IP address](#create-public-ip).

10. [Associate the cloud server’s public and private IP addresses](#associate-ip).

11. [Get the cloud server IP address](#get-ip).

## Configuration files \{#config}

<details>
  <summary>Example file for configuring providers</summary>

  ```hcl
  terraform {
    required_providers {
      selectel  = {
        source  = "selectel/selectel"
        version = "~> 6.0"
      }
      openstack = {
        source  = "terraform-provider-openstack/openstack"
        version = "2.1.0"
      }
    }
  }

  provider "selectel" {
    domain_name = "123456"
    username    = "user"
    password    = "password"
    auth_region = "ru-7"
    auth_url    = "https://cloud.api.selcloud.ru/identity/v3/"
  }

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

  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 
    }
  }

  provider "openstack" {
    auth_url    = "https://cloud.api.selcloud.ru/identity/v3"
    domain_name = "123456"
    tenant_id   = selectel_vpc_project_v2.project_1.id
    user_name   = selectel_iam_serviceuser_v1.serviceuser_1.name
    password    = selectel_iam_serviceuser_v1.serviceuser_1.password
    region      = "ru-7"
  }
  ```
</details>

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

  ```hcl

  resource "selectel_vpc_keypair_v2" "keypair_1" {
      name       = "keypair"
      public_key = file("~/.ssh/id_rsa.pub")
      user_id    = selectel_iam_serviceuser_v1.serviceuser_1.id
  }

  resource "openstack_networking_network_v2" "network_1" {
      name           = "private-network"
      admin_state_up = "true"
  }

  resource "openstack_networking_subnet_v2" "subnet_1" {
      network_id = openstack_networking_network_v2.network_1.id
      cidr       = "192.168.199.0/24"
  }

  data "openstack_networking_network_v2" "external_network_1" {
      external = true
  }

  resource "openstack_networking_router_v2" "router_1" {
      name                = "router"
      external_network_id = data.openstack_networking_network_v2.external_network_1.id
  }

  resource "openstack_networking_router_interface_v2" "router_interface_1" {
      router_id = openstack_networking_router_v2.router_1.id
      subnet_id = openstack_networking_subnet_v2.subnet_1.id
  }

  resource "openstack_networking_port_v2" "port_1" {
      name       = "port"
      network_id = openstack_networking_network_v2.network_1.id

      fixed_ip {
        subnet_id = openstack_networking_subnet_v2.subnet_1.id
      }
  }

  data "openstack_images_image_v2" "image_1" {
      name        = "Ubuntu 20.04 LTS 64-bit"
      most_recent = true
      visibility  = "public"
  }

  resource "openstack_blockstorage_volume_v3" "volume_1" {
      name                 = "boot-volume-for-server"
      size                 = "5"
      image_id             = data.openstack_images_image_v2.image_1.id
      volume_type          = "fast.ru-7b"
      availability_zone    = "ru-7b"
      enable_online_resize = true

      lifecycle {
        ignore_changes = [image_id]
      }

  }

  resource "openstack_compute_instance_v2" "server_1" {
    name              = "server"
    flavor_id         = "1063"
    key_pair          = selectel_vpc_keypair_v2.keypair_1.name
    availability_zone = "ru-7b"

    network {
      port = openstack_networking_port_v2.port_1.id
    }

    lifecycle {
      ignore_changes = [image_id]
    }

    block_device {
      uuid             = openstack_blockstorage_volume_v3.volume_1.id
      source_type      = "volume"
      destination_type = "volume"
      boot_index       = 0
    }

    vendor_options {
      ignore_resize_confirmation = true
    }
  }

  resource "openstack_networking_floatingip_v2" "floatingip_1" {
      pool = "external-network"
  }

  resource "openstack_networking_floatingip_associate_v2" "association_1" {
      port_id     = openstack_networking_port_v2.port_1.id
      floating_ip = openstack_networking_floatingip_v2.floatingip_1.address
  }

  output "public_ip_address" {
      value = openstack_networking_floatingip_v2.floatingip_1.fixed_ip
  }

  ```
</details>

## 1. Optional: configure providers \{#configure-providers}

If you have already configured Selectel and OpenStack providers, skip this step.

1. Ensure that you have [created a service user](/terraform/configure-terraform-environment/#add-service-user) with the [`member`](/access-control/role-reference/#member) role in the Account access scope and the [`iam.admin`](/access-control/role-reference/#iam-admin) role.

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

3. Add the Selectel and OpenStack providers to the provider configuration file:

   ```hcl
   terraform {
     required_providers {
       selectel  = {
         source  = "selectel/selectel"
         version = "~> 6.0"
       }
       openstack = {
         source  = "terraform-provider-openstack/openstack"
         version = "2.1.0"
       }
     }
   }
   ```

   Where `version` is the provider version.  The current version can be found in the Selectel documentation (in [Terraform Registry](https://registry.terraform.io/providers/selectel/selectel/latest/docs) and [GitHub](https://github.com/selectel/terraform-provider-selectel)) and OpenStack (in [Terraform Registry](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest) and [GitHub](https://github.com/terraform-provider-openstack/terraform-provider-openstack)).

   For more information about products, services, and features that can be managed using providers, see the [Selectel and OpenStack Providers](/terraform/providers/) guide.

4. Initialize the Selectel provider:

   ```hcl
   provider "selectel" {
     domain_name = "123456"
     username    = "user"
     password    = "password"
     auth_region = "ru-7"
     auth_url    = "https://cloud.api.selcloud.ru/identity/v3/"
   }
   ```

   Where:

   * `domain_name` — Selectel account ID. It can be found in the [control panel](https://my.selectel.ru/) in the top-right corner;
   * `username` — the name of the [service user](/terraform/configure-terraform-environment/#add-service-user) with the [`member`](/access-control/role-reference/#member) role in the Account access scope and the [`iam.admin`](/access-control/role-reference/#iam-admin) role. You can view it in the [control panel](https://my.selectel.ru/iam/service-users): in the top menu, click **IAM** → **Service users** section (available only to the account owner and users with the `iam.admin` role);
   * `password` — service user password. You can view it when creating the user or [change it to a new one](/access-control/manage/edit-user-data-or-role/);
   * `auth_region` — the [pool](/infrastructure/locations/#pool) for authorization in the `ru-7` format; do not use pools in the `SPB-2` format. The authorization pool may differ from the pool where you create your resources. The list of available pools can be viewed in the [Availability Matrix](/infrastructure/product-availability-by-location/) instructions.

5. Create a project:

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

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

6. Create a service user for project access and assign them the [`member`](/access-control/role-reference/#member) role in the Project access scope:

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

   Where:

   * `username` — user name;
   * `password` — user password. The password must be at least eight characters long and contain uppercase and lowercase Latin letters and digits;
   * `project_id` — Project ID. Can be viewed in the [control panel](https://my.selectel.ru/vpc/): in the top menu, click **Products** and select **Cloud Servers** → open the project menu → in the row of the required project, click .<CopyIcon />

   See the detailed resource description [selectel\_iam\_serviceuser\_v1](/terraform/selectel-provider-reference/resources/iam_serviceuser_v1/).

7. Initialize the OpenStack provider:

   ```hcl
   provider "openstack" {
     auth_url    = "https://cloud.api.selcloud.ru/identity/v3"
     domain_name = "123456"
     tenant_id   = selectel_vpc_project_v2.project_1.id
     user_name   = selectel_iam_serviceuser_v1.serviceuser_1.name
     password    = selectel_iam_serviceuser_v1.serviceuser_1.password
     region      = "ru-7"
   }
   ```

   Where:

   * `domain_name` — Selectel account number. Can be viewed in the [control panel](https://my.selectel.ru/) in the top-right corner;
   * `region` — [pool](/infrastructure/locations/#pool), for example `ru-7`. All resources will be created in this pool. The list of available pools can be found in the [Availability Matrix](/infrastructure/product-availability-by-location/).

8. If you are [creating resources](/terraform/manage-resources/) simultaneously with provider configuration, add the `depends_on` argument for OpenStack resources. For example, for the openstack\_networking\_network\_v2 resource:

   ```hcl
   resource "openstack_networking_network_v2" "network_1" {
     name           = "private-network"
     admin_state_up = "true"

     depends_on = [
       selectel_vpc_project_v2.project_1,
       selectel_iam_serviceuser_v1.serviceuser_1
     ]
   }
   ```

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

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

   Learn more about mirror settings in the [CLI Configuration File](https://developer.hashicorp.com/terraform/cli/config/config-file) instructions in the HashiCorp documentation.

10. Open the CLI.

11. Initialize the Terraform configuration in the directory:

    ```bash
    terraform init
    ```

12. Verify that the configuration files are syntactically correct:

    ```bash
    terraform validate
    ```

13. Format the configuration files:

    ```bash
    terraform fmt
    ```

14. Check which resources will be created:

    ```bash
    terraform plan
    ```

15. Apply the changes and create the resources:

    ```bash
    terraform apply
    ```

16. Confirm the creation — enter **yes** and press **Enter**. The created resources will appear in the control panel.

17. If you do not have enough quotas to create resources, [increase the quotas](/access-control/projects/quotas/#change-quotas).

## 2. Create an SSH key pair \{#create-ssh-keypair}

<AddPublicSsh />

## 3. Create a private network and a subnet \{#create-networks}

<CreateNetworks />

## 4. Create a cloud router connected to the internet \{#create-router}

<CreateRouter />

## 5. Create a port for the cloud server \{#create-port}

<CreatePort />

## 6. Get an image \{#get-image}

<GetImage />

## 7. Create a bootable network volume \{#create-boot-volume}

```hcl
resource "openstack_blockstorage_volume_v3" "volume_1" {
    name                 = "boot-volume-for-server"
    size                 = "5"
    image_id             = data.openstack_images_image_v2.image_1.id
    volume_type          = "fast.ru-7b"
    availability_zone    = "ru-7b"
    enable_online_resize = true

    lifecycle {
      ignore_changes = [image_id]
    }

}
```

## 8. Create a cloud server \{#create-server}

```hcl

resource "openstack_compute_instance_v2" "server_1" {
  name              = "server"
  flavor_id         = "1063"
  key_pair          = selectel_vpc_keypair_v2.keypair_1.name
  availability_zone = "ru-7b"

  network {
    port = openstack_networking_port_v2.port_1.id
  }

  lifecycle {
    ignore_changes = [image_id]
  }

  block_device {
    uuid             = openstack_blockstorage_volume_v3.volume_1.id
    source_type      = "volume"
    destination_type = "volume"
    boot_index       = 0
  }

  vendor_options {
    ignore_resize_confirmation = true
  }
}

```

Where:

* `availability_zone` — [pool segment](/infrastructure/locations/#pool) where the cloud server will be created, for example `ru-7b`. [Cloud servers with dedicated cores](/cloud-servers/about/dedicated-cores/) are only available in pool segments ru-3b, ru-7a, and ru-7b.
* `flavor_id` — ID of the flavor with dedicated cores. Flavors correspond to [cloud server configurations](/cloud-servers/create/configurations/) and define the number of vCPU, RAM and local disk size. For example, `1063` — the flavor of a fixed configuration of the Standard line with 12 vCPU and 48 GB RAM for creating a cloud server with dedicated cores. Flavors with dedicated core support are available in the Standard and HighFreq lines. The list of available flavors can be found in the [List of fixed configuration flavors in all pools](/cloud-servers/create/configurations/#server-flavors-full-list) subsection of the [Cloud Server Configurations](/cloud-servers/create/configurations/).

See the detailed resource description [openstack\_compute\_instance\_v2](/terraform/openstack-provider-reference/compute-nova/resources/openstack_compute_instance_v2/).

## 9. Create a public IP address \{#create-public-ip}

<CreatePublicIp />

## 10. Associate the cloud server’s public and private IP addresses \{#associate-ip}

<AssociateIp />

## 11. Get the cloud server’s IP address \{#get-ip}

<GetIp />

<Formbricks />
