# Cap what runner pools spend on cloud machines

Set a monthly cap on the cloud machines of one runner pool or of all pools together; at the cap jobs wait for our own hosts.

A runner pool runs its jobs on our own CI hosts first, and rents cloud machines when they are
full. Our own hosts cost you nothing extra; the cloud machines are billed by the started hour. A
**cloud spend cap** sets the most those cloud machines may cost in a billing month (a calendar
month, German time), in euros net. There are two:

- **A pool's cap** counts the cloud machines of that pool.
- **The organization cap** counts the cloud machines of all pools together, pools deleted this
  month included.

Whichever is reached first applies. At the cap:

- the pool rents no cloud machine; its jobs run on our own hosts, one free slot at a time;
- a cloud machine of the pool finishes the job it has, takes no other, and is removed;
- every waiting run says why: "Waiting for an own-host slot: cloud overflow paused, the pool's
  monthly cap of 300,00 € is reached; own hosts only until 1 December 2026 or until an
  administrator of this organization raises it."

A pool with placement `cloud-only` has no own-host slot to wait for: at the cap its jobs wait
until the month ends or the cap is raised. A cap of `0` keeps a pool on our own hosts always.

What counts is each cloud machine's started hours in the month times its hourly price when it
was bought. The pool's page under **This month** and the API show that number; your invoice
remains the authority on what was billed.

Replace pool-id with the pool's id.

## Prerequisites

- `ci:UpdateRunnerPool` to set a pool's cap, `ci:PutCloudSpendCap` to set the organization cap,
  both on all of CI (`rn:ews::<organization id>:ci:*`). `ci:DescribeRunnerPools` to read them.
- In the console, also `ci:DescribeRunners` to open **Runners** (without it the page shows an
  access-denied notice).

## Set a pool's cap

**Console**
1. Open **Runners** under CI, then choose the pool's row.
2. Choose **Edit**. When the pool is at its cap, **Raise the cap** in the banner at the top of the
   page opens the same sheet at the cap.
3. For **Cloud spend cap per month (€, net)**, enter an amount. Leave it empty for no cap.
4. Choose **Save pool**.

**CLI**
```sh
dcloud ci runner-pools update pool-id --monthly-cloud-cap-eur 300
```

**API**
```http
PATCH /ci/api/runner-pools/pool-id
{ "monthlyCloudCapEur": 300 }
```

`null` removes the cap. A new pool takes the same field on create.

**Terraform**
```hcl
resource "dcloud_ci_runner_pool" "ci" {
  name                  = "ci"
  labels                = ["ubuntu-latest", "ubuntu-24.04"]
  size                  = "s-16"
  max_size              = 24
  monthly_cloud_cap_eur = 300
}
```

## Set the organization cap

**Console**
1. Open **Runners** under CI.
2. Below the table, under **Cloud machines of all pools**, next to **Organization cap on CI cloud
   spend**, choose **Set a cap** (or **Change cap**). The section shows once your organization
   has a pool.
3. For **Cap per month (€, net)**, enter an amount. Leave it empty to remove the cap.
4. Choose **Save cap**.

**CLI**
```sh
dcloud ci cloud-spend-cap set --monthly-cloud-cap-eur 500
dcloud ci cloud-spend-cap get
```

**API**
```http
PUT /ci/api/cloud-spend-cap
{ "monthlyCloudCapEur": 500 }
```

`{ "monthlyCloudCapEur": null }` removes it.

**Terraform**
```hcl
resource "dcloud_ci_cloud_spend_cap" "org" {
  monthly_cloud_cap_eur = 500
}
```

Destroying the resource removes the cap.

Every pool is rescaled at once: a cap at or below this month's spend pauses cloud overflow within
a minute, and a cap raised above it resumes it.

## What you are told

- **At 80 %** of a cap, the organization's owners and admins get one mail.
- **When runs have waited 30 minutes** because of a cap, they get one more mail for that cap and
  month, not one per run.
- Both mails come once per cap amount and month: raising or lowering the cap arms them again.
- At the cap the pool's status in **Runners** reads **Cloud paused**, and its page shows the
  banner **Cloud overflow paused.** with the date it resumes. Under **This month** the page counts
  its jobs on our own hosts and on rented cloud machines.
- A run that waits its whole queue time behind the cap fails with that reason, not with "no
  runner".

## Related

- [Create a runner pool](create-a-runner-pool.md)
- [Change or delete a runner pool](change-or-delete-a-runner-pool.md)
- `ci.cloud-spend-cap.set` · `ci.runner-pools.update`
