canada-ca / accelerators_accelerateurs-gcp

[GCP] Tools and templates to accelerate GC service delivery. Outils et modèles pour accélérer la prestation de services du GC.
MIT License
10 stars 8 forks source link

Bug: bootstrap project without billing associated due to maxed 5 projects/billing quota will fail billing check silently #57

Open fmichaelobrien opened 1 year ago

fmichaelobrien commented 1 year ago

There is a billing check on line 69 of bootstrap.sh https://github.com/canada-ca/accelerators_accelerateurs-gcp/blob/main/deployment-templates/Terraform/guardrails/0-bootstrap/bootstrap.sh#L69

# get org and billing id based on project
org_id=$(gcloud projects get-ancestors $project_id --format='get(id)' | tail -1)
billing_id=$(gcloud alpha billing projects describe $project_id '--format=value(billingAccountName)' | sed 's/.*\///')

we need a -z check on the billing_id
      if [ -z "$billing_id" ]

oot_@cloudshell:~/cloudshell_open/accelerators_accelerateurs-gcp/deployment-templates/Terraform/guardrails/0-bootstrap (gr-bootstrap-sgz)$ ./bootstrap.sh -d sgz -p gr-bootstrap-sgz
seed project id: sgz-seed-project
boostrap project id: gr-bootstrap-sgz
org id: 22179561076
billing id:
Updated property [core/project].
checking roles of current account: root@staging.gcp.zone
iam.serviceAccountTokenCreator
ROLE: roles/iam.serviceAccountTokenCreator role set OK on super admin account      

Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/sgz-seed-project].
Waiting for [operations/cp.6003059784043367773] to finish...done.    
Enabling service [cloudapis.googleapis.com] on project [sgz-seed-project]...
Operation "operations/acat.p2-101190464045-7acd03d2-460b-484d-9bfe-b38f153261f0" finished successfully.
ERROR: (gcloud.beta.billing.projects.link) could not parse resource []
Listed 0 items.
Created service account [tfadmin-sgz].

 root_@cloudshell:~/cloudshell_open/accelerators_accelerateurs-gcp/deployment-templates/Terraform/guardrails/0-bootstrap (gr-bootstrap-sgz)$ billing_id=$(gcloud alpha billing projects describe $project_id '--format=value(billingAccountName)' | sed 's/.*\///')
root_@cloudshell:~/cloudshell_open/accelerators_accelerateurs-gcp/deployment-templates/Terraform/guardrails/0-bootstrap (gr-bootstrap-sgz)$ echo $billing_id

An empty value means billing is not enabled on the project yet - and will cause issues later on

Screen Shot 2022-11-18 at 10 42 24 AM
fmichaelobrien commented 1 year ago

adding PR today