By default, projects do not have a billing account enabled. This means you cannot create billable resources. Therefore, you need to enable billing by linking your project with an active billing account you have permission to use. With a new Google Cloud account, you should just have one billing account, and it should be active.

First, find ACCOUNT_ID for a billing account to use for the project by listing the billing accounts associated with your Google Cloud account. This is three blocks of six characters separated by hyphens:

gcloud
beta
billing
accounts
list

Now assign it to a BILLING_ACCOUNT_ID environment variable like you did with PROJECT_ID:

export
BILLING_ACCOUNT_ID
=[
BILLING_ACCOUNT_ID
]

You can then assign the billing account to the project using this command:

gcloud
beta
billing
projects
link
$PROJECT_ID
–billing-account
$BILLING_ACCOUNT_ID

Note that here the gcloud command includes beta. You will see this occasionally. It just means it is a newer feature of the gcloud CLI. By the time you read this, the command may be fully integrated and beta will not be needed.

Checking Billing Is Enabled

You can check that billing is enabled on a project using the following command:

gcloud
beta
billing
projects
describe
$PROJECT_ID
–format
=
“value(billingEnabled)”

This will return True if billing is enabled and False if it is not. If you see True, your project is now configured with a billing account and ready to use.

Tip

A nice feature of Google Cloud is that you can also remove the billing accounts from projects and be confident that you will not be billed. This will shut down the services in your project, so it is better to shut them down yourself first.

However, having worked with AWS, I still find I am billed a few dollars a month for forgotten resources I have not tracked down and removed, so I appreciate this Google Cloud feature.

The command to unlink a billing account from your project is:

gcloud
beta
billing
projects
unlink
$PROJECT_ID

Doing More with the gcloud CLI

You will be using the gcloud CLI throughout this book. Although you can do nearly everything through the Google Cloud Console, as you get more familiar, the gcloud CLI you will find your productivity rise.

A good way to do this is to use the gcloud interactive environment by running the following command:

gcloud
beta
interactive

This gives you command completion and provides inline documentation, helping you to learn the commands and options available.

Leave a Reply

Your email address will not be published. Required fields are marked *