Skip to content

Commit

Permalink
feat: add gh repo webhook stack
Browse files Browse the repository at this point in the history
  • Loading branch information
meysam81 committed Dec 7, 2024
1 parent 175ff30 commit de914e1
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .checkov_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
block-list-secret-scan: []
branch: main
download-external-modules: false
evaluate-variables: true
external-modules-download-path: .external_modules
framework:
- all
quiet: true
secrets-scan-file-type: []
skip-check:
- CKV_K8S_10 # CPU requests should be set
- CKV_K8S_11 # CPU limits should be set
- CKV_K8S_12 # Memory requests should be set
- CKV_K8S_13 # Memory limits should be set
- CKV_K8S_14 # Image Tag should be fixed - not latest or blank
- CKV_K8S_15 # Image Pull Policy should be Always
- CKV_K8S_21 # The default namespace should not be used
- CKV_K8S_38 # Ensure that Service Account Tokens are only mounted where necessary
- CKV_K8S_43 # Image should use digest
- CKV_K8S_49 # Minimize wildcard use in Roles and ClusterRoles
- CKV2_K8S_6 # Minimize the admission of pods which lack an associated NetworkPolicy

skip-framework: []
skip-path:
- ".*/kustomization\\.yml"
summary-position: bottom
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ terraform.rc
# End of https://www.toptal.com/developers/gitignore/api/Terraform

mkdocs
**/.terraform.lock.hcl
11 changes: 11 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create-tofu-stack dirname:
#!/usr/bin/env bash
mkdir -p $PWD/{{dirname}}
touch $PWD/{{dirname}}/{main,versions,variables,outputs}.tf

checkov:
checkov -c .checkov_config.yaml -d .

lint:
pre-commit run -a
41 changes: 41 additions & 0 deletions docs/github-repo-webhook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | < 2 |
| <a name="requirement_github"></a> [github](#requirement\_github) | < 7 |
| <a name="requirement_random"></a> [random](#requirement\_random) | < 5 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_github"></a> [github](#provider\_github) | 6.4.0 |
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [github_repository_webhook.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_webhook) | resource |
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_content_type"></a> [content\_type](#input\_content\_type) | The content type of the webhook | `string` | `"json"` | no |
| <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_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | The URL to send the webhook to | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_secret_value"></a> [secret\_value](#output\_secret\_value) | n/a |
43 changes: 43 additions & 0 deletions github-repo-webhook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | < 2 |
| <a name="requirement_github"></a> [github](#requirement\_github) | < 7 |
| <a name="requirement_random"></a> [random](#requirement\_random) | < 5 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_github"></a> [github](#provider\_github) | 6.4.0 |
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [github_repository_webhook.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_webhook) | resource |
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_content_type"></a> [content\_type](#input\_content\_type) | The content type of the webhook | `string` | `"json"` | no |
| <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_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | The URL to send the webhook to | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_secret_value"></a> [secret\_value](#output\_secret\_value) | n/a |
<!-- END_TF_DOCS -->
19 changes: 19 additions & 0 deletions github-repo-webhook/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "random_password" "this" {
length = var.secret_length
special = false
}

resource "github_repository_webhook" "this" {
repository = var.repository

configuration {
url = var.webhook_url
content_type = var.content_type
secret = random_password.this.result
insecure_ssl = false
}

active = true

events = var.events
}
4 changes: 4 additions & 0 deletions github-repo-webhook/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "secret_value" {
value = random_password.this.result
sensitive = true
}
29 changes: 29 additions & 0 deletions github-repo-webhook/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "secret_length" {
description = "The length of the webhook secret string"
type = number
default = 32
}

variable "repository" {
description = "The repository to add the webhook to"
type = string
nullable = false
}

variable "webhook_url" {
description = "The URL to send the webhook to"
type = string
nullable = false
}

variable "content_type" {
description = "The content type of the webhook"
type = string
default = "json"
}

variable "events" {
description = "The events to trigger the webhook"
type = list(string)
default = ["push"]
}
14 changes: 14 additions & 0 deletions github-repo-webhook/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "< 5"
}
github = {
source = "integrations/github"
version = "< 7"
}
}

required_version = "< 2"
}

0 comments on commit de914e1

Please sign in to comment.