hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

Enable multiple project services #6249

Closed jeremad closed 4 years ago

jeremad commented 4 years ago

Community Note

Description

The google_project_service ressource allows to enable a service API on a project. When manipulating multiple projects, it would be nice to provide a way to enable multiple service APIs.

It is easy to loop around APIs when manipulating one or two projects, however for N projects this does not scale easily.

New or Affected Resource(s)

A new resource that will enable multiple service APIs, using the batchEnable endpoint

Potential Terraform Configuration

resource "google_project_services" "services" {
  project  = "my-project"
  services = ["cloudbilling.googleapis.com", "clouderrorreporting.googleapis.com"] 
}

References

https://cloud.google.com/service-usage/docs/reference/rest/v1/services/batchEnable

jeremad commented 4 years ago

Well, looking at make a PR to do this, I realized that this API used to exist. I didn't find why it was removed, though

jeremad commented 4 years ago

https://www.terraform.io/docs/providers/google/guides/version_3_upgrade.html#resource-google_project_services https://registry.terraform.io/modules/terraform-google-modules/project-factory/google/3.3.0/submodules/project_services

OK I found out what I needed to know, I'll use the module. I can close this.

jeremad commented 4 years ago

Actually the module cannot be used with multiple projects programmatically because of https://github.com/hashicorp/terraform/issues/17519.

So it would still be nice to have a non-authoritative version of google_project_services

nat-henderson commented 4 years ago

Hi there! It seems like a resource-level for_each on google_project_service would do what you need - is that right?

nat-henderson commented 4 years ago

Let me provide a little more:

variable "services" {
  type = list(string)
}

resource "google_project_service" "services" {
  for_each = toset(var.services)
  project = "my-project"
  service = each.value
}

And then you can set the variable in a tf.vars file or however you prefer to set variables.

Is that helpful?

jeremad commented 4 years ago

The problem is when you need to iterate over services and projects!

I managed to make it work with setproduct however I am not too satified with the result, and since the GCP APIs supports it, I figured it would be a nice feature. However I understand that this is just a nice to have, and there is probably some more important stuff to work on.

nat-henderson commented 4 years ago

Ah yeah, setproduct is a good solution for that. :)

Behind the scenes we do support the GCP API service enablement batch mode. I'm going to close this issue since the setproduct solution is the best one right now and should get you the relatively-low request volume you're looking for.

jeremad commented 4 years ago

OK, I understand. Thank you for you support anyways ! :+1:

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!