Deleting a subnet
Alert
Before deleting a subnet, disable all resources connected to it.
You cannot restore a subnet after it is deleted.
- In the management console
, go to the folder where you need to delete a subnet. - In the list of services, select Virtual Private Cloud.
- In the left-hand panel, select
Subnets. - Click
next to the subnet you need and select Delete. - In the window that opens, click Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for deleting a subnet:
yc vpc subnet delete --help
-
Get a list of all subnets in the default folder:
yc vpc subnet list
Result:
+----------------------+-----------------------+------------------------+ | ID | NAME | ... | RANGE | +----------------------+-----------------------+------------------------+ ... | e2l0psbfoloe******** | test-subnet-1 | ... | [192.168.0.0/24] | ... +----------------------+-----------------------+-----+------------------+
-
Select the
ID
orNAME
of the subnet. -
Delete the subnet from the default folder:
yc vpc subnet delete test-subnet-1
If you don't have Terraform, install it and configure the Yandex Cloud provider.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
To delete a subnet created using Terraform:
-
Open the Terraform configuration file and delete the fragment with the subnet description.
Example subnet description in a Terraform configuration
... resource "yandex_vpc_subnet" "lab-subnet-a" { name = "subnet-1" description = "My first subnet" v4_cidr_blocks = ["10.2.0.0/16"] zone = "ru-central1-a" network_id = "${yandex_vpc_network.lab-net.id}" } ...
-
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can verify the changes using the management console
or the CLI command below:yc vpc subnet list
To delete a subnet, use the delete REST API method for the Subnet resource or the SubnetService/Delete gRPC API call and provide the ID of the subnet to be deleted in the subnetId
request parameter.
To get the subnet ID, use the list REST API method for the Subnet resource or the SubnetService/List gRPC API call and provide the folder ID in the folderId
request parameter.
To learn how to find out the folder ID, see Getting the folder ID.
Examples
Deleting a subnet from a particular folder
Delete a subnet from another folder:
yc vpc subnet delete test-subnet-2 --folder-id b1gnbfd11bq5********
Where --folder-id
is the ID of the folder.
yc vpc subnet delete test-subnet-2 --folder-name test-folder
Where --folder-name
is the name of the folder.
You can provide the ID and name not only as positional arguments but also using the --id
and --name
flags:
yc vpc subnet delete --id enpavfmgapum********
yc vpc subnet delete --name test-network-1