Sample Terraform script that can be used to enable the required APIs at each project level for Google Cloud monitoring

Sample Terraform script that can be used to enable the required APIs at each project level for Google Cloud monitoring

Use this sample Terraform script to enable the required APIs for each project. This Terraform script helps you enable all the required APIs for multiple projects in a single deployment.
  1. Main.tf
  2. provider "google" {
  3. project = "base project id"
  4. } module "project-services" {
  5. source = "terraform-google-modules/project-factory/google//modules/project_services"
  6. for_each=var.project_id_map
  7. project_id = "${each.value.project_id}"
  8. activate_apis = [
  9. "compute.googleapis.com",
  10. "cloudfunctions.googleapis.com",
  11. "dataproc.googleapis.com",
  12. "redis.googleapis.com",
  13. "container.googleapis.com",
  14. "spanner.googleapis.com",
  15. "appengine.googleapis.com",
  16. "pubsub.googleapis.com",
  17. "composer.googleapis.com",
  18. "monitoring.googleapis.com",
  19. "compute.googleapis.com",
  20. "dataflow.googleapis.com",
  21. "run.googleapis.com",
  22. "file.googleapis.com",
  23. "cloudkms.googleapis.com",
  24. "dns.googleapis.com",
  25. "cloudbilling.googleapis.com",
  26. "cloudresourcemanager.googleapis.com",
  27. "cloudasset.googleapis.com",
  28. "servicenetworking.googleapis.com",
  29. "appengine.googleapis.com",
  30. "container.googleapis.com",
  31. "sqladmin.googleapis.com",
  32. "cloudkms.googleapis.com"
  33. ]
  34. }

  35. variables.tf
  36. variable "project_id_map" {
  37. type = map(object({
  38. project_id = string
  39. }))
  40. default = {
  41. "Projectid_1" = {
  42. project_id = "project_1_id"
  43. }
  44. "Projectid_2" = {
  45. project_id = "project_2_id"
  46. }
  47. }
  48. }