GoogleCloudPlatform / cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
https://cloud.run
Apache License 2.0
526 stars 91 forks source link

Handling When Billing Not Enabled #24

Closed jamesward closed 5 years ago

jamesward commented 5 years ago

Like:

  gcloud services enable run.googleapis.com 2> /dev/null

  if [[ $? -eq 1 ]]; then
    echo "Your account needs to have billing setup to continue. Visit:"
    echo "https://console.developers.google.com/billing/linkedaccount?project=$PROJECT_ID\n"
    read -p "After setting up billing, press enter to continue."
    gcloud services enable run.googleapis.com
  fi
ahmetb commented 5 years ago

Sounds like it should be in the first release.

jamesward commented 5 years ago

This exists in the existing button and I don't think we should drop it.

ahmetb commented 5 years ago

This is a bit too much gcloud output parsing (sadly).

I think we can redirect users to New Project UI as we do in #25, which prompts them with associating a billing account?

jamesward commented 5 years ago

Why can't we do something similar to what the current button does?

ahmetb commented 5 years ago
  1. I am not sure if this is a real problem (project exists without billing account)
  2. The enable command can fail with other reasons. It doesn’t mean billing always.
  3. Output parsing in the main code is sad and nasty

Unless this happens to a noticeable % of users, I am not sure if it’s worth doing.

People can read the gcloud error and re-click the button, it’s not a huge deal.

jamesward commented 5 years ago

Setting up billing on a project is a different and non-instinctive step after the project is created. So it seems like folks new to the platform could run into this. I did when I was getting started.

Since the primary purpose of the button is to get people new to the platform to give it a try, the more hand holding we can do, the better. It is worth trying to button from zero (no account, etc) and see how it all flows. That kind of user is the target for the button.

So maybe we can find a better way to validate a billing account?

ahmetb commented 5 years ago

Got it. This is more severe than I initially anticipated.

I'll try to get this in the first version.

ahmetb commented 5 years ago

Actually when no projects are found, we send users to https://console.cloud.google.com/cloud-resource-manager, which clearly asks for a billing account: image

How does someone end up with a project without a billing account?

ahmetb commented 5 years ago

Found this command which can help detecting:

$ gcloud beta billing projects describe ahmetb-samples-playground --format=yaml

billingAccountName: billingAccounts/0050EC-505932-A9F334
billingEnabled: true
name: projects/ahmetb-samples-playground/billingInfo
projectId: ahmetb-samples-playground

The only problem would be if they decide to change this command from beta to GA, then backport GA to beta, we would break in the downstream. But I think it's a fair amount of risk.

ahmetb commented 5 years ago

Sandeep tells me that this command fails if there's no billing account ––in a weird way:

$ gcloud beta billing projects describe --format=json x
API [cloudbilling.googleapis.com] not enabled on project
[x]. Would you like to enable and retry (this will take a
few minutes)? (y/N)?

Apparently enabling another API has an output like this

ERROR: (gcloud.beta.billing.projects.describe) User [y@gmail.com] does
 not have permission to access project [x] (or it may not exist):
Cloud Billing API has not been used in project x before or it is dis
abled. Enable it by visiting https://console.developers.google.com/apis/api/clou
dbilling.googleapis.com/overview?project=x then retry. If you enable
d this API recently, wait a few minutes for the action to propagate to our syste
ms and retry.
- '@type': type.googleapis.com/google.rpc.Help
  links:
  - description: Google developers console API activation
    url: https://console.developers.google.com/apis/api/cloudbilling.googleapis.
com/overview?project=1027933777022

but I really don't want to parse the output.

jamesward commented 5 years ago

In my case when I go to https://console.cloud.google.com/ without any projects, it takes me to https://console.cloud.google.com/getting-started

Then use the project selector to create a project, which takes me to: https://console.cloud.google.com/projectcreate

But I don't have an option to select a billing account there because I don't have a billing account. So I get a project without a billing account.

ahmetb commented 5 years ago

For the record, it is possible to create a project without billing via gcloud projects create, however it's nearly impossible (I wasn't able to find it) create a project on Cloud Console that doesn't prompt for a billing account.

That said, billing accounts can also go "inactive" (say an expired card), and the check we added covers both cases.

jamesward commented 5 years ago

Here is the UI I get on my demo account: Screenshot from 2019-06-04 09-04-58

But on my non-google work account I am forced to select a billing account.