What you enable
Step 1: Enable the exports (Console)
Enabling a billing export is Console-only - Google provides no API, gcloud command,
or Terraform resource for the toggle itself. This is the one manual step.
- In the Cloud Console, open Billing and select the billing account you want to connect.
- Go to Billing export -> BigQuery export.
- Under FOCUS export, click Edit settings, choose the project that will hold
the export, choose a data location, and Save. Google creates its own immutable
dataset named
gcp_billing_immutable_<BILLING_ACCOUNT_ID>_<region>- you do not pick the dataset. - Under Detailed usage cost, click Edit settings, choose a project and dataset
(or let it create
gcp_billing_export_resource_v1_<region>), and Save.
Step 2: Grant CostGraph read access
The connect dialog shows a one-line command. Open Cloud Shell in the project holding the export datasets and run it:COSTGRAPH_PROJECT_ID when the export lives outside your active Cloud Shell
project, or COSTGRAPH_SA_NAME to reuse an existing service account.
What it grants
Doing it by hand instead? These are the exact, least-privilege grants:
Dataset-level
dataViewer (rather than project-level) keeps access scoped to the
billing data only.
Keyless is recommended. Rather than exporting a service-account key, grant
CostGraph’s identity permission to impersonate this service account: grant
roles/iam.workloadIdentityUser on the service account to CostGraph’s federated
principal (Workload Identity Federation). Use roles/iam.serviceAccountTokenCreator
only when the caller is a Google identity - it is broader than external federation
needs. No secret leaves your project and there is no key to rotate. The connect screen provides CostGraph’s
identity to authorize. A downloaded service-account key is supported as a fallback.Step 3: Connect in CostGraph
- Open Integrations and choose Google Cloud.
- Paste the values the Cloud Shell script printed. To set it up by hand instead, choose impersonation (recommended - authorize CostGraph’s identity on your service account) or paste a service-account key, then enter the billing account ID.
- CostGraph validates it can run a query and read the FOCUS dataset, then starts the first sync. If a role is missing, the connect screen names the exact grant to add.
What CostGraph does with it
- Cost: FOCUS line items normalized to a canonical model, keeping both billed and effective (amortized) cost, credits, and commitment attribution.
- Reconciliation: allocated plus unallocated cost is checked to equal the invoice per billing account per month; FOCUS is validated against the Detailed export.
- Allocation: spend attributed by resource, label, and project, with an explicit unallocated bucket for tax, shared, and commitment costs.
Automating the setup
The Cloud Shell script in Step 2 covers this for a single billing account. Across many projects, provision it as code instead:google_bigquery_datasetfor the Detailed destinationgoogle_bigquery_dataset_iam_member/google_project_iam_memberfor the grantsgoogle_project_serviceto enable the BigQuery API