Prerequisites
- A Google Cloud project where you can create service accounts and grant IAM roles.
-
Permission to create service account keys. If your organization enforces
constraints/iam.disableServiceAccountKeyCreation(the default on organizations created since May 2024), ask your organization policy admin for an exception on this project before you start. Policy changes can take a few minutes to apply. -
The APIs for the services you want answers about, enabled in every project the connection should cover. Agents get
API not enabledfor any service that’s off. Enabling APIs needs Service Usage Admin (roles/serviceusage.serviceUsageAdmin) or Owner on the project. A common set, covering projects, inventory, GKE, BigQuery, IAM reviews, metrics, logs, and Cloud Storage: - The Admin role in your CloudThinker workspace, which can add and edit connections. See Roles.
- For cost questions and Optimize: a Cloud Billing Standard usage cost export to BigQuery. The export dataset must be in the same project as the service account, because Optimize only reads billing tables in the connected project. To create it, a Billing Account Administrator goes to Billing → Billing export → BigQuery export, and under Standard usage cost clicks Edit settings. See Google’s setup guide. A new export can take a few hours before its first rows appear, so Optimize may look empty on day one.
Setup
Create the service account in Google Cloud first, then upload its key to CloudThinker.- Google Cloud console
- gcloud CLI
1
Create the service account
In the Google Cloud console, select the project and go to IAM & Admin → Service Accounts. Click Create service account, name it
cloudthinker-readonly, and click Create and continue.2
Grant read-only roles
Add Viewer (
roles/viewer). For Optimize, also add BigQuery Job User (roles/bigquery.jobUser). Click Done. If your organization bans basic roles such as Viewer, use the predefined roles in Required permissions instead.3
For Optimize: share the billing dataset
Go to BigQuery, select the billing export dataset, and click Sharing → Permissions → Add principal. Enter the service account’s email, pick BigQuery Data Viewer, and click Save. Skip it if you don’t use Optimize.
4
Create a JSON key
Open the service account, go to the Keys tab, and click Add key → Create new key. Choose JSON and click Create. The key file downloads once and can’t be downloaded again.
1
Open the connect dialog
In the sidebar, click More → Workspace settings → Connections, select Google Cloud Platform, and click Connect.
2
Name the project
Fill in Alias (for example
prod-gcp) and Description (for example Production GCP project, GKE workloads). Agents read the description to pick the right connection when you have several.3
Upload the key and pick a region
Drag the JSON key file into GOOGLE_SERVICE_ACCOUNT_KEY, or click to browse for it. Pick your main region from the GCP_DEFAULT_REGION list. It defaults to
us-central1. Click Connect.Success state: the status moves through Connecting and Verifying, and the project shows a Connected status. Discovery now runs once in the background and spends credits. Check the Discovery section on the detail panel before your first prompt. See What happens after you connect.4
Set the environment
Open Google Cloud Platform in More → Workspace settings → Connections, click the pencil icon on the project’s row, and set Environment in Edit Instance. It labels the project for people and agents.
5
Ask a verification question
Open a chat and ask the verification question. The answer should list your real project IDs.
Connect more projects
Optimize reads billing only from the project the key belongs to (its
project_id), whichever option you pick. A per-project connection whose project doesn’t hold a billing export gets no Optimize cost data. The billing export covers every project on its billing account, so put the service account in the project that holds the export, grant Viewer on the folder or organization, and connect once. To grant on a folder you need Folder IAM Admin (roles/resourcemanager.folderIamAdmin). To grant on the organization you need Organization Administrator (roles/resourcemanager.organizationAdmin):
Connection details
The key file is JSON with fields such as
type, project_id, private_key, and client_email. Upload it unchanged.
Environment (Production, Staging, Development, or Not set) isn’t in the connect dialog. Set it after connecting, as in the setup steps: it labels the project for people and agents. Approval rules don’t read it, so a Rule that should cover one project names that connection.
Required permissions
If your organization bans basic roles, grant predefined read roles for the areas you need in place of Viewer:
Agent capabilities
Verify the connection
Example prompts
Write access
Allow writes on the connection’s detail panel controls whether agents may change anything in Google Cloud. It’s on by default, but a service account with only Viewer and the BigQuery read roles can’t change anything, so Google Cloud refuses every write until you grant more.
To lock writes in CloudThinker as well, open More → Workspace settings → Connections, select Google Cloud Platform, and turn off the Allow writes switch on its detail panel.
Troubleshooting
You can't create a key: key creation is disabled
You can't create a key: key creation is disabled
Cause: the organization policy
constraints/iam.disableServiceAccountKeyCreation is enforced.Fix: ask an organization policy admin to allow key creation for this project, or to create the key for you. If the exception is already granted, wait a few minutes: policy changes take time to apply. Also check that a policy set lower down, on the project or its folder, doesn’t still enforce the constraint.The upload is rejected or the test fails right away
The upload is rejected or the test fails right away
Cause: the file isn’t the original JSON key. Common cases are a P12 key, a copied snippet, or a file that was edited and lost its
private_key line breaks.Fix: create a new JSON key and upload the downloaded file unchanged.Agents get PERMISSION_DENIED or 'API not enabled'
Agents get PERMISSION_DENIED or 'API not enabled'
Check: the service account has a role on the project you asked about, and the API for that service (for example Compute Engine or Kubernetes Engine) is enabled in that project.Fix: grant Viewer on the project or its folder, or enable the API under APIs & Services. No reconnect needed: the next request uses the new access.
Optimize says no billing export was found
Optimize says no billing export was found
Cause: Optimize needs a Cloud Billing Standard usage cost export table (named
gcp_billing_export_v1_...) in the connected project.Fix: turn on the Standard usage cost export in Billing → Billing export, pointing at a dataset in the same project as the service account. If Optimize says the table is outside the connected project, move the export or create the service account in the project that holds it. If it asks you to select a table, pick the one you want Optimize to use.The test shows Timed out
The test shows Timed out
Cause: the test didn’t finish in time. Google Cloud endpoints are public, so it’s rarely your network.Fix: connect again. If it keeps timing out, contact us.
The connection shows Error
The connection shows Error
Cause: the key was deleted or disabled, or an organization policy (
constraints/iam.serviceAccountKeyExpiryHours) expired it.Fix: create a new key, then open the connection and click Replace credentials to upload it. That opens Edit Instance, the same dialog as Replace…. Scheduled work resumes once the status is Connected.Security
- Least privilege — grant only the permissions the agents need for your use case; start read-only and widen later.
- Read-only by default — use read-only credentials unless you want agents to make changes through this connection.
- Rotate credentials — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
- Revoke on offboarding — remove the credential at the provider when you delete a connection or a teammate leaves.
- Delete local copies of the key. After you upload the JSON file, delete it from your downloads folder or store it in a secret manager. It grants the service account’s access to anyone who holds it.
- Rotate at least every 90 days. Limit the key’s lifetime with the
constraints/iam.serviceAccountKeyExpiryHourspolicy. To rotate, create a new key, click the pencil icon on the project’s row, upload it with Replace… in Edit Instance, then delete the old key under the service account’s Keys tab. See Rotate a credential.
Related
Optimize quickstart
Turn your billing export into cost findings and savings recommendations.
Connections
Rotate credentials, set the environment, and read Discovery results.