Skip to content

Commit ef43513

Browse files
authored
fix:adds test assertion for log sink writer identity
1 parent b997fa1 commit ef43513

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

examples/logbucket/folder/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ This example configures a folder-level log sink that feeds a logging log bucket
1818
| log\_bucket\_project | The project where the log bucket is created. |
1919
| log\_sink\_destination\_uri | A fully qualified URI for the log sink. |
2020
| log\_sink\_folder\_id | The folder id where the log sink is created. |
21+
| log\_sink\_writer\_identity | Writer identity for the log sink that writes to the log bucket. |
2122

2223
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/logbucket/folder/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ output "log_sink_destination_uri" {
3333
description = "A fully qualified URI for the log sink."
3434
value = module.destination.destination_uri
3535
}
36+
37+
output "log_sink_writer_identity" {
38+
description = "Writer identity for the log sink that writes to the log bucket."
39+
value = module.log_export.writer_identity
40+
}

examples/logbucket/organization/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ This example configures a organization-level log sink that feeds a Cloud Log Buc
1818
| log\_bucket\_project | The project where the log bucket is created. |
1919
| log\_sink\_destination\_uri | A fully qualified URI for the log sink. |
2020
| log\_sink\_organization\_id | The organization id where the log sink is created. |
21+
| log\_sink\_writer\_identity | Writer identity for the log sink that writes to the log bucket. |
2122

2223
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/logbucket/organization/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ output "log_sink_destination_uri" {
3333
description = "A fully qualified URI for the log sink."
3434
value = module.destination.destination_uri
3535
}
36+
37+
output "log_sink_writer_identity" {
38+
description = "Writer identity for the log sink that writes to the log bucket."
39+
value = module.log_export.writer_identity
40+
}

test/integration/logbucket-folder/logbucket_folder_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestLogBucketFolderModule(t *testing.T) {
3737
logBucketName := insSimpleT.GetStringOutput("log_bucket_name")
3838
logSinkFolderId := insSimpleT.GetStringOutput("log_sink_folder_id")
3939
logSinkDestination := insSimpleT.GetStringOutput("log_sink_destination_uri")
40+
logSinkWriterId := insSimpleT.GetStringOutput("log_sink_writer_identity")
4041

4142
logBucketDetails := gcloud.Runf(t, fmt.Sprintf("logging buckets describe %s --location=%s --project=%s", logBucketName, "global", projectId))
4243

@@ -50,6 +51,9 @@ func TestLogBucketFolderModule(t *testing.T) {
5051
assert.Equal(logSinkDestination, logSinkDetails.Get("destination").String(), "log sink destination should match")
5152
assert.Equal("resource.type = gce_instance", logSinkDetails.Get("filter").String(), "log sink filter should match")
5253

54+
//assert writer id has the bucketWriter role
55+
logSinkServiceAccount := gcloud.Runf(t, fmt.Sprintf("projects get-iam-policy %s --flatten bindings --filter bindings.role:roles/logging.bucketWriter", projectId))
56+
assert.Contains(logSinkServiceAccount.Array()[0].Get("bindings.members").String(), logSinkWriterId, "log sink has expected identity")
5357
})
5458
insSimpleT.Test()
5559
}

test/integration/logbucket-org/logbucket_org_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ func TestLogBucketOrgModule(t *testing.T) {
3434
insSimpleT.DefineVerify(func(assert *assert.Assertions) {
3535
insSimpleT.DefaultVerify(assert)
3636

37-
project_id := insSimpleT.GetStringOutput("log_bucket_project")
37+
projectId := insSimpleT.GetStringOutput("log_bucket_project")
3838
logBucketName := insSimpleT.GetStringOutput("log_bucket_name")
3939
logSinkOrgId := insSimpleT.GetStringOutput("log_sink_organization_id")
4040
logSinkDestination := insSimpleT.GetStringOutput("log_sink_destination_uri")
41+
logSinkWriterId := insSimpleT.GetStringOutput("log_sink_writer_identity")
4142

42-
logBucketDetails := gcloud.Runf(t, fmt.Sprintf("logging buckets describe %s --location=%s --project=%s", logBucketName, "global", project_id))
43+
logBucketDetails := gcloud.Runf(t, fmt.Sprintf("logging buckets describe %s --location=%s --project=%s", logBucketName, "global", projectId))
4344

4445
// assert log bucket name, retention days & location
4546
assert.Equal(logSinkDestination[len(logApiFdqm)+1:], logBucketDetails.Get("name").String(), "log bucket name should match")
@@ -51,6 +52,9 @@ func TestLogBucketOrgModule(t *testing.T) {
5152
assert.Equal(logSinkDestination, logSinkDetails.Get("destination").String(), "log sink destination should match")
5253
assert.Equal("resource.type = gce_instance", logSinkDetails.Get("filter").String(), "log sink filter should match")
5354

55+
//assert writer id has the bucketWriter role
56+
logSinkServiceAccount := gcloud.Runf(t, "projects get-iam-policy %s --flatten bindings --filter bindings.role:roles/logging.bucketWriter", projectId)
57+
assert.Contains(logSinkServiceAccount.Array()[0].Get("bindings.members").String(), logSinkWriterId, "log sink SA has expected role")
5458
})
5559
insSimpleT.Test()
5660
}

0 commit comments

Comments
 (0)