Deletes a virtual private cloud (VPC).

Usage notes

When you call this operation, take note of the following limits:

  • Before you delete a VPC, make sure that all resources deployed in the VPC are released or removed, such as vSwitches, instances, and high-availability virtual IP addresses (HAVIPs).
  • You can delete only a VPC that is in the Available state.
  • DeleteVpc is an asynchronous operation. After you send a request, the system returns a request ID and runs the task in the background. You can call the DescribeVpcAttribute operation to query the status of a VPC:
    • If the VPC is in the Deleting state, the VPC is being deleted.
    • If you cannot query the VPC, the VPC is deleted.
  • You cannot repeatedly call the DeleteVpc operation to delete a VPC within the specified period of time.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes DeleteVpc

The operation that you want to perform. Set the value to DeleteVpc.

VpcId String Yes vpc-bp1m7v25emi1h5mtc****

The ID of the VPC that you want to delete.

RegionId String No cn-hangzhou

The ID of the region where the VPC is deployed.

You can call the DescribeRegions operation to query the most recent region list.

ForceDelete Boolean No false

Specifies whether to forcefully delete the VPC. Valid values:

  • true: yes
  • false (default): no

You can forcefully delete a VPC in the following scenarios:

  • Only an IPv4 gateway and routes that point to the IPv4 gateway exist in the VPC.
  • Only an IPv6 gateway and routes that point to the IPv6 gateway exist in the VPC.
DryRun Boolean No false

Specifies whether to perform a dry run. Valid values:

  • true: performs a dry run. The system checks the required parameters, request syntax, and limits. If the request fails the dry run, an error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.
  • false (default): performs a dry run and sends the request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.

Response parameters

Parameter Type Example Description
RequestId String 0ED8D006-F706-4D23-88ED-E11ED28DCAC0

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?Action=DeleteVpc
&VpcId=vpc-bp1m7v25emi1h5mtc****
&RegionId=cn-hangzhou
&ForceDelete=false
&DryRun=false
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<DeleteVpcResponse>
    <RequestId>0ED8D006-F706-4D23-88ED-E11ED28DCAC0</RequestId>
</DeleteVpcResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "0ED8D006-F706-4D23-88ED-E11ED28DCAC0"
}

Error codes

HttpCode Error code Error message Description
400 IncorrectStatus.VpcDhcpStatus The DhcpOptionsSet status of vpc does not support this operation. The error message returned because you cannot delete the VPC when the DHCP options set of the VPC is in the current state.
400 DependencyViolation.GatewayEndpoint The VPC contains endpoints and cannot be deleted. The error message returned because endpoints exist in the VPC. Delete the endpoints before you delete the VPC.
400 IncorrectVpcStatus Current VPC status does not support this operation. The error message returned because this operation cannot be performed when the VPC is in the current state.
400 DependencyViolation.RouteEntry Specified object has dependent resources The error message returned because custom route entries exist in the VPC and the VPC cannot be deleted.
400 DependencyViolation.Instance Specified object has dependent resources The error message returned because the VPC is associated with a resource.
400 DependencyViolation.VSwitch Specified object has dependent resources The error message returned because vSwitches exist in the VPC and the VPC cannot be deleted. Delete the vSwitches and try again.
400 DependencyViolation.SecurityGroup Specified object has dependent resources SecurityGroup. The error message returned because security groups exist in the VPC and the VPC cannot be deleted. Delete the security groups and try again.
400 DependencyViolation.RouteInterface Specified object has dependent route interface . The error message returned because the vSwitch is associated with a router interface and cannot be deleted.
400 DependencyViolation.Tunnel Specified object has dependent tunnel. The error message returned because the VPC is associated with a tunnel.
400 DependencyViolation.NatGateway Specified object has dependent resources NatGateway. The error message returned because NAT gateways exist in the VPC and the VPC cannot be deleted. Delete the NAT gateways and try again.
400 DependencyViolation.RouterInterface Specified object has dependent resources RouterInterface. The error message returned because the VPC is associated with a router interface.
400 Forbidden.VpcNotFound Specified VPC can not found. The error message returned because the specified VPC does not exist.
400 Forbbiden Active custom route in vpc. The error message returned because you must add a custom route entry to the VPC.
400 TaskConflict The eip operate too frequent, TaskConflict. The error message returned because the operations are too frequent and tasks conflict with each other.
400 IncorrectStatus.cbnStatus Current CBN status does not support this operation. The error message returned because the status of the CEN instance is invalid.
400 DependencyViolation.DhcpOptionsSet The VPC cannot be deleted when it is associated with dhcpOptionsSet. The error message returned because DHCP options sets exist in the VPC and the VPC cannot be deleted. Delete the DHCP options sets and try again.
400 InvalidRegionId.NotFound The specified region is not found. The error message returned because the specified region does not exist.
400 DependencyViolation.CustomRouteTable CustomRouteTable already exists. The error message returned because custom route tables exist in the VPC.
400 DependencyViolation.Ipv4Gateway The VPC cannot be deleted when it has ipv4Gateway. The error message returned because an IPv4 gateway exists in the VPC and the VPC cannot be deleted.
400 OperationDenied.VpcPeerExists The operation is not allowed because the VpcPeer exists. The error message returned because the VPC has a VPC peering connection.
400 DependencyViolation.AppAccess Specified object has dependent resources app access. The error message returned because the VPC has a reverse access and cannot be deleted.
403 OperationDenied The operation is not supported in this status. The error message returned because the status of the VPC is invalid and the operation cannot be performed.
403 OperationDenied The snapshot creation for the specified disk is not finished yet. The error message returned because the snapshot of the specified disk is being created.
404 InvalidVpcId.NotFound Specified VPC does not exist. The error message returned because the specified VPC does not exist.
500 InternalError The request processing has failed due to some unknown error. The error message returned because some unknown errors occurred.

For a list of error codes, see Service error codes.