Allow explicit declaration of project for service
Closed this issue · 1 comments
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:
- Allow a user to specify an explicit
project_id
- 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.