Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 525f400

Browse files
npalmgithub-actions[bot]GuptaNavdeep1983
authored
feat: add module to update GitHub app webhook (#3451)
## Description Setting up the runners are requiring typically three steps 1. Create the GitHub App 2. Run terraform with App details 3. Update the GitHub App webhook. This PR adds a module that let you update the App webhook endpoint and secret via a terraform module. Usages is sown in the examples. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Navdeep Gupta <[email protected]>
1 parent 99ff767 commit 525f400

File tree

20 files changed

+313
-34
lines changed

20 files changed

+313
-34
lines changed

Diff for: examples/arm64/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Be aware some shells will print some end of line character `%`.
5252
|------|--------|---------|
5353
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
5454
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
55+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
5556

5657
## Resources
5758

Diff for: examples/arm64/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ module "runners" {
8686
# override scaling down
8787
scale_down_schedule_expression = "cron(* * * * ? *)"
8888
}
89+
90+
module "webhook-github-app" {
91+
source = "../../modules/webhook-github-app"
92+
93+
github_app = {
94+
key_base64 = var.github_app.key_base64
95+
id = var.github_app.id
96+
webhook_secret = random_id.random.hex
97+
}
98+
webhook_endpoint = module.runners.webhook.endpoint
99+
}

Diff for: examples/default/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ terraform init
2222
terraform apply
2323
```
2424

25-
You can receive the webhook details by running:
25+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
2626

2727
```bash
28-
terraform output -raw webhook_secret
28+
terraform output webhook_secret
2929
```
3030

31-
Be aware some shells will print some end of line character `%`.
32-
3331
<!-- BEGIN_TF_DOCS -->
3432
## Requirements
3533

@@ -52,6 +50,7 @@ Be aware some shells will print some end of line character `%`.
5250
|------|--------|---------|
5351
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
5452
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
53+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
5554

5655
## Resources
5756

Diff for: examples/default/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,14 @@ module "runners" {
9797
# Enable debug logging for the lambda functions
9898
# log_level = "debug"
9999
}
100+
101+
module "webhook-github-app" {
102+
source = "../../modules/webhook-github-app"
103+
104+
github_app = {
105+
key_base64 = var.github_app.key_base64
106+
id = var.github_app.id
107+
webhook_secret = random_id.random.hex
108+
}
109+
webhook_endpoint = module.runners.webhook.endpoint
110+
}

Diff for: examples/ephemeral/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ terraform init
2121
terraform apply
2222
```
2323

24-
You can receive the webhook details by running:
24+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
2525

2626
```bash
27-
terraform output -raw webhook_secret
27+
terraform output webhook_secret
2828
```
2929

30-
Be aware some shells will print some end of line character `%`.
3130
<!-- BEGIN_TF_DOCS -->
3231
## Requirements
3332

@@ -50,6 +49,7 @@ Be aware some shells will print some end of line character `%`.
5049
|------|--------|---------|
5150
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
5251
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
52+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
5353

5454
## Resources
5555

Diff for: examples/ephemeral/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,14 @@ module "runners" {
8585
# deadLetterTargetArn = null
8686
# }
8787
}
88+
89+
module "webhook-github-app" {
90+
source = "../../modules/webhook-github-app"
91+
92+
github_app = {
93+
key_base64 = var.github_app.key_base64
94+
id = var.github_app.id
95+
webhook_secret = random_id.random.hex
96+
}
97+
webhook_endpoint = module.runners.webhook.endpoint
98+
}

Diff for: examples/multi-runner/.terraform.lock.hcl

+35-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/multi-runner/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ terraform init
3939
terraform apply
4040
```
4141

42-
You can receive the webhook details by running:
42+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
4343

4444
```bash
45-
terraform output -raw webhook_secret
45+
terraform output webhook_secret
4646
```
4747

48-
Be aware some shells will print some end of line character `%`.
49-
5048
<!-- BEGIN_TF_DOCS -->
5149
## Requirements
5250

@@ -69,6 +67,7 @@ Be aware some shells will print some end of line character `%`.
6967
|------|--------|---------|
7068
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
7169
| <a name="module_multi-runner"></a> [multi-runner](#module\_multi-runner) | ../../modules/multi-runner | n/a |
70+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
7271

7372
## Resources
7473

Diff for: examples/multi-runner/main.tf

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ locals {
99
resource "random_id" "random" {
1010
byte_length = 20
1111
}
12+
1213
module "base" {
1314
source = "../base"
1415

@@ -46,3 +47,14 @@ module "multi-runner" {
4647
# Enable debug logging for the lambda functions
4748
# log_level = "debug"
4849
}
50+
51+
module "webhook-github-app" {
52+
source = "../../modules/webhook-github-app"
53+
54+
github_app = {
55+
key_base64 = var.github_app.key_base64
56+
id = var.github_app.id
57+
webhook_secret = random_id.random.hex
58+
}
59+
webhook_endpoint = module.multi-runner.webhook.endpoint
60+
}

Diff for: examples/prebuilt/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ terraform init
8686
terraform apply
8787
```
8888

89-
You can receive the webhook details by running:
89+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
9090

9191
```bash
92-
terraform output -raw webhook_secret
92+
terraform output webhook_secret
9393
```
9494

95-
Be aware some shells will print some end of line character `%`.
96-
9795
<!-- BEGIN_TF_DOCS -->
9896
## Requirements
9997

@@ -117,6 +115,7 @@ Be aware some shells will print some end of line character `%`.
117115
|------|--------|---------|
118116
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
119117
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
118+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
120119

121120
## Resources
122121

Diff for: examples/prebuilt/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@ module "runners" {
6161
# override scaling down
6262
scale_down_schedule_expression = "cron(* * * * ? *)"
6363
}
64+
65+
module "webhook-github-app" {
66+
source = "../../modules/webhook-github-app"
67+
68+
github_app = {
69+
key_base64 = var.github_app.key_base64
70+
id = var.github_app.id
71+
webhook_secret = random_id.random.hex
72+
}
73+
webhook_endpoint = module.runners.webhook.endpoint
74+
}

Diff for: examples/ubuntu/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ terraform init
2323
terraform apply
2424
```
2525

26+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
27+
28+
```bash
29+
terraform output webhook_secret
30+
```
31+
2632
<!-- BEGIN_TF_DOCS -->
2733
## Requirements
2834

@@ -45,6 +51,7 @@ terraform apply
4551
|------|--------|---------|
4652
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
4753
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
54+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
4855

4956
## Resources
5057

@@ -65,4 +72,4 @@ terraform apply
6572
| <a name="output_runners"></a> [runners](#output\_runners) | n/a |
6673
| <a name="output_webhook_endpoint"></a> [webhook\_endpoint](#output\_webhook\_endpoint) | n/a |
6774
| <a name="output_webhook_secret"></a> [webhook\_secret](#output\_webhook\_secret) | n/a |
68-
<!-- END_TF_DOCS -->
75+
<!-- END_TF_DOCS -->

Diff for: examples/ubuntu/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,14 @@ module "runners" {
111111
# Enable logging all commands of user_data, secrets will be logged!!!
112112
# enable_user_data_debug_logging_runner = true
113113
}
114+
115+
module "webhook-github-app" {
116+
source = "../../modules/webhook-github-app"
117+
118+
github_app = {
119+
key_base64 = var.github_app.key_base64
120+
id = var.github_app.id
121+
webhook_secret = random_id.random.hex
122+
}
123+
webhook_endpoint = module.runners.webhook.endpoint
124+
}

Diff for: examples/windows/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ terraform apply
2525

2626
_**Note**_: It can take upwards of ten minutes for a runner to start processing jobs, and about as long for logs to start showing up. It's recommend that scale the runners via a warm-up job and then keep them idled.
2727

28+
The module will try to update the GitHub App webhook and secret (only linux/mac). You can receive the webhook details by running:
29+
30+
```bash
31+
terraform output webhook_secret
32+
```
33+
2834
<!-- BEGIN_TF_DOCS -->
2935
## Requirements
3036

@@ -47,6 +53,7 @@ _**Note**_: It can take upwards of ten minutes for a runner to start processing
4753
|------|--------|---------|
4854
| <a name="module_base"></a> [base](#module\_base) | ../base | n/a |
4955
| <a name="module_runners"></a> [runners](#module\_runners) | ../../ | n/a |
56+
| <a name="module_webhook-github-app"></a> [webhook-github-app](#module\_webhook-github-app) | ../../modules/webhook-github-app | n/a |
5057

5158
## Resources
5259

@@ -67,4 +74,4 @@ _**Note**_: It can take upwards of ten minutes for a runner to start processing
6774
| <a name="output_runners"></a> [runners](#output\_runners) | n/a |
6875
| <a name="output_webhook_endpoint"></a> [webhook\_endpoint](#output\_webhook\_endpoint) | n/a |
6976
| <a name="output_webhook_secret"></a> [webhook\_secret](#output\_webhook\_secret) | n/a |
70-
<!-- END_TF_DOCS -->
77+
<!-- END_TF_DOCS -->

Diff for: examples/windows/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,14 @@ module "runners" {
5353
# override scaling down for testing
5454
scale_down_schedule_expression = "cron(* * * * ? *)"
5555
}
56+
57+
module "webhook-github-app" {
58+
source = "../../modules/webhook-github-app"
59+
60+
github_app = {
61+
key_base64 = var.github_app.key_base64
62+
id = var.github_app.id
63+
webhook_secret = random_id.random.hex
64+
}
65+
webhook_endpoint = module.runners.webhook.endpoint
66+
}

Diff for: modules/webhook-github-app/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Module - Update GitHub App Webhook
2+
3+
> This module is using the local executor to run a bash script.
4+
5+
This module updates the GitHub App webhook with the endpoint and secret and can be changed with the root module. See the examples for usages.
6+
7+
<!-- BEGIN_TF_DOCS -->
8+
## Requirements
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
13+
| <a name="requirement_null"></a> [null](#requirement\_null) | ~> 3 |
14+
15+
## Providers
16+
17+
| Name | Version |
18+
|------|---------|
19+
| <a name="provider_null"></a> [null](#provider\_null) | ~> 3 |
20+
21+
## Modules
22+
23+
No modules.
24+
25+
## Resources
26+
27+
| Name | Type |
28+
|------|------|
29+
| [null_resource.update_app](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
30+
31+
## Inputs
32+
33+
| Name | Description | Type | Default | Required |
34+
|------|-------------|------|---------|:--------:|
35+
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub app parameters, see your github app. Ensure the key is the base64-encoded `.pem` file (the output of `base64 app.private-key.pem`, not the content of `private-key.pem`). | <pre>object({<br> key_base64 = string<br> id = string<br> webhook_secret = string<br> })</pre> | n/a | yes |
36+
| <a name="input_webhook_endpoint"></a> [webhook\_endpoint](#input\_webhook\_endpoint) | The endpoint to use for the webhook, defaults to the endpoint of the runners module. | `string` | n/a | yes |
37+
38+
## Outputs
39+
40+
No outputs.
41+
<!-- END_TF_DOCS -->

0 commit comments

Comments
 (0)