Google Associate Cloud EngineerSetting up a cloud solution environmentMedium
A development team needs to deploy a new application to Google Cloud. They have created a new project, but when attempting to deploy resources, they receive an error indicating that the project is not associated with a billing account. Which `gcloud` command should they use to link their project to an existing billing account, assuming they have the necessary permissions?
- A`gcloud config set billing_account [BILLING_ACCOUNT_ID]`
- B`gcloud billing projects link [PROJECT_ID] --billing-account [BILLING_ACCOUNT_ID]`
- C`gcloud alpha billing accounts projects link [BILLING_ACCOUNT_ID] --project [PROJECT_ID]`
- D`gcloud projects update [PROJECT_ID] --billing-account [BILLING_ACCOUNT_ID]`
Show answer & explanationAnswer & explanation
Correct answer: B. `gcloud billing projects link [PROJECT_ID] --billing-account [BILLING_ACCOUNT_ID]`
The `gcloud billing projects link` command is the correct and direct way to associate a Google Cloud project with a specific billing account. This command requires the Project ID and the Billing Account ID.
Why the other options are wrong
- A. `gcloud config set` is for setting local CLI configuration properties, not for linking a project to a billing account in Google Cloud itself.
- C. The `gcloud alpha billing accounts projects link` command exists, but the more commonly used and stable command is `gcloud billing projects link`. The alpha version is usually for experimental features.
- D. There is no `--billing-account` flag for `gcloud projects update`. This command is for general project metadata updates.
gcloud Link Project to Billing Account
The `gcloud billing projects link` command is used to associate a Google Cloud project with a specific billing account, which is a prerequisite for deploying most resources.
- Connects a project to a billing account.
- Requires project ID and billing account ID.
- Necessary before resources can consume billable services.
Memory trick: Billing projects link is the command you need, to make your project's billing succeed.