How do I link the billing account to project in google cloud

Viewed 17320

How do i link the billing account to my project on google cloud? I have enabled the billing but unable to open the JS file and getting some errors like "You must enable the billing on google clouds projects". Please help me out in fixing this error!! Thanks!! enter image description here

4 Answers
  1. Go to the Google Cloud Platform Console.
  2. Click the "hamburger" menu item top left.
  3. Select Manage billing accounts.
  4. You will see a list of billing accounts and the number of projects assigned.
  5. The My projects tab will show you a list of your projects and the associated billing account.

To assign a billing account to a project:

  1. Go to IAM & admin.
  2. Select Manage resources.
  3. To the RIGHT of each project is an ellipsis menu (three vertical dots). Click and select billing.

If you just enabled your billing account, wait. The approval is not instant. If it has been an hour or so, go to your billing account and look for errors regarding your payment being declined, invalid credit card etc.

Just creating a billing account does not enable a project. You must assign a billing account to a project. The menus above provide these features.

I created a videolab with a collection of videos on Google Cloud Billing. The following link is a video to show you how to create and attach a billing account. There are many more videos in this collection.

Create and attach a billing account

Updated gcloud command - Alpha has now become beta

gcloud beta billing projects link Project-ID --billing-account=xxxxxx-yyyyyy-xxxxxx

To update the projects billing account info programmatically one could use google-cloud's billing client library. Below is the sample using ruby client,

require "google/cloud/billing"

billing_account_name = ""
project_id = ""

billing_manager = Google::Cloud::Billing.cloud_billing_service   
billing_manager.update_project_billing_info name: "projects/#{project_id}", 
                                            project_billing_info: {
                                                billing_account_name: "billingAccounts/#{billing_account_name}",
                                                billing_enabled: true,
                                                project_id: project_id,
                                                name: "projects/#{project_id}/billingInfo",
                                            }

Refer https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-billing for more info on enabling auth and running the script.

Elaborating on @suraj-psu's answer, and using a tip found at https://unix.stackexchange.com/questions/84922/extract-a-part-of-one-line-from-a-file-with-sed, the following should work only under the right circumstances.

You can borrow the information from another project that you know for sure it has an enabled billing account.

gcloud beta billing projects describe KNOWN_BILLING_ENABLED_PROJECT

You copy/paste the result, but you could also save it in a variable as follows,

BILLING_ACCOUNT=$(gcloud beta billing projects describe KNOWN_BILLING_ENABLED_PROJECT | awk '/billingAccountName: /{print $NF}')

And then,

gcloud beta billing projects link YOUR_NEW_PROJECT --billing-account=$BILLING_ACCOUNT
Related