Skip to content

Commit da7a7d4

Browse files
authored
feat(TPG >= 5.27)!: Add intercept_children support for log sinks (#229)
Signed-off-by: Up Neck <163534172+up2neck@users.noreply.github.com>
1 parent 4301605 commit da7a7d4

File tree

9 files changed

+40
-27
lines changed

9 files changed

+40
-27
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Current version is 9.X. Upgrade guides:
2020
- [4.X -> 5.0](/docs/upgrading_to_v5.0.md)
2121
- [6.X -> 7.0](/docs/upgrading_to_v7.0.md)
2222
- [8.X -> 9.0](/docs/upgrading_to_v9.0.md)
23+
- [9.X -> 10.0](/docs/upgrading_to_v10.0.md)
2324

2425
## Usage
2526

@@ -29,7 +30,7 @@ example that will configure a Cloud Storage destination and a log export at the
2930
```hcl
3031
module "log_export" {
3132
source = "terraform-google-modules/log-export/google"
32-
version = "~> 9.0"
33+
version = "~> 10.0"
3334
destination_uri = "${module.destination.destination_uri}"
3435
filter = "severity >= ERROR"
3536
log_sink_name = "storage_example_logsink"
@@ -40,7 +41,7 @@ module "log_export" {
4041
4142
module "destination" {
4243
source = "terraform-google-modules/log-export/google//modules/storage"
43-
version = "~> 9.0"
44+
version = "~> 10.0"
4445
project_id = "sample-project"
4546
storage_bucket_name = "storage_example_bucket"
4647
log_sink_writer_identity = "${module.log_export.writer_identity}"
@@ -63,6 +64,7 @@ so that all dependencies are met.
6364
| exclusions | (Optional) A list of sink exclusion filters. | <pre>list(object({<br> name = string,<br> description = string,<br> filter = string,<br> disabled = bool<br> }))</pre> | `[]` | no |
6465
| filter | The filter to apply when exporting logs. Only log entries that match the filter are exported. Default is '' which exports all logs. | `string` | `""` | no |
6566
| include\_children | Only valid if 'organization' or 'folder' is chosen as var.parent\_resource.type. Determines whether or not to include children organizations/folders in the sink export. If true, logs associated with child projects are also exported; otherwise only logs relating to the provided organization/folder are included. | `bool` | `false` | no |
67+
| intercept\_children | Only valid if 'organization' or 'folder' is chosen as var.parent\_resource.type. Whether or not to intercept logs from child projects. If true, matching logs will not match with sinks in child resources, except \_Required sinks. This sink will be visible to child resources when listing sinks. | `bool` | `false` | no |
6668
| log\_sink\_name | The name of the log sink to be created. | `string` | n/a | yes |
6769
| parent\_resource\_id | The ID of the GCP resource in which you create the log sink. If var.parent\_resource\_type is set to 'project', then this is the Project ID (and etc). | `string` | n/a | yes |
6870
| parent\_resource\_type | The GCP resource in which you create the log sink. The value must not be computed, and must be one of the following: 'project', 'folder', 'billing\_account', or 'organization'. | `string` | `"project"` | no |

docs/upgrading_to_v10.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Upgrading to Log Export v10.0
2+
3+
The v10.0 release of Log Export is a backwards incompatible release and features a new feature `intercept_children` for folder and oraganization logging sinks. Minimum provider version `5.27` ia required.

examples/storage/billing_account/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
module "log_export" {
1818
source = "terraform-google-modules/log-export/google"
19-
version = "~> 9.0"
19+
version = "~> 10.0"
2020

2121
destination_uri = module.destination.destination_uri
2222
log_sink_name = "storage_example_logsink"
@@ -27,7 +27,7 @@ module "log_export" {
2727

2828
module "destination" {
2929
source = "terraform-google-modules/log-export/google//modules/storage"
30-
version = "~> 9.0"
30+
version = "~> 10.0"
3131

3232
project_id = var.project_id
3333
storage_bucket_name = "storage_example_bucket"

examples/storage/folder/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "random_string" "suffix" {
2323

2424
module "log_export" {
2525
source = "terraform-google-modules/log-export/google"
26-
version = "~> 9.0"
26+
version = "~> 10.0"
2727

2828
destination_uri = module.destination.destination_uri
2929
filter = "resource.type = gce_instance"
@@ -35,7 +35,7 @@ module "log_export" {
3535

3636
module "destination" {
3737
source = "terraform-google-modules/log-export/google//modules/storage"
38-
version = "~> 9.0"
38+
version = "~> 10.0"
3939

4040
project_id = var.project_id
4141
storage_bucket_name = "storage_folder_${random_string.suffix.result}"

examples/storage/organization/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "random_string" "suffix" {
2323

2424
module "log_export" {
2525
source = "terraform-google-modules/log-export/google"
26-
version = "~> 9.0"
26+
version = "~> 10.0"
2727

2828
destination_uri = module.destination.destination_uri
2929
filter = "resource.type = gce_instance"
@@ -35,7 +35,7 @@ module "log_export" {
3535

3636
module "destination" {
3737
source = "terraform-google-modules/log-export/google//modules/storage"
38-
version = "~> 9.0"
38+
version = "~> 10.0"
3939

4040
project_id = var.project_id
4141
storage_bucket_name = "storage_org_${random_string.suffix.result}"

examples/storage/project/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resource "random_string" "suffix" {
2222

2323
module "log_export" {
2424
source = "terraform-google-modules/log-export/google"
25-
version = "~> 9.0"
25+
version = "~> 10.0"
2626

2727
destination_uri = module.destination.destination_uri
2828
filter = "resource.type = gce_instance"
@@ -34,7 +34,7 @@ module "log_export" {
3434

3535
module "destination" {
3636
source = "terraform-google-modules/log-export/google//modules/storage"
37-
version = "~> 9.0"
37+
version = "~> 10.0"
3838

3939
project_id = var.project_id
4040
storage_bucket_name = "storage_project_${random_string.suffix.result}"

main.tf

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ resource "google_logging_project_sink" "sink" {
6767

6868
# Folder-level
6969
resource "google_logging_folder_sink" "sink" {
70-
count = local.is_folder_level ? 1 : 0
71-
name = var.log_sink_name
72-
description = var.description
73-
folder = var.parent_resource_id
74-
filter = var.filter
75-
include_children = var.include_children
76-
destination = var.destination_uri
77-
disabled = var.disabled
70+
count = local.is_folder_level ? 1 : 0
71+
name = var.log_sink_name
72+
description = var.description
73+
folder = var.parent_resource_id
74+
filter = var.filter
75+
include_children = var.include_children
76+
intercept_children = var.intercept_children
77+
destination = var.destination_uri
78+
disabled = var.disabled
7879
dynamic "bigquery_options" {
7980
for_each = local.bigquery_options
8081
content {
@@ -95,14 +96,15 @@ resource "google_logging_folder_sink" "sink" {
9596

9697
# Org-level
9798
resource "google_logging_organization_sink" "sink" {
98-
count = local.is_org_level ? 1 : 0
99-
name = var.log_sink_name
100-
description = var.description
101-
org_id = var.parent_resource_id
102-
filter = var.filter
103-
include_children = var.include_children
104-
destination = var.destination_uri
105-
disabled = var.disabled
99+
count = local.is_org_level ? 1 : 0
100+
name = var.log_sink_name
101+
description = var.description
102+
org_id = var.parent_resource_id
103+
filter = var.filter
104+
include_children = var.include_children
105+
intercept_children = var.intercept_children
106+
destination = var.destination_uri
107+
disabled = var.disabled
106108
dynamic "bigquery_options" {
107109
for_each = local.bigquery_options
108110
content {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ variable "include_children" {
3131
default = false
3232
}
3333

34+
variable "intercept_children" {
35+
description = "Only valid if 'organization' or 'folder' is chosen as var.parent_resource.type. Whether or not to intercept logs from child projects. If true, matching logs will not match with sinks in child resources, except _Required sinks. This sink will be visible to child resources when listing sinks."
36+
type = bool
37+
default = false
38+
}
39+
3440
variable "log_sink_name" {
3541
description = "The name of the log sink to be created."
3642
type = string

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ terraform {
2020

2121
google = {
2222
source = "hashicorp/google"
23-
version = ">= 3.53, < 6"
23+
version = ">= 5.27, < 6"
2424
}
2525
}
2626

0 commit comments

Comments
 (0)