# Check stock before you launch

See which instance types each zone can sell right now, so a launch goes where the type is in stock.

Machines come from live stock in each zone, and a type can be sold out in `de1a` while `de1b` still
has it. The platform reads the stock every minute.

## Prerequisites

- Permission for `ec2:DescribeInstanceTypeOfferings` (CLI, API, Terraform). The console shows
  stock in the **Create instance** form, which needs `ec2:RunInstances`.

## See the stock

**Console**
1. Open **Compute**, then choose **Create instance**.
2. Under **Size**, open **Instance type**. A type sold out in every zone is greyed and marked
   **sold out**.
3. Choose a type. Under **Basics**, the **Availability zone** list marks each zone where that type
   is sold out with _type_ **sold out**.
4. When the chosen type is sold out in the chosen zone, a note appears under the type picker. It
   names the zones that have the type, with a **Use** _zone_ button for each, and under **In stock
   where it goes** a button for each in-stock type with its monthly price.

**CLI**
```sh
dcloud ec2 instance-type-offerings list --instance-type performance-2
```

**API**
```http
GET /ec2/api/instance-type-offerings?instanceType=performance-2
```

```json
{
  "success": true,
  "data": [
    { "instanceType": "performance-2", "availabilityZoneId": "de1a", "providerLocation": "fsn1", "inStock": false, "changedAt": "…", "checkedAt": "…" },
    { "instanceType": "performance-2", "availabilityZoneId": "de1b", "providerLocation": "nbg1", "inStock": true, "changedAt": "…", "checkedAt": "…" }
  ],
  "unknownZones": []
}
```

Filters: `regionId` (default: yours), `availabilityZoneId`, `instanceType`.

**Terraform**
Use the `dcloud_instance_type_offerings` data source.

## Result

One row per type and zone, sorted by type, then zone. A zone in `unknownZones` could not be read
just now, which is not the same as sold out.

## When a launch hits a stock-out

A launch of a type sold out in its zone is refused with `409` before anything is bought; the
message also names the other zones that have the type, when there are any. A resize to a sold-out
type is refused with `409` as well. When the provider refuses a create that the last check still
saw in stock, the launch is refused with `409` and the type is recorded as sold out at once, so
every picker shows it. Every launch refused for stock is also reported as an event and a metric;
see [Monitoring](monitoring.md).

## Related

- [Instance types, images and zones](instance-types-and-zones.md)
- `ec2.instance-type-offerings.list` · `dcloud ec2 instance-type-offerings list` · `dcloud_instance_type_offerings`
