Allow projects as destinations for log sinks (#2102)
* Add project log sink destination to project module * Add project log sink destination to folder module * Add project log sink destination to organization module * Fix typos * Add project log sink destination to billing-account module * Make filter field optional * Update READMEs --------- Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>
This commit is contained in:
@@ -293,6 +293,17 @@ module "bucket" {
|
||||
id = "${var.prefix}-bucket"
|
||||
}
|
||||
|
||||
module "destination-project" {
|
||||
source = "./fabric/modules/project"
|
||||
name = "destination-project"
|
||||
billing_account = var.billing_account_id
|
||||
parent = var.folder_id
|
||||
prefix = var.prefix
|
||||
services = [
|
||||
"logging.googleapis.com"
|
||||
]
|
||||
}
|
||||
|
||||
module "org" {
|
||||
source = "./fabric/modules/organization"
|
||||
organization_id = var.organization_id
|
||||
@@ -322,12 +333,17 @@ module "org" {
|
||||
}
|
||||
type = "logging"
|
||||
}
|
||||
alert = {
|
||||
destination = module.destination-project.id
|
||||
filter = "severity=ALERT"
|
||||
type = "project"
|
||||
}
|
||||
}
|
||||
logging_exclusions = {
|
||||
no-gce-instances = "resource.type=gce_instance"
|
||||
}
|
||||
}
|
||||
# tftest modules=5 resources=13 inventory=logging.yaml e2e serial
|
||||
# tftest modules=6 resources=17 inventory=logging.yaml e2e serial
|
||||
```
|
||||
|
||||
## Data Access Logs
|
||||
@@ -500,7 +516,7 @@ module "org" {
|
||||
| [iam_by_principals](variables-iam.tf#L54) | Authoritative IAM binding in {PRINCIPAL => [ROLES]} format. Principals need to be statically defined to avoid cycle errors. Merged internally with the `iam` variable. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [logging_data_access](variables.tf#L51) | Control activation of data access logs. Format is service => { log type => [exempted members]}. The special 'allServices' key denotes configuration for all services. | <code>map(map(list(string)))</code> | | <code>{}</code> |
|
||||
| [logging_exclusions](variables.tf#L66) | Logging exclusions for this organization in the form {NAME -> FILTER}. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [logging_sinks](variables.tf#L73) | Logging sinks to create for the organization. | <code title="map(object({ bq_partitioned_table = optional(bool, false) description = optional(string) destination = string disabled = optional(bool, false) exclusions = optional(map(string), {}) filter = string iam = optional(bool, true) include_children = optional(bool, true) type = string }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [logging_sinks](variables.tf#L73) | Logging sinks to create for the organization. | <code title="map(object({ bq_partitioned_table = optional(bool, false) description = optional(string) destination = string disabled = optional(bool, false) exclusions = optional(map(string), {}) filter = optional(string) iam = optional(bool, true) include_children = optional(bool, true) type = string }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [network_tags](variables-tags.tf#L17) | Network tags by key name. If `id` is provided, key creation is skipped. The `iam` attribute behaves like the similarly named one at module level. | <code title="map(object({ description = optional(string, "Managed by the Terraform organization module.") iam = optional(map(list(string)), {}) id = optional(string) network = string # project_id/vpc_name values = optional(map(object({ description = optional(string, "Managed by the Terraform organization module.") iam = optional(map(list(string)), {}) })), {}) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [org_policies](variables.tf#L104) | Organization policies applied to this organization keyed by policy name. | <code title="map(object({ inherit_from_parent = optional(bool) # for list policies only. reset = optional(bool) rules = optional(list(object({ allow = optional(object({ all = optional(bool) values = optional(list(string)) })) deny = optional(object({ all = optional(bool) values = optional(list(string)) })) enforce = optional(bool) # for boolean policies only. condition = optional(object({ description = optional(string) expression = optional(string) location = optional(string) title = optional(string) }), {}) })), []) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [org_policy_custom_constraints](variables.tf#L131) | Organization policy custom constraints keyed by constraint name. | <code title="map(object({ display_name = optional(string) description = optional(string) action_type = string condition = string method_types = list(string) resource_types = list(string) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
|
||||
@@ -17,8 +17,16 @@
|
||||
# tfdoc:file:description Log sinks and data access logs.
|
||||
|
||||
locals {
|
||||
logging_sinks = {
|
||||
for k, v in var.logging_sinks :
|
||||
# rewrite destination and type when type="project"
|
||||
k => merge(v, v.type != "project" ? {} : {
|
||||
destination = "projects/${v.destination}"
|
||||
type = "logging"
|
||||
})
|
||||
}
|
||||
sink_bindings = {
|
||||
for type in ["bigquery", "logging", "pubsub", "storage"] :
|
||||
for type in ["bigquery", "logging", "project", "pubsub", "storage"] :
|
||||
type => {
|
||||
for name, sink in var.logging_sinks :
|
||||
name => sink if sink.iam && sink.type == type
|
||||
@@ -41,7 +49,7 @@ resource "google_organization_iam_audit_config" "default" {
|
||||
}
|
||||
|
||||
resource "google_logging_organization_sink" "sink" {
|
||||
for_each = var.logging_sinks
|
||||
for_each = local.logging_sinks
|
||||
name = each.key
|
||||
description = coalesce(each.value.description, "${each.key} (Terraform-managed).")
|
||||
org_id = local.organization_id_numeric
|
||||
@@ -108,6 +116,13 @@ resource "google_project_iam_member" "bucket-sinks-binding" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_project_iam_member" "project-sinks-binding" {
|
||||
for_each = local.sink_bindings["project"]
|
||||
project = each.value.destination
|
||||
role = "roles/logging.logWriter"
|
||||
member = google_logging_organization_sink.sink[each.key].writer_identity
|
||||
}
|
||||
|
||||
resource "google_logging_organization_exclusion" "logging-exclusion" {
|
||||
for_each = var.logging_exclusions
|
||||
name = each.key
|
||||
|
||||
@@ -78,7 +78,7 @@ variable "logging_sinks" {
|
||||
destination = string
|
||||
disabled = optional(bool, false)
|
||||
exclusions = optional(map(string), {})
|
||||
filter = string
|
||||
filter = optional(string)
|
||||
iam = optional(bool, true)
|
||||
include_children = optional(bool, true)
|
||||
type = string
|
||||
@@ -88,9 +88,9 @@ variable "logging_sinks" {
|
||||
validation {
|
||||
condition = alltrue([
|
||||
for k, v in var.logging_sinks :
|
||||
contains(["bigquery", "logging", "pubsub", "storage"], v.type)
|
||||
contains(["bigquery", "logging", "project", "pubsub", "storage"], v.type)
|
||||
])
|
||||
error_message = "Type must be one of 'bigquery', 'logging', 'pubsub', 'storage'."
|
||||
error_message = "Type must be one of 'bigquery', 'logging', 'project', 'pubsub', 'storage'."
|
||||
}
|
||||
validation {
|
||||
condition = alltrue([
|
||||
|
||||
Reference in New Issue
Block a user