Skip to content

Commit 9eaa9b5

Browse files
authored
Merge pull request #18 from kiran002/master
Support aggregated log exports (#13)
2 parents 11ed38f + 4abdf02 commit 9eaa9b5

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

modules/event-project-log-entry/main.tf

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
locals {
17+
destination_uri = "pubsub.googleapis.com/projects/${var.project_id}/topics/${local.topic_name}"
18+
topic_name = "${element(concat(google_pubsub_topic.main.*.name, list("")), 0)}"
19+
}
20+
21+
module "log_export" {
22+
source = "terraform-google-modules/log-export/google"
23+
destination_uri = "${local.destination_uri}"
24+
filter = "${var.filter}"
25+
log_sink_name = "${var.name}"
26+
parent_resource_id = "${var.project_id}"
27+
parent_resource_type = "${var.parent_resource_type}"
28+
unique_writer_identity = "true"
29+
}
1630

1731
resource "google_pubsub_topic" "main" {
1832
name = "${var.name}"
1933
labels = "${var.labels}"
2034
project = "${var.project_id}"
2135
}
2236

23-
resource "google_logging_project_sink" "main" {
24-
name = "${var.name}"
25-
destination = "pubsub.googleapis.com/${google_pubsub_topic.main.id}"
26-
filter = "${var.filter}"
27-
project = "${var.project_id}"
28-
unique_writer_identity = true
29-
}
30-
3137
resource "google_pubsub_topic_iam_member" "main" {
3238
topic = "${google_pubsub_topic.main.name}"
33-
project = "${google_logging_project_sink.main.project}"
34-
member = "${google_logging_project_sink.main.writer_identity}"
39+
project = "${var.project_id}"
40+
member = "${module.log_export.writer_identity}"
3541
role = "roles/pubsub.publisher"
3642
}
43+

modules/event-project-log-entry/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ variable "project_id" {
3434
type = "string"
3535
description = "The ID of the project to which resources will be applied."
3636
}
37+
38+
variable "parent_resource_type" {
39+
type = "string"
40+
default = "project"
41+
description = "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'."
42+
}

0 commit comments

Comments
 (0)