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!!
4 Answers
- Go to the Google Cloud Platform Console.
- Click the "hamburger" menu item top left.
- Select Manage billing accounts.
- You will see a list of billing accounts and the number of projects assigned.
- 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:
- Go to IAM & admin.
- Select Manage resources.
- 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.

- 1
- 1

- 74,467
- 6
- 95
- 159
-
Hi @john-hanley, do you happen to know if it is possible to link a project and billing account programmatically? I am creating GCP projects in code using the Resource Manager API, and have yet to figure out how to assign billing accounts to the created projects at the same time, without requiring the manual process you describe in the web console. – crimeminister Dec 31 '19 at 18:52
-
1@crimeminister - Use the `updateBillingInfo` API: https://cloud.google.com/billing/reference/rest/v1/projects/updateBillingInfo – John Hanley Dec 31 '19 at 22:33
-
1Thanks @john-hanley, much appreciated! – crimeminister Jan 02 '20 at 20:28
-
1Also, you can do it with [gcloud command](https://cloud.google.com/sdk/gcloud/reference/alpha/billing/accounts/projects/link): `gcloud alpha billing accounts projects link PROJECT_ID (--account-id=ACCOUNT_ID | --billing-account=ACCOUNT_ID) [GCLOUD_WIDE_FLAG …]` – Serhii Rohoza Dec 09 '20 at 16:38
-
thanks. can't believe how much you have to dig to link a billing account. i would have expected this to be available from the"billing" page – Patrick Michaelsen Feb 19 '23 at 07:39
Updated gcloud command - Alpha has now become beta
gcloud beta billing projects link Project-ID --billing-account=xxxxxx-yyyyyy-xxxxxx

- 11
- 1
-
2As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 04 '22 at 17:45
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.

- 817
- 8
- 21
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

- 379
- 4
- 7