Skip to content

Commit 6716fa8

Browse files
committed
Added Github Module
1 parent 6ca5967 commit 6716fa8

File tree

5 files changed

+229
-0
lines changed

5 files changed

+229
-0
lines changed

examples/github.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
provider "github" {
2+
token = "<GITHUB_TOKEN>"
3+
organization = "<GITHUB_ORGANIZATION"
4+
}
5+
6+
### Github Module
7+
module "sumologic-jira-github-app" {
8+
source = "SumoLogic/integrations/sumologic//github"
9+
version = "{revision}"
10+
11+
sumo_access_id = "<SUMO_ACCESS_ID>"
12+
sumo_access_key = "<SUMO_ACCESS_KEY>"
13+
sumo_api_endpoint = "https://api.sumologic.com/api/v1/"
14+
collector_id = sumologic_collector.sumo_collector.id
15+
source_category = "Github"
16+
folder_id = sumologic_folder.folder.id
17+
github_repo_webhook_create = "true"
18+
github_org_webhook_create = "true"
19+
github_repository_names = ["<GITHUB_REPOSITORY_NAME1>", "<GITHUB_REPOSITORY_NAME2"]
20+
github_repo_events = ["create","delete","fork"] # By default all events are configured.
21+
github_org_events = ["create","delete","fork"] # By default all events are configured.
22+
app_version = "1.0"
23+
}

github/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Github
2+
3+
## Purpose
4+
5+
This module installs [Sumo Logic Github application](https://help.sumologic.com/07Sumo-Logic-Apps/08App_Development/Github) in Sumo Logic and configures Webhooks in Github to send events to Sumo Logic.
6+
7+
## Requirements
8+
9+
* [Terraform](https://www.terraform.io/downloads.html) >= 0.13.0
10+
* Null >= 2.1
11+
* Github >= 1.2
12+
13+
## Module Declaration
14+
15+
This module requires Sumo Logic collector Id and Folder id as explained [here](https://github.com/SumoLogic/terraform-sumologic-integrations#prerequisites-for-using-modules).
16+
17+
### Github Provider
18+
```shell
19+
provider "github" {
20+
token = "<GITHUB_TOKEN>"
21+
organization = "<GITHUB_ORGANIZATION"
22+
}
23+
```
24+
25+
### Github Module
26+
```shell
27+
module "sumologic-jira-github-app" {
28+
source = "SumoLogic/integrations/sumologic//github"
29+
version = "{revision}"
30+
31+
sumo_access_id = "<SUMO_ACCESS_ID>"
32+
sumo_access_key = "<SUMO_ACCESS_KEY>"
33+
sumo_api_endpoint = "https://api.sumologic.com/api/v1/"
34+
collector_id = sumologic_collector.sumo_collector.id
35+
source_category = "Github"
36+
folder_id = sumologic_folder.folder.id
37+
github_repo_webhook_create = "true"
38+
github_org_webhook_create = "true"
39+
github_repository_names = ["<GITHUB_REPOSITORY_NAME1>", "<GITHUB_REPOSITORY_NAME2"]
40+
github_repo_events = ["create","delete","fork"] # By default all events are configured.
41+
github_org_events = ["create","delete","fork"] # By default all events are configured.
42+
app_version = "1.0"
43+
}
44+
```
45+
46+
## Inputs
47+
48+
| Name | Description | Type | Default | Required |
49+
|------|-------------|------|---------|:-----:|
50+
|sumo_access_id|[Sumo Logic Access ID](https://help.sumologic.com/Manage/Security/Access-Keys)|string| |yes
51+
|sumo_access_key|[Sumo Logic Access Key](https://help.sumologic.com/Manage/Security/Access-Keys)|string| |yes
52+
|sumo_api_endpoint|[Sumo Logic API Endpoint](https://help.sumologic.com/APIs/General-API-Information/Sumo-Logic-Endpoints-and-Firewall-Security)|string|https://api.sumologic.com/api/v1/|yes
53+
|collector_id|Sumo Logic Collector ID|string| |yes
54+
|folder_id|Sumo Logic Folder ID|string| |yes
55+
|source_category|Github Source Category|string|Github|yes
56+
|github_token|[Github Token.](https://github.com/settings/tokens)|string| |yes
57+
|github_repo_webhook_create|Create webhooks at repo level. Default "true".|string|true|no
58+
|github_org_webhook_create|Create webhooks at org level. Default "false".|string|false|no
59+
|github_organization|Organization Name.|string| |yes
60+
|github_repository_names|List of repository names for which webhooks need to be created. Example, ["repo1","repo2"]|list| |yes
61+
|github_repo_events|List of repository [events](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads) which should be sent to Sumo Logic. Example, ["create","delete","fork"]|list|List of all the Github Repo Events|yes
62+
|github_org_events|List of organization level [events](https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads) which should be sent to Sumo Logic. Example, ["create","delete","fork"]|string|List of all the Github Org Events|yes
63+
|app_version|The app_version input parameter can be used to install a new copy of the app. When the app_version field is changed, it will force Terraform to install a new app folder with the current timestamp.|String|1.0|no

github/inputs.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Github
2+
variable "sumo_access_id" {
3+
type = string
4+
description = "Sumo Logic Access ID"
5+
}
6+
variable "sumo_access_key" {
7+
type = string
8+
description = "Sumo Logic Access Key"
9+
}
10+
variable "sumo_api_endpoint" {
11+
type = string
12+
description = "Sumo Logic Endpoint"
13+
default = "https://api.sumologic.com/api/v1/"
14+
}
15+
variable "collector_id" {
16+
type = string
17+
description = "Sumo Logic Collector ID"
18+
}
19+
variable "source_category" {
20+
type = string
21+
description = "Sumo Logic Github Source Category"
22+
default = "Github"
23+
}
24+
variable "folder_id" {
25+
type = string
26+
description = "Sumo Logic Content Folder ID"
27+
}
28+
variable "github_repository_names" {
29+
type = list
30+
description = "Github Repositories"
31+
default = []
32+
}
33+
variable "github_repo_events" {
34+
type = list
35+
description = "Github Repository Events"
36+
default = ["check_run", "check_suite", "commit_comment", "create", "delete", "deploy_key", "deployment",
37+
"deployment_status", "fork",
38+
"gollum", "issue_comment", "issues", "label", "member", "meta", "milestone", "package", "page_build", "ping", "project_card",
39+
"project_column", "project", "public", "pull_request", "pull_request_review", "pull_request_review_comment",
40+
"push", "release", "repository", "repository_import", "repository_vulnerability_alert", "star", "status", "team_add", "watch"]
41+
}
42+
variable "github_org_events" {
43+
type = list
44+
description = "Github Organization Events"
45+
default = ["check_run", "check_suite", "commit_comment", "create", "delete", "deploy_key", "deployment",
46+
"deployment_status", "fork", "gollum", "issue_comment", "issues", "label", "member",
47+
"membership", "meta", "milestone", "organization", "org_block", "package", "page_build", "ping", "project_card",
48+
"project_column", "project", "public", "pull_request", "pull_request_review", "pull_request_review_comment",
49+
"push", "release", "repository", "repository_import", "repository_vulnerability_alert", "star", "status", "team", "team_add", "watch"]
50+
}
51+
variable "github_org_webhook_create" {
52+
type = string
53+
description = "Create Webhooks at Organization Level"
54+
default = "false"
55+
}
56+
variable "github_repo_webhook_create" {
57+
type = string
58+
description = "Create Webhooks at Repository Level"
59+
default = "true"
60+
}
61+
variable "app_version" {
62+
type = string
63+
description = "App Version"
64+
default = "1.0"
65+
}

github/main.tf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Create/Delete Github Source
2+
resource "sumologic_http_source" "github" {
3+
name = "Github"
4+
category = var.source_category
5+
fields = { "_convertHeadersToFields" = "true" }
6+
collector_id = var.collector_id
7+
}
8+
9+
# Repository Level Webhook
10+
resource "github_repository_webhook" "github_sumologic_repo_webhook" {
11+
count = "${var.github_repo_webhook_create}" ? length(var.github_repository_names) : 0
12+
repository = var.github_repository_names[count.index]
13+
14+
configuration {
15+
url = sumologic_http_source.github.url
16+
content_type = "json"
17+
insecure_ssl = false
18+
}
19+
20+
active = true
21+
22+
events = var.github_repo_events
23+
}
24+
25+
# Organization Level Webhook
26+
resource "github_organization_webhook" "github_sumologic_org_webhook" {
27+
count = "${var.github_org_webhook_create}" ? 1 : 0
28+
29+
configuration {
30+
url = sumologic_http_source.github.url
31+
content_type = "json"
32+
insecure_ssl = false
33+
}
34+
35+
active = true
36+
37+
events = var.github_org_events
38+
}
39+
40+
# Generate timestamp to add to the folder name.
41+
locals {
42+
time_stamp = formatdate("DD-MMM-YYYY hh:mm:ss", timestamp())
43+
}
44+
45+
# Install Github App
46+
resource "null_resource" "install_github_app" {
47+
depends_on = [sumologic_http_source.github]
48+
triggers = {
49+
version = var.app_version
50+
}
51+
52+
provisioner "local-exec" {
53+
command = <<EOT
54+
curl -s --request POST '${var.sumo_api_endpoint}/v1/apps/86289912-b909-426e-8154-bda55b9ee902/install' \
55+
--header 'Accept: application/json' \
56+
--header 'Content-Type: application/json' \
57+
-u ${var.sumo_access_id}:${var.sumo_access_key} \
58+
--data-raw '{ "name": "Github - ${local.time_stamp}", "description": "The Sumo Logic App for GitHub connects to your GitHub repository at the Organization or Repository level, and ingests GitHub events via a webhook.", "destinationFolderId": "${var.folder_id}","dataSourceValues": {"paramId123": "_sourceCategory = ${var.source_category}"}}'
59+
EOT
60+
}
61+
}

github/versions.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
terraform {
2+
required_version = ">= 0.13.0"
3+
4+
required_providers {
5+
null = {
6+
version = "~> 2.1"
7+
}
8+
github = {
9+
source = "hashicorp/github"
10+
version = "~> 2.8"
11+
}
12+
sumologic = {
13+
version = "~> 2.1.0"
14+
source = "SumoLogic/sumologic"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)