Skip to content

sambajahlo/GCloud-Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GCloud-Commands

A set of GCloud commands that you can install and run using Nimbella Commander.

Installing Google Cloud Commands

If you don't have the Nimbella Commander Slack app installed, follow the tutorial. Install the Google Cloud Command set using /nc csm_install github:SambaDialloB/GCloud-Commands

Access billing info via BigQuery

To use the GCloud Billing command provided in this repo, you need to enable Cloud Billing to export into BigQuery. This allows you to:

  1. View much more detailed charges and usage data in the BigQuery console.
  2. Use SQL to pull certain subsets of this information in the BigQuery console.
  3. Access and organize this data any way you want, programmatically. Follow the following instructions to set up Google Cloud Billing with BigQuerey. If you already have BigQuery enabled, you can skip to the last section to insert your keys into this command's secrets.

Create a BigQuery Dataset

  • Make sure you have the Billing Account Administrator role, a project, and a linked billing account.
  • Navigate to the BigQuery page and make sure your project is selected in the drop-down in the top left. select_project_gcloud.png
  • Add a dataset using the button under the resources tab on the left. Fill in the required information
  • Now you have a dataset that you can access with the gcloud_bill command.

Connect Cloud Billing to the BigQuery dataset

  • Access your Billing Cloud Console and choose your Billing Account.
  • Click Billing Export on the left and make sure BigQuery is selected near the top.
  • If your Daily cost detail is disabled, edit the settings and choose your new dataset to export your bills to.
  • After clicking "Save", your data will take a while to load into BigQuery. After a few hours, you should see data loaded into your dataset!

Since we now have a dataset set up, go ahead and create SQL statements to query it!

Create gcloud_bill Service Account to Access Data

  • Create a service account key, with the role of Project > Owner and choose the JSON key type.
  • After clicking create, a JSON file will be downloaded to your computer. Open it to view its contents.
  • Inside Slack, run /nc secret_create. This command lets you enter secrets into a secure web user interface and adds them to your app. Find out more about secret creation.
  • Split up the service account key, putting the "private_key" value in a separate secret. Replace that value with an empty string in the JSON. Put the rest of the JSON into a secret. Additionally, create a secret with your dataset and table name.
  • Run the gcloud_bill command using /<your_app_name> gcloud_bill and after a few seconds on initial spin up, you'll receive your current bill information!