Deleting a NAT gateway
If you no longer need a NAT gateway, you can delete it. Before deleting a NAT gateway, detach it from all route tables that use it.
Detaching a NAT gateway from a route table
- In the management console
, go to the folder where you need to detach a NAT gateway. - In the list of services, select Virtual Private Cloud.
- In the left-hand panel, select
Routing tables. - In the list that opens, find the route table with the NAT gateway listed in its Static routes column.
- In the line with the appropriate table, click
and select Edit. - In the window that opens, click
in the line with the NAT gateway name. - Click Save.
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.
To detach a NAT gateway from a route table:
-
View the description of the CLI command for editing a route table:
yc vpc route-table update --help
-
Get the name or ID of the route table the NAT gateway is attached to:
yc vpc route-table list
Result:
+----------------------+----------------------+-------------+----------------------+ | ID | NAME | DESCRIPTION | NETWORK-ID | +----------------------+----------------------+-------------+----------------------+ | enpcaaqahk3c******** | test-table | | enptgj64mv2r******** | +----------------------+----------------------+-------------+----------------------+
-
Detach the NAT gateway:
yc vpc route-table update <route_table_name_or_ID> --clear-routes
Use either the
--id
or--name
parameter.
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 detach a NAT gateway from a route table created using Terraform:
-
Open the Terraform configuration file and find the section with the description of the route table the NAT gateway is attached to:
Example of a table description in the Terraform configuration
... resource "yandex_vpc_route_table" "routetable" { folder_id = "<user_folder_ID>" name = "<route_table_name>" network_id = "<network_ID>" static_route { destination_prefix = "0.0.0.0/0" gateway_id = <gateway_ID> } } ...
-
Delete the
static_route
object. -
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 check the update using the management console
or this CLI command:yc vpc route-table get <route_table_name_or_ID>
Use either the
--id
or--name
parameter.
To detach a NAT gateway from a route table, delete the static route with that NAT gateway from the route table. To do this, use the update REST API method for the RouteTable resource or the RouteTableService/Update gRPC API call. In your request, provide a list of static routes without the route you want to delete under:
staticRoutes
: For REST APIstatic_routes
: For gRPC API
If the list contained a single static route, provide an empty list.
To get a list of static routes, use the get REST API method for the RouteTable resource or the RouteTableService/Get gRPC API call. In your request, provide the route table ID in this parameter:
routeTableId
: For REST APIroute_table_id
: For gRPC API
Warning
This API method overrides all parameters of the object being modified that were not explicitly passed in the request to the default values. To avoid this, list the settings you want to change in the updateMask
parameter (one line separated by commas).
Deleting a NAT gateway
Warning
Before deleting a NAT gateway, detach it from all route tables it is attached to.
To delete a NAT gateway:
- In the management console
, go to the folder where you need to delete a NAT gateway. - In the list of services, select Virtual Private Cloud.
- In the left-hand panel, select Gateways.
- Click
in the line with the appropriate NAT gateway name 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.
To delete a route table:
-
View the description of the CLI command for deleting a NAT gateway:
yc vpc gateway delete --help
-
Get the name or ID of the NAT gateway to delete:
yc vpc gateway list
Result:
+----------------------+-----------+-------------+ | ID | NAME | DESCRIPTION | +----------------------+-----------+-------------+ | enpkq171u4gb******** | gateway-1 | | +----------------------+-----------+-------------+
-
Delete the NAT gateway:
yc vpc gateway delete <gateway_name_or_ID>
Use either the
--id
or--name
parameter.
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 NAT gateway created using Terraform:
-
Open the Terraform configuration file and delete the section with the NAT gateway description.
Example of a NAT gateway description in the Terraform configuration
... resource "yandex_vpc_gateway" "natgateway" { folder_id = "<folder_ID>" name = "<gateway_name>" shared_egress_gateway {} } ...
-
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 check the update using the management console
or this CLI command:yc vpc gateway list
To delete a NAT gateway, use the delete REST API method for the Gateway resource or the GatewayService/Delete gRPC API call. In your request, provide the ID of the NAT gateway you want to delete in this parameter:
gatewayId
: For REST APIgateway_id
: For gRPC API
To get the NAT gateway ID, use the list REST API method for the Gateway resource or the GatewayService/List gRPC API call. In your request, provide the folder ID in this parameter:
folderId
: For REST APIfolder_id
: For gRPC API