Skip to content

Commit

Permalink
chore(gh-webhook): allow overriding the secret phrase
Browse files Browse the repository at this point in the history
Release-As: 0.2.1
  • Loading branch information
meysam81 committed Dec 17, 2024
1 parent 176e85c commit fe4b685
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/github-repo-webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ No modules.
| <a name="input_events"></a> [events](#input\_events) | The events to trigger the webhook | `list(string)` | <pre>[<br/> "push"<br/>]</pre> | no |
| <a name="input_repository"></a> [repository](#input\_repository) | The repository to add the webhook to | `string` | n/a | yes |
| <a name="input_secret_length"></a> [secret\_length](#input\_secret\_length) | The length of the webhook secret string | `number` | `32` | no |
| <a name="input_secret_phrase"></a> [secret\_phrase](#input\_secret\_phrase) | The secret phrase to use for the webhook secret (default: auto-generated) | `string` | `""` | no |
| <a name="input_special"></a> [special](#input\_special) | Whether to include special characters in the secret | `bool` | `false` | no |
| <a name="input_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | The URL to send the webhook to | `string` | n/a | yes |

## Outputs
Expand Down
2 changes: 2 additions & 0 deletions github-repo-webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ No modules.
| <a name="input_events"></a> [events](#input\_events) | The events to trigger the webhook | `list(string)` | <pre>[<br/> "push"<br/>]</pre> | no |
| <a name="input_repository"></a> [repository](#input\_repository) | The repository to add the webhook to | `string` | n/a | yes |
| <a name="input_secret_length"></a> [secret\_length](#input\_secret\_length) | The length of the webhook secret string | `number` | `32` | no |
| <a name="input_secret_phrase"></a> [secret\_phrase](#input\_secret\_phrase) | The secret phrase to use for the webhook secret (default: auto-generated) | `string` | `""` | no |
| <a name="input_special"></a> [special](#input\_special) | Whether to include special characters in the secret | `bool` | `false` | no |
| <a name="input_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | The URL to send the webhook to | `string` | n/a | yes |

## Outputs
Expand Down
3 changes: 3 additions & 0 deletions github-repo-webhook/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
create_secret = var.secret_phrase == "" ? true : false
}
6 changes: 4 additions & 2 deletions github-repo-webhook/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "random_password" "this" {
count = local.create_secret ? 1 : 0

length = var.secret_length
special = false
special = var.special
}

resource "github_repository_webhook" "this" {
Expand All @@ -9,7 +11,7 @@ resource "github_repository_webhook" "this" {
configuration {
url = var.webhook_url
content_type = var.content_type
secret = random_password.this.result
secret = local.create_secret ? random_password.this[0].result : var.secret_phrase
insecure_ssl = false
}

Expand Down
2 changes: 1 addition & 1 deletion github-repo-webhook/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "secret_value" {
value = random_password.this.result
value = try(random_password.this[0].result, null)
sensitive = true
}
12 changes: 12 additions & 0 deletions github-repo-webhook/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ variable "events" {
type = list(string)
default = ["push"]
}

variable "special" {
description = "Whether to include special characters in the secret"
type = bool
default = false
}

variable "secret_phrase" {
description = "The secret phrase to use for the webhook secret (default: auto-generated)"
type = string
default = ""
}
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ plugins:
version_selector: true
remote_branch: gh-pages
remote_name: origin
repo_name: meysam81/terraform-modules
repo_name: GitHub
repo_url: https://github.com/meysam81/terraform-modules
site_author: Meysam Azad <meysam@developer-friendly.blog>
site_description: This repo holds the Terraform modules that I have created and used in my projects.
Expand Down

0 comments on commit fe4b685

Please sign in to comment.