From 0c21fecff8fafc1e2c7152a6bd6551527b0c1505 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Tue, 21 Dec 2021 09:22:10 +0100 Subject: [PATCH] Add metric scopes support (#397) * Add metric scopes support * Fix typo * new tfdoc block in README Co-authored-by: Ludovico Magnocavallo --- CHANGELOG.md | 1 + modules/project/README.md | 1 + modules/project/main.tf | 7 +++++++ modules/project/variables.tf | 6 ++++++ 4 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc86b8faa..0a5078b68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - **incompatible change** renamed `private_service_networking_range` variable to `psc_ranges` in `net-vpc`module, and changed its type to `list(string)` - added a firewall policy factory to `organization` module - refactored `tfdoc` +- added support for metric scopes to the `project` module ## [8.0.0] - 2021-10-21 diff --git a/modules/project/README.md b/modules/project/README.md index aa21fa773..d07d1ffb1 100644 --- a/modules/project/README.md +++ b/modules/project/README.md @@ -193,6 +193,7 @@ module "project" { | lien_reason | If non-empty, creates a project lien with this description. | string | | "" | | logging_exclusions | Logging exclusions for this project in the form {NAME -> FILTER}. | map(string) | | {} | | logging_sinks | Logging sinks to create for this project. | map(object({…})) | | {} | +| metric_scopes | List of projects that will act as metric scopes for this project. | list(string) | | null | | oslogin | Enable OS Login. | bool | | false | | oslogin_admins | List of IAM-style identities that will be granted roles necessary for OS Login administrators. | list(string) | | [] | | oslogin_users | List of IAM-style identities that will be granted roles necessary for OS Login users. | list(string) | | [] | diff --git a/modules/project/main.tf b/modules/project/main.tf index bb4ca986d..abd15fed2 100644 --- a/modules/project/main.tf +++ b/modules/project/main.tf @@ -389,3 +389,10 @@ resource "google_kms_crypto_key_iam_member" "crypto_key" { data.google_storage_project_service_account.gcs_sa, ] } + +resource "google_monitoring_monitored_project" "primary" { + provider = google-beta + for_each = toset(coalesce(var.metric_scopes, [])) + metrics_scope = each.value + name = local.project.project_id +} diff --git a/modules/project/variables.tf b/modules/project/variables.tf index 0db919757..34db467bf 100644 --- a/modules/project/variables.tf +++ b/modules/project/variables.tf @@ -100,6 +100,12 @@ variable "logging_sinks" { default = {} } +variable "metric_scopes" { + description = "List of projects that will act as metric scopes for this project." + type = list(string) + default = null +} + variable "name" { description = "Project name and id suffix." type = string