-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
95 lines (82 loc) · 4.18 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
locals {
is_project_level = var.parent_resource_type == "project"
is_folder_level = var.parent_resource_type == "folder"
is_org_level = var.parent_resource_type == "organization"
is_billing_level = var.parent_resource_type == "billing_account"
# Locals for outputs to ensure the value is available after the resource is created
log_sink_writer_identity = local.is_project_level ? element(concat(google_logging_project_sink.sink.*.writer_identity, [""]), 0) : local.is_folder_level ? element(concat(google_logging_folder_sink.sink.*.writer_identity, [""]), 0) : local.is_org_level ? element(concat(google_logging_organization_sink.sink.*.writer_identity, [""]), 0) : local.is_billing_level ? element(concat(google_logging_billing_account_sink.sink.*.writer_identity, [""]), 0) : ""
log_sink_resource_id = local.is_project_level ? element(concat(google_logging_project_sink.sink.*.id, [""]), 0) : local.is_folder_level ? element(concat(google_logging_folder_sink.sink.*.id, [""]), 0) : local.is_org_level ? element(concat(google_logging_organization_sink.sink.*.id, [""]), 0) : local.is_billing_level ? element(concat(google_logging_billing_account_sink.sink.*.id, [""]), 0) : ""
log_sink_resource_name = local.is_project_level ? element(concat(google_logging_project_sink.sink.*.name, [""]), 0) : local.is_folder_level ? element(concat(google_logging_folder_sink.sink.*.name, [""]), 0) : local.is_org_level ? element(concat(google_logging_organization_sink.sink.*.name, [""]), 0) : local.is_billing_level ? element(concat(google_logging_billing_account_sink.sink.*.name, [""]), 0) : ""
log_sink_parent_id = local.is_project_level ? element(concat(google_logging_project_sink.sink.*.project, [""]), 0) : local.is_folder_level ? element(concat(google_logging_folder_sink.sink.*.folder, [""]), 0) : local.is_org_level ? element(concat(google_logging_organization_sink.sink.*.org_id, [""]), 0) : local.is_billing_level ? element(concat(google_logging_billing_account_sink.sink.*.billing_account, [""]), 0) : ""
}
# Org-level
resource "google_logging_organization_sink" "sink" {
count = local.is_org_level ? 1 : 0
org_id = var.parent_resource_id
name = var.log_sink_name
filter = var.filter
include_children = var.include_children
destination = var.destination_uri
dynamic "exclusions" {
for_each = var.exclusions
content {
name = exclusions.value.name
description = exclusions.value.description
filter = exclusions.value.filter
disabled = exclusions.value.disabled
}
}
}
# Folder-level
resource "google_logging_folder_sink" "sink" {
count = local.is_folder_level ? 1 : 0
folder = var.parent_resource_id
name = var.log_sink_name
filter = var.filter
include_children = var.include_children
destination = var.destination_uri
dynamic "exclusions" {
for_each = var.exclusions
content {
name = exclusions.value.name
description = exclusions.value.description
filter = exclusions.value.filter
disabled = exclusions.value.disabled
}
}
}
# Project-level
resource "google_logging_project_sink" "sink" {
count = local.is_project_level ? 1 : 0
project = var.parent_resource_id
name = var.log_sink_name
filter = var.filter
destination = var.destination_uri
unique_writer_identity = var.unique_writer_identity
dynamic "exclusions" {
for_each = var.exclusions
content {
name = exclusions.value.name
description = exclusions.value.description
filter = exclusions.value.filter
disabled = exclusions.value.disabled
}
}
}
# Billing Account-level
resource "google_logging_billing_account_sink" "sink" {
count = local.is_billing_level ? 1 : 0
billing_account = var.parent_resource_id
name = var.log_sink_name
filter = var.filter
destination = var.destination_uri
dynamic "exclusions" {
for_each = var.exclusions
content {
name = exclusions.value.name
description = exclusions.value.description
filter = exclusions.value.filter
disabled = exclusions.value.disabled
}
}
}