Using gcloud
This guide covers the same integration as Manual, performed from the command line with the gcloud CLI instead of the Google Cloud console. The resulting service account, external user and IAM roles are identical.
Below APIs must be enabled on your projects for OneLens to be able to read usage data on the respective services:
Vertex AI API(aiplatform.googleapis.com)Cloud Functions API(cloudfunctions.googleapis.com)Cloud SQL Admin API(sqladmin.googleapis.com)Compute Engine API(compute.googleapis.com)Kubernetes Engine API(container.googleapis.com)Dataflow API(dataflow.googleapis.com)Cloud Dataproc API(dataproc.googleapis.com)Cloud Filestore API(file.googleapis.com)Cloud Monitoring API(monitoring.googleapis.com)Network Management API(networkmanagement.googleapis.com)Recommender API(recommender.googleapis.com)Google Cloud Memorystore for Redis API(redis.googleapis.com)Service Usage API(serviceusage.googleapis.com)Cloud Asset API(cloudasset.googleapis.com)BigQuery API(bigquery.googleapis.com)
APIs are enabled per project, as Google Cloud has no organisation-level equivalent, so the above must be enabled for each project to be onboarded.
For steps on how to enable APIs, please follow this link to Google's documentation.
Setting up the billing exports is the one part of this guide that cannot be done from the CLI. Google provides no gcloud command or API for configuring Cloud Billing exports to BigQuery, so that step is performed in the Google Cloud console.
Identities involved
OneLens Reader SA, <service-account-id>@<billing-project-id>.iam.gserviceaccount.com
Created by you, in your billing project
Holds the read-only IAM roles OneLens uses. The address is unique to your environment, since it contains your own billing project ID.
onelens.finops@astuto.ai
Invited into your organisation as an external user
OneLens FinOps team, console login and manual validation
onelens-customer-sa@astuto-prod-mum.iam.gserviceaccount.com
OneLens, in our own environment
Our platform identity. You grant it Service Account Token Creator on your OneLens Reader SA so it can generate short-lived credentials to impersonate it. It receives no other role, and no service account keys are ever shared.
The external user email above is the default. If the OneLens team provided you with a different address during onboarding, use that address in place of onelens.finops@astuto.ai throughout this guide.
Values to collect before you start
Organisation ID
111111111111
Billing Account ID
XXXXXX-XXXXXX-XXXXXX
Billing Export Project ID
onelens-billing-project
Create the Billing Project
Create the project that will hold your exported billing data, link it to your billing account, and enable the APIs it needs.
If you already have a project set up to host billing data through BigQuery, skip the project creation above and set BILLING_PROJECT_ID to that project.
Enable Detailed Usage Export
Create the dataset that will hold the detailed usage cost export.
Enabling the export must be completed in the Google Cloud console, it cannot be performed via CLI. Print the billing export URL for your account, then open it in a browser:
On the
BigQuery exporttab, enableDetailed usage costwith the following options:Under
Projects, select the billing project (OneLens Billing Project).Under
Dataset, select the dataset created above (billing_export).Click
Save.
Enable CUD Export
This step must be completed in the Google Cloud console, it cannot be performed via CLI. Print the billing export URL for your account, then open it in a browser:
On the
BigQuery exporttab, enableCommitted use discounts exportwith the following options:Under
Projects, select the billing project (OneLens Billing Project).Under
Linked dataset name, enter a new dataset name: cud_export.Under
Location type, select Multi-region.Under
Multi-region, select US (multiple regions in the United States).Click
Save.
Do not create this dataset with bq mk. The committed use discounts export requires a dataset name that does not already exist, and creates the linked dataset for you.
Grant Organisation-level roles
Run the following commands to grant all required organisation-level roles to both principals. Granting at the organisation covers every project in it, including projects created later. Each command is idempotent, existing bindings are never overwritten.
Grant roles to External User (onelens.finops@astuto.ai)
Grant roles to OneLens Service Account ($LOCAL_SA)
Create and grant the AI key inventory role (Service Account only)
OneLens reports on the API keys in your organisation, so that keys which can reach Vertex AI or Gemini without a restriction are visible alongside their cost. That needs one permission, apikeys.keys.list, which returns a key's name, display name, API restrictions and creation time.
There is a predefined role for this, API Keys Viewer, and this guide deliberately does not use it. It also contains apikeys.keys.getKeyString, which reads live key strings. The custom role below holds apikeys.keys.list and nothing else, so the key strings in your organisation stay unreachable.
You have now successfully integrated your Google Cloud Platform environment with OneLens.
Please share the following values to the OneLens team to facilitate the connection on our end:
Service Account email ID
Billing project ID
Billing Account ID(s)
BigQuery dataset ID (billing_export)
BigQuery dataset ID (cud_export)
Role summary
The table below lists every IAM role granted, the resource level at which it is applied, the member it is assigned to, and its purpose.
Both = onelens.finops@astuto.ai and the OneLens Reader service account.
roles/resourcemanager.organizationViewer
Organisation
Both
View the organisation, folder and project hierarchy
roles/cloudasset.viewer
Organisation
Both
View the asset inventory across the organisation
roles/browser
Organisation
Both
Browse the resource hierarchy without reading resource data
roles/viewer
Organisation
User only
Read-only console access for FinOps analysis
Service viewer roles*
Organisation
SA only
Read metadata for Compute, GKE, Cloud SQL and other services
roles/bigquery.resourceViewer
Organisation
Both
View BigQuery datasets, tables and jobs
roles/bigquery.metadataViewer
Organisation
Both
Read dataset and table metadata
roles/bigquery.jobUser
Organisation
Both
Run BigQuery jobs and queries
roles/billing.viewer
Billing account
Both
Read billing account costs, invoices and spend data
roles/bigquery.dataViewer
Billing project
Both
Read the data inside the billing export tables
roles/bigquery.readSessionUser
Billing project
SA only
Create read sessions for programmatic data reads
roles/iam.serviceAccountTokenCreator
Your OneLens Reader SA
OneLens backend SA and external user
Impersonate the OneLens Reader service account
onelensAiKeyInventory (custom)
Organisation
SA only
List API key metadata for AI cost reporting
*Service viewer roles are roles/aiplatform.viewer, roles/cloudfunctions.viewer, roles/cloudsql.viewer, roles/compute.viewer, roles/container.viewer, roles/dataflow.viewer, roles/dataproc.viewer, roles/file.viewer, roles/monitoring.viewer, roles/networkmanagement.viewer, roles/recommender.viewer, roles/redis.viewer and roles/serviceusage.serviceUsageViewer.
Revoking access (if required)
Access is fully reversible. The commands below remove every binding this guide created and delete the service account.
Last updated

