Assign project to bigquery reservation (GCP)

I’m using project-factory module to create projects and that is working great. I’ve been tasked with assigning each newly-created project to a bigquery reservation. I haven’t found any method of doing this in terraform.

I do have a way to do this in gcloud using “bq mk --reservation_grant”, but I’d prefer to do it natively in terraform. If there isn’t any current native solution, is it possible to somehow run a gcloud command inside of terraform using outputs from the project-factory module?

I think the best practice way to do this would be to run bq mk --reservation_grant in your pipeline after the Terraform run and use the eoutput from Terraform with the command terraform output $var_name.

If you do want to do this explicitly within Terraform, you can use a local-exec provisioner to run that command (, but keep in mind that this isn’t idempotent, and should be more of a last resort.

1 Like