# Create or delete a network

Create a private network (VPC) with an address range of your choice, and delete one that nothing uses any more.

A network costs nothing. Instances you launch without one join the region's default network.

## Prerequisites

- Permission for `ec2:CreateVpc`; deleting needs `ec2:DeleteVpc`.
- In the console, also `ec2:DescribeVpcs` to open **Networks** (without it the page says "Access
  denied") and a network's page (without it the page is not found).
- Room in the VPCs quota (the default network counts).

## Create a network

**Console**
1. Open **Compute**, then **Networks**, and choose **Create network**.
2. (Optional) For **Name**, enter prod.
3. For **Region**, choose the region. A network cannot be moved later.
4. For **Address range**, enter the range, or keep `10.0.0.0/16`.
5. Choose **Create network**.

You can also create one from the **Network** picker of the launch form.

**CLI**
```sh
dcloud ec2 vpcs create --region-id de1 --name prod --cidr-block 10.1.0.0/16
```

**API**
```http
POST /ec2/api/vpcs
{ "regionId": "de1", "name": "prod", "cidrBlock": "10.1.0.0/16" }
```

**Terraform**
```hcl
resource "dcloud_vpc" "prod" {
  name       = "prod"
  cidr_block = "10.1.0.0/16"
}
```

The range is a private IPv4 range (RFC 1918), `/8` to `/24`, starting on its boundary; another is
refused with `400`. The answer is `201`; the network is `pending` until it exists at the provider,
then `available`. It has no subnets: instances take any free address in the range until you
[create a subnet](create-a-subnet.md).

## Delete a network

**Console**
1. Open the network, then choose **Danger zone**.
2. Choose **Delete network**, enter the network name, and choose **Delete network**.

**CLI**
```sh
dcloud ec2 vpcs delete vpc-uuid
```

**API**
```http
DELETE /ec2/api/vpcs/0ea56c91-0000-4000-8000-000000000001
```

**Terraform**
Remove the `dcloud_vpc` resource and run `terraform apply`.

The network and its subnets are removed. The delete is refused:

- `400` "Cannot delete the default VPC".
- `409` "Delete what is still in this VPC first: NAT gateway …" while it has a
  [NAT gateway](add-a-nat-gateway.md).
- `409` "Delete what is still in this VPC first: …" naming every instance that is not terminated,
  database, cache and VPN gateway still in it.

## Related

- [Networks and addresses](networks-and-addresses.md)
- `ec2.vpcs.create` · `dcloud ec2 vpcs delete` · `dcloud_vpc`
