---
title: "Manage Terraform resources"
sidebar_label: "Manage resources"
sidebar_position: 4
description: "How to create, edit, or delete Terraform resources"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import {CustomTable} from '@selectel/docux/components'

# Manage Terraform resources

All resources created using Terraform are billed according to the [service payment model](/balance-and-payments/payment-models/). Billing for a resource starts after [creating the resource](#create-or-edit-resources).

The cost of resources created using Terraform is the same as the cost of resources created using the [control panel](https://my.selectel.ru/).

## Approaches to resource management \{#approaches-to-resources-management}

To manage resources, you can use the [resource-based approach](#resource-approach) and the [modular approach](#module-approach).

For getting started with Terraform, we recommend using the resource-based approach. This approach is considered easier to learn due to its clear syntax, lack of dependencies, and ease of resource debugging.

### Resource-based approach \{#resource-approach}

In the resource-based approach, every resource is described individually in a configuration file. This provides maximum control over every infrastructure component and is suitable for small projects, testing new functionality, or developing prototypes. The resource-based approach is easy to learn but can lead to code duplication when scaling.

Usage examples can be found in the [Infrastructure creation examples](/terraform/examples/) section.

### Modular approach \{#module-approach}

In the modular approach, logically related resources are combined into modules — independent, reusable infrastructure components. Modules encapsulate logic, for example, creating a cloud server or a cloud database cluster. This simplifies maintenance, testing, and collaboration, and also allows you to standardize infrastructure. It is suitable for medium and large projects.

Module examples can be found in the [Selectel repository](https://github.com/selectel/selectel-infra-examples) on GitHub.

## Create or edit resources \{#create-or-edit-resources}

To add new resources to your infrastructure or edit existing resources, you need to edit the configuration file. Terraform will automatically determine which resources need to be created, updated, or deleted.

If you make changes via the control panel, they will not be reflected in the Terraform configuration files.

We recommend creating resources in order. If you create all resources described in the configuration file at once, an error may occur — Terraform creates resources independently of the order in which they are listed in the file. Read more about creating resources in the [Create resource dependencies](https://developer.hashicorp.com/terraform/tutorials/configuration-language/dependencies) guide in the Terraform documentation.

1. Open the CLI.

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

3. Add the resources you want to create or edit the resource description in the configuration file.

4. Check that the configuration file is valid:

   ```sh
   terraform validate
   ```

5. Format the configuration file:

   ```sh
   terraform fmt
   ```

6. Check which resources will be created:

   ```sh
   terraform plan
   ```

7. Apply the changes and create the resources:

   ```sh
   terraform apply
   ```

8. Confirm creation — enter **yes** and press **Enter**. Changes will be reflected in the Control Panel.

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

### Limitations of the openstack\_compute\_flavor\_v2 resource \{#openstack-compute-flavor-v2-limitations}

If you change the `vcpus`, `ram`, or `disk` parameters in the openstack\_compute\_flavor\_v2 resource description to an invalid value, an error will occur — Terraform will delete the resource and fail to create a new one.

To create a new flavor first and then delete the old one, add a block to the openstack\_compute\_flavor\_v2 resource description:

```hcl
lifecycle {
    create_before_destroy = true
  }
```

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

## Delete resources \{#delete-resources}

You can delete specific resources or the entire infrastructure that was created using Terraform. Resources created by other means (for example, in the control panel) will not be deleted.

<Tabs>
  <TabItem value="deleteresource" default>
    <TabItemLabel>
      Delete a resource
    </TabItemLabel>

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

    2. Remove the resources from the configuration file.

    3. Check which resources will be deleted:

       ```sh
       terraform plan
       ```

    4. Apply the changes and delete the resources:

       ```sh
       terraform apply
       ```

    5. Confirm deletion — enter **yes** and press **Enter**. Deleted resources will stop appearing in the Control Panel.
  </TabItem>

  <TabItem value="deleteall">
    <TabItemLabel>
      Delete the entire infrastructure
    </TabItemLabel>

    :::danger

    When deleting using this method, all resources described in all files within the directory will be deleted.

    :::

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

    2. Delete all resources:

       ```sh
       terraform destroy
       ```

    3. Confirm deletion — enter **yes** and press **Enter**. Deleted resources will stop appearing in the Control Panel.
  </TabItem>
</Tabs>

<Formbricks />
