---
title: "Install an OS via autoinstallation using Terraform"
sidebar_label: "Install an OS via autoinstallation"
description: "How to install an OS via autoinstallation"
sidebar_position: 3
---

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'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'

# Install an OS via autoinstallation using Terraform

:::danger

Automatic OS installation will delete data on all disks.<br />We recommend that you save your data or create a backup before installing the OS.

:::

You can only install an OS via Terraform using automatic installation. [Automatic OS installation](/dedicated/manage/autoinstall-os/) is only available for pre-configured servers without upgrades. On a [pre-configured server with an upgrade](/dedicated/order/change-server-configuration/#prebuilt-server-upgrade), you can [manually install an OS from a custom image](/dedicated/manage/install-os-from-image/).

You can install an OS on the server that differs from the current one, or reinstall the current OS.

<Tabs queryString="install-os">
  <TabItem value="install-another-os" default>
    <TabItemLabel>
      Install a new OS
    </TabItemLabel>

    1. Open the CLI.

    2. Make sure you are in the directory with the configuration file.

    3. Specify the required OS in the data source `selectel_dedicated_os_v1`:

       ```hcl
       data "selectel_dedicated_os_v1" "server_os" {
           project_id         = selectel_vpc_project_v2.project_1.id
           filter {
               name             = "<os_image_name>"
               version_name     = "<version_name>"
               configuration_id = data.selectel_dedicated_configuration_v1.server_config.configurations[0].id
               location_id      = data.selectel_dedicated_location_v1.server_location.locations[0].id
           }
       }
       ```

       Specify:

       * `<os_image_name>` — the OS family name, for example `Ubuntu`;
       * `<version_name>` — OS version, for example `22.04`. You can check the OS version in the [Standard OS images](/dedicated/manage/os-images/#standart-os-images) table or using the [List OS configurations](/api/dedicated/#tag/Boot-Manager/operation/get_os_template_list_new_view) method via the [Dedicated Servers API](/api/dedicated/).

    4. Check that the configuration file is free of errors:

       ```sh
       terraform validate
       ```

    5. Format the configuration file:

       ```sh
       terraform fmt
       ```

    6. Check the changes:

       ```sh
       terraform plan
       ```

    7. Apply the changes:

       ```sh
       terraform apply
       ```

    8. Confirm the creation — enter **yes** and press **Enter**. The changes will be displayed in the control panel.

    9. Wait for the OS installation to finish.
  </TabItem>

  <TabItem value="reinstall-os">
    <TabItemLabel>
      Reinstall the OS
    </TabItemLabel>

    1. Open the CLI.

    2. Make sure you are in the directory with the configuration file.

    3. In the configuration file, add the `selectel_dedicated_server_v1` parameter `force_update_additional_params` with the value `true`:

       ```hcl
       resource "selectel_dedicated_server_v1" "server_1" {
           project_id                     = selectel_vpc_project_v2.project_1.id
           configuration_id               = data.selectel_configuration_v1.server_config.configurations[0].id
           location_id                    = data.selectel_location_v1.server_location.locations[0].id
           price_plan_name                = "1 day"
           public_subnet_id               = data.selectel_public_subnet_v1.subnets.subnets[0].id
           os_id                          = data.selectel_os_v1.server_os.os[0].id
           os_host_name                   = "Turing"
           os_password                    = "Passw0rd!"
           force_update_additional_params = true
       }
       ```

    4. Change the value of any additional parameter for `os_id`: `os_password`, `user_data`, `ssh_key`, `ssh_key_name`, `partitions_config`, `os_host_name`:

       ```hcl
       resource "selectel_dedicated_server_v1" "server_1" {
           project_id                     = selectel_vpc_project_v2.project_1.id
           configuration_id               = data.selectel_configuration_v1.server_config.configurations[0].id
           location_id                    = data.selectel_location_v1.server_location.locations[0].id
           price_plan_name                = "1 day"
           public_subnet_id               = data.selectel_public_subnet_v1.subnets.subnets[0].id
           os_id                          = data.selectel_os_v1.server_os.os[0].id
           force_update_additional_params = true
           os_host_name                   = "new_Turing"            
           os_password                    = "new_Passw0rd!"
       }
       ```

       Here, `os_host_name`, `os_password` are additional OS parameters. View the detailed description of the resource [selectel\_dedicated\_server\_v1](/terraform/selectel-provider-reference/resources/dedicated_server_v1/).

    5. Check that the configuration file is free of errors:

       ```sh
       terraform validate
       ```

    6. Format the configuration file:

       ```sh
       terraform fmt
       ```

    7. Check the changes:

       ```sh
       terraform plan
       ```

    8. Apply the changes:

       ```sh
       terraform apply
       ```

    9. Confirm the creation — enter **yes** and press **Enter**. The changes will be displayed in the control panel.

    10. Wait for the OS installation to finish.

    11. In the configuration file, remove the `force_update_additional_params` parameter that you added in step 3 from the `selectel_dedicated_server_v1` resource.

    12. Check that the configuration file is free of errors:

        ```sh
        terraform validate
        ```

    13. Format the configuration file:

        ```sh
        terraform fmt
        ```

    14. Check the changes:

        ```sh
        terraform plan
        ```

    15. Apply the changes:

        ```sh
        terraform apply
        ```
  </TabItem>
</Tabs>
