topics
January 7, 2025
Benefit: CloudHealth is granted access to all the projects in the billing account at the project level.
Overview: Create a custom role (or use the default Editor role) and IAM member at the project level and assign the role and IAM member to the service account. Identical roles and IAM members are automatically created and assigned to all projects in the billing account. If a new project is added to the billing account, a role and IAM member must be manually assigned to the new project.
Use When:
Configuring GCP Accounts in gcloud The gcloud command-line interface (CLI) is the primary CLI to the Google Cloud Platform. You can use this CLI in place of the Google Portal interface to programmatically configure your billing account in the CloudHealth platform. To use gcloud, you can either use Cloud Shell in the Google Console or Download and install the Google Cloud SDK.
To configure the GCP billing account using gcloud CLI, you need the project ID of a project assigned to that billing account. When you complete configuration, all projects assigned to the billing account are pulled into the CloudHealth Platform.
If you have already enabled BigQuery, use the project that contains your BigQuery dataset. Otherwise, you can use any project assigned to the billing account.
To ensure that billing data isn't lost, use the project ID of a project that won't be deleted.
The project ID is located in the Project Info pane of the Dashboard in the Google Cloud Console.

If you have already enabled BigQuery in the Google Console, skip this step.
Enter the following command in the gcloud CLI to create a dataset to use later when enabling BigQuery.
<insert project ID> with your project ID.<insert dataset name> with your dataset name.bq mk <insert project id>:<insert dataset name>
Enter the following command in the gcloud CLI to allow CloudHealth to gather cost and tagging information for your projects. This command enables the following APIs:
for project in $(gcloud projects list --format="value(projectId)")
do
if [[ $(gcloud beta billing projects describe $project --format="value(billingEnabled)") = "True" ]];
then
echo "ProjectId: $project - Enabling APIs..."
gcloud services enable compute.googleapis.com \
cloudresourcemanager.googleapis.com \
storage-component.googleapis.com \
recommender.googleapis.com \
container.googleapis.com \
dataproc.googleapis.com \
--project $project
fi;
done
This gcloud command only enables the APIs for existing projects. If you create new projects in the future, you must manually enable the above APIs for the new projects.
Enter the following command in the gcloud CLI to allow CloudHealth to gather data from your BigQuery dataset. Replace <insert project ID> with your project ID.
gcloud services enable bigquery-json.googleapis.com --project <insert project id>
Enter the following command in the gcloud CLI to create a service account.
<insert project ID> with your project ID.<insert service account name> with your new service account name.gcloud iam service-accounts create <insert service account name> --project <insert project id>
Enter the following command in the gcloud CLI to create a private key for the newly created service account and to save the key to the $HOME directory of your instance.
<insert project ID> with your project ID.<insert service account name> with your service account name.<insert private key name> with your new private key name.gcloud iam service-accounts keys create \
--iam-account <insert service account name>@<insert project id>.iam.gserviceaccount.com <insert private key name>.json
Enter the following command in the gcloud CLI to download the service account key to your local machine. Replace <insert private key name> with your private key name.
cloudshell download <insert private key name>.json
Depending on your cloud setup, you may choose to use the Editor role or create a custom role. CloudHealth recommend using a custom role, but you can use the Editor role with Automated setup for easier maintenance.
To create a custom role, refer to the Create a Custom Role topic.
Enter the following command to assign your preferred role to the service account.
<insert service account name> with your service account name.<insert project ID> with your project ID.Replace <insert role path> with the file path to your preferred role:
roles/editor for the Editor roleprojects/<insert project id>/roles/<insert custom role name> for a custom rolegcloud projects add-iam-policy-binding <insert project id> --member serviceAccount:<insert service account name>@<insert project id>.iam.gserviceaccount.com \
--role <insert role path>
Create your IAM members with the preferred role from Step 8.
<insert service account name> with your service account name.<insert project ID> with your project ID.Replace <insert role path> with the file path to your preferred role:
roles/editor for the Editor roleprojects/<insert project id>/roles/<insert custom role name> for a custom rolefor project in $(gcloud projects list --format="value(projectId)")
do
echo "ProjectId: $project"
gcloud config set project $project
gcloud projects add-iam-policy-binding $project --member user:<insert service account name>@<insert project id>.iam.gserviceaccount.com \
--member serviceAccount:<insert service account name>@<insert project id>.iam.gserviceaccount.com \
--role <insert role path> --project $project
done
Enabling BigQuery can only be completed in the Google Console.
Use the dataset you created above as your BigQuery dataset. If you have already enabled BigQuery in the Google Console, skip this step.
Log in to the CloudHealth platform and from the left menu, select Setup > Accounts > GCP Billing. Then click Add Account.
Enter your billing account, BigQuery, billing export, and service account information into the form. If needed, you can locate this information in the Google Cloud Console.

When you use a JSON key, CloudHealth verifies that the project ID in the JSON key matches the ID of the project to which you are attaching the credentials.
This option should be used if you want to use different service accounts for billing data collection and asset metadata collection.

CloudHealth validates new Google Service Accounts and derived projects every 4 hours. You can view derived projects by going to Setup > Accounts > GCP Project. Projects you enable in the CloudHealth Platform change status from Not Configured to Green, Yellow, Red, or Pending. See Status of Google Project to learn more about what each status represents.
The newly configured GCP billing accounts will be onboarded automatically, and within 48 hrs, you will see the cost data in the CloudHealth platform.