Skip to content

Commit ac2d575

Browse files
authored
Merge pull request #9 from parabolic/Add_a_gcp_sumologic_module_for_cloudlogging
Add_a_gcp_sumologic_module_for_cloudlogging
2 parents 2a54c51 + 17faf6f commit ac2d575

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

gcp/cloudlogging/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SumoLogic-GCP-Logging
2+
3+
4+
This module is used to create GCP and Sumo Logic resources to collect logs from the [Cloud Logging] service in GCP.
5+
Features include:
6+
- Create a Sumologic source and a collector
7+
- Create a PubSub Topic and a Subscription
8+
- Create a Cloud Logging Sink
9+
- Assign the pubsub.publisher role to the Cloud Logging service account
10+
11+
For examples please check the [example] folder.
12+
13+
<!-- Links -->
14+
[Cloud Logging]:https://cloud.google.com/logging
15+
[example]:(example)
16+
17+
## Requirements
18+
19+
| Name | Version |
20+
|------|---------|
21+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
22+
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 4.0 |
23+
| <a name="requirement_sumologic"></a> [sumologic](#requirement\_sumologic) | >= 2.11 |
24+
25+
## Providers
26+
27+
| Name | Version |
28+
|------|---------|
29+
| <a name="provider_google"></a> [google](#provider\_google) | >= 4.0 |
30+
| <a name="provider_sumologic"></a> [sumologic](#provider\_sumologic) | >= 2.11 |
31+
32+
## Modules
33+
34+
No modules.
35+
36+
## Resources
37+
38+
| Name | Type |
39+
|------|------|
40+
| [google_logging_project_sink.sumologic](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/logging_project_sink) | resource |
41+
| [google_project_iam_binding.sumologic](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_binding) | resource |
42+
| [google_pubsub_subscription.sumologic](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription) | resource |
43+
| [google_pubsub_topic.sumologic](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_topic) | resource |
44+
| [sumologic_collector.this](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/collector) | resource |
45+
| [sumologic_gcp_source.this](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/gcp_source) | resource |
46+
47+
## Inputs
48+
49+
| Name | Description | Type | Default | Required |
50+
|------|-------------|------|---------|:--------:|
51+
| <a name="input_gcp_project"></a> [gcp\_project](#input\_gcp\_project) | GCP project ID. | `string` | n/a | yes |
52+
| <a name="input_logging_sink_filter"></a> [logging\_sink\_filter](#input\_logging\_sink\_filter) | Logging filter for the GCP sink. | `string` | `null` | no |
53+
| <a name="input_name"></a> [name](#input\_name) | Names that will be assigned to resources. | `string` | n/a | yes |
54+
| <a name="input_sumologic_category"></a> [sumologic\_category](#input\_sumologic\_category) | The category description for the collector/source. | `string` | `"gcp"` | no |
55+
| <a name="input_sumologic_collector_fields"></a> [sumologic\_collector\_fields](#input\_sumologic\_collector\_fields) | A Map containing key/value pairs. | `map(any)` | `null` | no |
56+
| <a name="input_sumologic_collector_name"></a> [sumologic\_collector\_name](#input\_sumologic\_collector\_name) | Name for the collector. | `string` | `null` | no |
57+
| <a name="input_sumologic_collector_timezone"></a> [sumologic\_collector\_timezone](#input\_sumologic\_collector\_timezone) | The time zone to use for this collector. | `string` | `null` | no |
58+
| <a name="input_sumologic_description"></a> [sumologic\_description](#input\_sumologic\_description) | The description of the created resources collector/source. | `string` | `null` | no |
59+
| <a name="input_sumologic_source_name"></a> [sumologic\_source\_name](#input\_sumologic\_source\_name) | Name for the GCP source. | `string` | `null` | no |
60+
61+
## Outputs
62+
63+
No outputs.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
locals {
2+
project = "some-project-name"
3+
name = "sumologic"
4+
}
5+
6+
module "sumologic" {
7+
source = "../.."
8+
9+
name = local.name
10+
gcp_project = local.project
11+
12+
}

gcp/cloudlogging/gcp.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
resource "google_project_iam_binding" "sumologic" {
2+
project = var.gcp_project
3+
4+
role = "roles/pubsub.publisher"
5+
6+
members = [
7+
"serviceAccount:[email protected]"
8+
]
9+
}
10+
11+
resource "google_logging_project_sink" "sumologic" {
12+
project = var.gcp_project
13+
14+
name = var.name
15+
16+
destination = "pubsub.googleapis.com/${google_pubsub_topic.sumologic.id}"
17+
18+
filter = var.logging_sink_filter
19+
}
20+
21+
resource "google_pubsub_subscription" "sumologic" {
22+
project = var.gcp_project
23+
24+
name = var.name
25+
topic = google_pubsub_topic.sumologic.name
26+
27+
ack_deadline_seconds = 20
28+
29+
push_config {
30+
push_endpoint = sumologic_gcp_source.this.url
31+
}
32+
}
33+
34+
resource "google_pubsub_topic" "sumologic" {
35+
project = var.gcp_project
36+
37+
name = var.name
38+
}

gcp/cloudlogging/sumologic.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
locals {
2+
sumologic_collector_name = var.sumologic_collector_name == null ? var.name : var.sumologic_collector_name
3+
sumologic_source_name = var.sumologic_source_name == null ? var.name : var.sumologic_source_name
4+
}
5+
resource "sumologic_collector" "this" {
6+
name = local.sumologic_collector_name
7+
description = var.sumologic_description
8+
9+
category = var.sumologic_category
10+
fields = var.sumologic_collector_fields
11+
}
12+
13+
resource "sumologic_gcp_source" "this" {
14+
name = local.sumologic_source_name
15+
description = var.sumologic_description
16+
17+
collector_id = sumologic_collector.this.id
18+
category = var.sumologic_category
19+
}

gcp/cloudlogging/variables.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
variable "gcp_project" {
2+
description = "GCP project ID."
3+
type = string
4+
}
5+
6+
variable "logging_sink_filter" {
7+
description = "Logging filter for the GCP sink."
8+
type = string
9+
default = null
10+
}
11+
12+
variable "name" {
13+
description = "Names that will be assigned to resources."
14+
type = string
15+
}
16+
17+
variable "sumologic_category" {
18+
description = "The category description for the collector/source."
19+
type = string
20+
default = "gcp"
21+
}
22+
23+
variable "sumologic_collector_fields" {
24+
description = "A Map containing key/value pairs."
25+
type = map(any)
26+
default = null
27+
}
28+
29+
variable "sumologic_collector_name" {
30+
description = "Name for the collector."
31+
type = string
32+
default = null
33+
}
34+
35+
variable "sumologic_collector_timezone" {
36+
description = "The time zone to use for this collector."
37+
type = string
38+
default = null
39+
}
40+
41+
variable "sumologic_description" {
42+
description = "The description of the created resources collector/source."
43+
type = string
44+
default = null
45+
}
46+
47+
variable "sumologic_source_name" {
48+
description = "Name for the GCP source."
49+
type = string
50+
default = null
51+
}

gcp/cloudlogging/versions.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = ">= 4.0"
6+
}
7+
sumologic = {
8+
source = "SumoLogic/sumologic"
9+
version = ">= 2.11"
10+
}
11+
}
12+
required_version = ">= 0.13"
13+
}

0 commit comments

Comments
 (0)