Manage Terraform resources
Due to high load on Servercore infrastructure, the capacities required to create many resources, such as CPU, RAM, and disk space, are not available in all pools.
You can check availability in the Control panel or on the status page. For more information, see the Resource availability in pools for migration guide.
All resources created with Terraform are billed according to the service billing model. Billing for a resource starts after the resource is created.
The cost of resources created with Terraform does not differ from the cost of resources created using the Control panel.
Resource management approaches
To manage resources, you can use the resource-based approach and the module-based approach.
To get started with Terraform, we recommend using the resource-based approach. This approach is considered easier to learn due to its straightforward syntax, lack of dependencies, and ease of debugging resources.
Resource-based approach
In the resource-based approach, each resource is defined separately in a configuration file. This provides maximum control over each infrastructure component and is suitable for small projects, testing new features, or developing prototypes. The resource-based approach is easy to learn, but it can lead to code duplication as you scale.
Usage examples can be found in the Infrastructure creation examples section.
Module-based approach
In the module-based approach, logically related resources are grouped into modules—independent, reusable infrastructure components. Modules encapsulate logic—such as creating a cloud server or a cloud database cluster. This simplifies maintenance, testing, and collaboration, as well as allows standardizing infrastructure. Suitable for medium and large projects.
Create or modify resources
Changing certain arguments causes the resource to be recreated: the existing resource is deleted, and a new one is created with updated parameters. If there are no available capacities in the pool (for example, CPU, RAM, or disk space), the new resource will not be created, and the existing one will already be deleted by that point.
Capacity availability can be checked in the Control panel or on the status page. For more information, see the Resource availability in pools for migration guide.
To add new resources to the infrastructure or modify existing resources, edit the configuration file. Terraform will automatically determine which resources need to be created, modified, or deleted.
If you made changes via the Control panel, they will not be reflected in Terraform configuration files.
We recommend creating resources sequentially. If you create all resources described in the configuration file at once, an error may occur—Terraform creates resources regardless of the order in which they are listed in the file. For more information on resource creation, see the Create resource dependencies guide in the Terraform documentation.
-
Make sure you have sufficient quotas to create or modify resources. If the quotas are insufficient, increase quotas.
-
Open the CLI.
-
Make sure you are in the directory with the configuration file.
-
Add the resources to be created or edit the resource definitions in the configuration file.
If you are changing arguments that require recreating a resource, you can add a block to the resource definition that prevents deleting the existing resource before creating the new one:
lifecycle {create_before_destroy = true} -
Check that the configuration file contains no errors:
terraform validate -
Format the configuration file:
terraform fmt -
Check which resources will be created or modified:
terraform plan -
Apply the changes and create the resources:
terraform apply -
Confirm the creation — type yes and press Enter. The changes will appear in the Control panel.
openstack_compute_flavor_v2 resource limitations
If you change the vcpus, ram, or disk parameters in the openstack_compute_flavor_v2 resource definition to an invalid value, an error will occur — Terraform will delete the resource and will not be able to create a new one.
To create the new flavor first and then delete the old one, add a block to the openstack_compute_flavor_v2 resource definition:
lifecycle {
create_before_destroy = true
}
See the detailed description of the openstack_compute_flavor_v2 resource.
Delete resources
You can delete specific resources or the entire infrastructure created with Terraform. Resources created by other means (for example, in the Control panel) will not be deleted.
Delete a resource
Delete entire infrastructure
-
Make sure you are in the directory with the configuration file.
-
Remove the resources from the configuration file.
-
Check which resources will be deleted:
terraform plan -
Apply the changes and delete the resources:
terraform apply -
Confirm the deletion — type yes and press Enter. The deleted resources will no longer be displayed in the Control panel.