# Resize an instance

Change a stopped instance to another instance type, for more or less CPU and memory.

Replace _i-3f9a2c07_ with your instance's id. A resize changes CPU and memory only: the disk keeps
its size. For more space, attach a [volume](create-and-attach-a-volume.md).

## Prerequisites

- Permission for `ec2:ModifyInstanceAttribute`.
- In the console, also `ec2:DescribeInstances` to open the instance's page (without it the page is
  not found).
- The instance is `stopped`. Otherwise the request is refused with `400` "Instance must be stopped
  before resizing (current state: …)".
- The new type is a type of the catalog (else `400` "Invalid or unavailable server type") and is in
  stock in the instance's zone (else `409` with the provider's stock message).
- A type with more vCPUs needs room for the extra vCPUs in the vCPU quota, else `409` "Quota
  exceeded: …".
- The instance runs on a provider machine: an instance on your own hosts, or one whose machine does
  not exist yet, is refused with `409` "Instance has no backing server yet".
- An instance that is a node of a Kubernetes cluster is refused with `409`; scale its node group
  instead.

## Resize

**Console**
1. Open the instance, then choose **Settings** (or **Resize** in the **⋯** menu).
2. Under **Server type**, choose **Resize**.
3. If the instance is not stopped, the dialog says "Stop … first."; while it is running, choose
   **Stop instance** and wait until it is stopped.
4. For **New type**, choose a type. The current type, types of the other architecture and types
   sold out in the zone are greyed with the reason. The dialog shows the monthly price before and
   after, as a maximum: instances are billed per started hour, capped at the monthly price.
5. Choose **Resize instance**.

**CLI**
```sh
dcloud ec2 instances stop i-3f9a2c07
dcloud ec2 instances wait i-3f9a2c07 --state stopped
dcloud ec2 instances resize i-3f9a2c07 --server-type performance-4
dcloud ec2 instances start i-3f9a2c07
```

**API**
```http
POST /ec2/api/instances/i-3f9a2c07/actions/resize
{ "serverType": "performance-4" }
```

**Terraform**
Change `server_type` on the `dcloud_instance` and run `terraform apply`. Terraform stops the
instance, resizes it and starts it again.

## Result

The answer comes as soon as the change is accepted; the type changes in the background. The API
and console leave the instance stopped: start it again when its type has changed. A resize that
fails at the provider leaves the instance stopped with the error, starting "Resize:", on its page.
Once started, the instance is billed at the new type's hourly price.

## Related

- [Instance types, images and zones](instance-types-and-zones.md)
- `ec2.instances.resize` · `dcloud ec2 instances resize` · `dcloud_instance`
