# Committed use discounts

> Turn on the Committed Use Discounts export in Cloud Billing and grant LevelFour read access, so your commitment terms, dates, and status appear alongside coverage.

Source: https://docs.levelfour.ai/connectors/gcp/committed-use-discounts


Google Cloud publishes the lifecycle of your committed use discounts in a separate BigQuery export. Enabling it fills in the commitment term, start and end dates, and status on your Google Cloud commitments.

Skip this page if you hold no committed use discounts. Everything else about commitments, including coverage and utilization, already works from the [Detailed usage cost export](/connectors/gcp/billing-export).

> **Warning**
>
> This export only works with an **organization** connection. If any of your Google Cloud connections is a single project, LevelFour keeps commitment lifecycle data off, because the export covers the whole billing account and cannot be narrowed to one project. Connect at the organization level first. See [Connect Google Cloud](/connectors/gcp#choose-single-project-or-organization).

> **Note**
>
> Google lists this export as Preview. Its fields can change, and the data you see may lag or shift as Google finishes the feature.

## What you get

| Field                            | Source                     |
| -------------------------------- | -------------------------- |
| Commitment term (1 year, 3 year) | This export                |
| Start and end dates              | This export                |
| Commitment status                | This export                |
| Coverage and utilization         | Detailed usage cost export |
| Spend against the commitment     | Detailed usage cost export |

## Prerequisites

* An **organization** connection to LevelFour, with no single-project connections alongside it.
* The [Detailed usage cost export](/connectors/gcp/billing-export) already connected.
* **Billing Account Administrator** or **Costs Manager** on the Cloud Billing account.
* **BigQuery Admin** on the project that holds your billing export dataset.

## Set up the export

### Turn on the export

1. Open the **Cloud Billing** console and select your billing account.
2. Go to **Billing export**, then the **BigQuery export** tab.
3. Under **Committed use discounts**, click **Edit settings** and choose the project that already holds your billing export dataset.

> **Warning**
>
> Choose the same project as your Detailed usage cost export. LevelFour looks for this export inside that project only.

This export arrives as a **linked dataset**, created in your project through Analytics Hub and sitting alongside your billing export dataset. No new table appears in the dataset you already have. You usually end up with a `billing_export_cud` dataset next to `billing_export`.

You do not report the dataset name to LevelFour. It looks for the export table inside your billing project.

### Grant LevelFour read access

The connect commands do not cover this dataset, because it did not exist when you ran them. Grant access yourself. It takes two grants: one so LevelFour can find the dataset, one so it can read it.

Use the address the connect script printed; see [Finding your service-account address](/connectors/gcp#finding-your-service-account-address) if you no longer have it.

**Let LevelFour find the dataset.** From Cloud Shell:

```bash
SA="PASTE_THE_ADDRESS_THE_SCRIPT_PRINTED"
gcloud projects add-iam-policy-binding YOUR_EXPORT_PROJECT_ID \
  --member="serviceAccount:$SA" --role="roles/bigquery.metadataViewer"
```

**Let LevelFour read the dataset.** Run `bq ls --datasets YOUR_EXPORT_PROJECT_ID` if you are not sure what Google named the linked dataset.

In the Google Cloud console, open **BigQuery**, find the linked dataset, then **Sharing > Permissions > Add principal**. Paste the service-account address and assign **BigQuery Data Viewer**.

Or from Cloud Shell, edit the dataset's access list in place. Save it first:

```bash
bq show --format=prettyjson YOUR_EXPORT_PROJECT_ID:billing_export_cud > cud-access.json
```

Add `{"role": "READER", "userByEmail": "<the service-account address>"}` to the `"access"` array in `cud-access.json`, then write the list back:

```bash
bq update --source cud-access.json YOUR_EXPORT_PROJECT_ID:billing_export_cud
```

### Wait for the first snapshot

Google writes this export as a daily snapshot. Allow up to 48 hours after enabling it, plus up to a day for LevelFour's next read.

## Confirming it worked

Open **Connect Providers > Google Cloud** in the dashboard.

> **Success**
>
> The **Committed Use Discounts (BigQuery export)** panel moves to **Connected**. Your commitments then carry a term, start and end dates, and a status.

The panel reaches **Connected** only when all of the following hold:

* Every Google Cloud connection in your account is an organization connection.
* Your Detailed usage cost export is connected and has delivered data.
* The linked dataset exists in the same project as your billing export.
* LevelFour can list datasets in that project and read the linked dataset.

See the [export status reference](/connectors/gcp/billing-export#export-status-reference) for what each label means.

## Removing access

Remove the LevelFour principal from the linked dataset's permissions in the BigQuery console, then drop the project-level role:

```bash
SA="PASTE_THE_ADDRESS_THE_SCRIPT_PRINTED"
gcloud projects remove-iam-policy-binding YOUR_EXPORT_PROJECT_ID \
  --member="serviceAccount:$SA" --role="roles/bigquery.metadataViewer"
```

Disabling the export in the Cloud Billing console stops new snapshots. Your commitments keep their coverage and utilization figures, which come from the usage cost export.

## Troubleshooting

**The panel stays at Not connected yet.**
Most often the linked dataset landed in a different project than your billing export, or the grants in [Grant LevelFour read access](#grant-levelfour-read-access) were never applied. Confirm with `bq ls --datasets YOUR_EXPORT_PROJECT_ID` that the dataset is in the expected project.

**You connected a single project and the panel stays at Not connected yet.**
Commitment lifecycle data needs an organization connection. Reconnect at the organization level.

**The panel shows Sync error.**
A permission error means the grants in [Grant LevelFour read access](#grant-levelfour-read-access) are missing or have not propagated yet. Wait a few minutes and check again.

**Commitments show coverage but no term or dates.**
Expected before this export lands. Coverage comes from the usage cost export.

## Next

* [Billing export](/connectors/gcp/billing-export) is the usage cost export that coverage itself comes from
* [All connectors](/connectors) has the other providers you can connect
