garbetjie/terraform-google-cloud-run

Allow explicit declaration of project for service

Closed this issue · 1 comments

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_service#project

project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

There are use-cases where the provider project may differ from the target project for the new resource, and unfortunately it's currently not possible to reliably use dynamic providers in terraform. Therefore, it would be great if we could specify which project we wish for the service to be created in.

An additional caveat is that the actor may not have access to the default project associated with their provider. I think the logic would therefore be:

  1. Allow a user to specify an explicit project_id
  2. If no explicit project_id is provided then obtain the default project for the provider
variable "project_id" {
  type    = string
  default = null 
}

data "google_project" "default" {
  count = var.project_id == null ? 1 : 0
}

locals {
  project_id = var.project_id != null ? var.project_id : data.google_project.default.project_id
}

I'm not a terraform expert so although this works, I'm not sure if it's best practice: perhaps there's a better way to tackle this. If this is the right way, I'm happy to submit a PR.

Ps: great work on this module, looking forward to using it! thank you.

Hey @shrink. Glad to hear the module is useful for you!

Thanks for raising this issue and suggesting this. I've just pushed version 1.1.0 which includes the project variable to be able to specify the project in which the service is created.