Skip to content

Commit 545b1d7

Browse files
authored
fix:adds iam for the log-sink writer id for the logbucket module
1 parent 548c03b commit 545b1d7

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

examples/logbucket/folder/main.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ resource "random_string" "suffix" {
2121
}
2222

2323
module "log_export" {
24-
source = "../../../"
25-
destination_uri = module.destination.destination_uri
26-
filter = "resource.type = gce_instance"
27-
log_sink_name = "logbucket_folder_${random_string.suffix.result}"
28-
parent_resource_id = var.parent_resource_folder
29-
parent_resource_type = "folder"
24+
source = "../../../"
25+
destination_uri = module.destination.destination_uri
26+
filter = "resource.type = gce_instance"
27+
log_sink_name = "logbucket_folder_${random_string.suffix.result}"
28+
parent_resource_id = var.parent_resource_folder
29+
parent_resource_type = "folder"
30+
unique_writer_identity = true
3031
}
3132

3233
module "destination" {
33-
source = "../../..//modules/logbucket"
34-
project_id = var.project_id
35-
name = "logbucket_folder_${random_string.suffix.result}"
36-
location = "global"
34+
source = "../../..//modules/logbucket"
35+
project_id = var.project_id
36+
name = "logbucket_folder_${random_string.suffix.result}"
37+
location = "global"
38+
log_sink_writer_identity = module.log_export.writer_identity
3739
}

examples/logbucket/organization/main.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ resource "random_string" "suffix" {
2121
}
2222

2323
module "log_export" {
24-
source = "../../../"
25-
destination_uri = module.destination.destination_uri
26-
filter = "resource.type = gce_instance"
27-
log_sink_name = "logbucket_org_${random_string.suffix.result}"
28-
parent_resource_id = var.parent_resource_organization
29-
parent_resource_type = "organization"
24+
source = "../../../"
25+
destination_uri = module.destination.destination_uri
26+
filter = "resource.type = gce_instance"
27+
log_sink_name = "logbucket_org_${random_string.suffix.result}"
28+
parent_resource_id = var.parent_resource_organization
29+
parent_resource_type = "organization"
30+
unique_writer_identity = true
3031
}
3132

3233
module "destination" {
33-
source = "../../..//modules/logbucket"
34-
project_id = var.project_id
35-
name = "logbucket_org_${random_string.suffix.result}"
36-
location = "global"
34+
source = "../../..//modules/logbucket"
35+
project_id = var.project_id
36+
name = "logbucket_org_${random_string.suffix.result}"
37+
location = "global"
38+
log_sink_writer_identity = module.log_export.writer_identity
3739
}

modules/logbucket/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module "destination" {
3838
| Name | Description | Type | Default | Required |
3939
|------|-------------|------|---------|:--------:|
4040
| location | The location of the log bucket. | `string` | `"global"` | no |
41+
| log\_sink\_writer\_identity | The service account that logging uses to write log entries to the destination. (This is available as an output coming from the root module). | `string` | n/a | yes |
4142
| name | The name of the log bucket to be created and used for log entries matching the filter. | `string` | n/a | yes |
4243
| project\_id | The ID of the project in which the log bucket will be created. | `string` | n/a | yes |
4344
| retention\_days | The number of days data should be retained for the log bucket. | `number` | `30` | no |

modules/logbucket/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ resource "google_logging_project_bucket_config" "bucket" {
3838
retention_days = var.retention_days
3939
bucket_id = var.name
4040
}
41+
42+
#--------------------------------#
43+
# Service account IAM membership #
44+
#--------------------------------#
45+
resource "google_project_iam_member" "logbucket_sink_member" {
46+
project = google_logging_project_bucket_config.bucket.project
47+
role = "roles/logging.bucketWriter"
48+
member = var.log_sink_writer_identity
49+
}

modules/logbucket/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ variable "project_id" {
1919
type = string
2020
}
2121

22+
variable "log_sink_writer_identity" {
23+
description = "The service account that logging uses to write log entries to the destination. (This is available as an output coming from the root module)."
24+
type = string
25+
}
26+
2227
variable "name" {
2328
description = "The name of the log bucket to be created and used for log entries matching the filter."
2429
type = string

0 commit comments

Comments
 (0)