Skip to content

Commit f5dfb70

Browse files
authored
Added webhook support (#20)
* feat: added webhook and build configs support * refactor: rename webhook_urls to webhooks - Updated README.md to reflect the new variable name - Modified main.tf to use the new variable name - Changed the variable name in variables.tf to webhooks
1 parent 3c38561 commit f5dfb70

File tree

12 files changed

+129
-107
lines changed

12 files changed

+129
-107
lines changed

.github/renovate.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:base",
5+
":semanticCommitTypeAll(chore)"
6+
],
7+
"lockFileMaintenance": {
8+
"enabled": true,
9+
"extends": [
10+
"schedule:weekly"
11+
]
12+
},
13+
"nix": {
14+
"enabled": true
15+
}
16+
}

.github/workflows/flake.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/terraform.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: terraform
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
CACHIX_BINARY_CACHE: altf4llc-os
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: cachix/install-nix-action@v27
17+
with:
18+
nix_path: nixpkgs=channel:nixos-unstable
19+
- uses: cachix/cachix-action@v15
20+
with:
21+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
22+
name: ${{ env.CACHIX_BINARY_CACHE }}
23+
- uses: actions/checkout@v4
24+
- run: nix develop -c just check
25+
26+
package:
27+
needs:
28+
- check
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: cachix/install-nix-action@v27
32+
with:
33+
nix_path: nixpkgs=channel:nixos-unstable
34+
- uses: cachix/cachix-action@v15
35+
with:
36+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
37+
name: ${{ env.CACHIX_BINARY_CACHE }}
38+
- uses: actions/checkout@v4
39+
- run: nix develop -c just package

.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
# Nix directories
21
.direnv
3-
result
2+
*.tfplan
43

54
# Local .terraform directories
65
**/.terraform/*
76

8-
# Terraform lockfile
9-
.terraform.lock.hcl
10-
117
# .tfstate files
128
*.tfstate
139
*.tfstate.*
@@ -17,8 +13,8 @@ crash.log
1713
crash.*.log
1814

1915
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
20-
# password, private keys, and other secrets. These should not be part of version
21-
# control as they are data points which are potentially sensitive and subject
16+
# password, private keys, and other secrets. These should not be part of version
17+
# control as they are data points which are potentially sensitive and subject
2218
# to change depending on the environment.
2319
*.tfvars
2420
*.tfvars.json
@@ -39,3 +35,4 @@ override.tf.json
3935
# Ignore CLI configuration files
4036
.terraformrc
4137
terraform.rc
38+
.terraform.lock.hcl

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ teams = { "1234567890" = "maintain" }
1919

2020
| Name | Version |
2121
|------|---------|
22-
| <a name="requirement_github"></a> [github](#requirement\_github) | 6.0.0 |
22+
| <a name="requirement_github"></a> [github](#requirement\_github) | ~> 6.0 |
2323

2424
## Providers
2525

2626
| Name | Version |
2727
|------|---------|
28-
| <a name="provider_github"></a> [github](#provider\_github) | 6.0.0 |
28+
| <a name="provider_github"></a> [github](#provider\_github) | ~> 6.0 |
2929

3030
## Modules
3131

@@ -35,9 +35,10 @@ No modules.
3535

3636
| Name | Type |
3737
|------|------|
38-
| [github_branch_protection.self](https://registry.terraform.io/providers/integrations/github/6.0.0/docs/resources/branch_protection) | resource |
39-
| [github_repository.self](https://registry.terraform.io/providers/integrations/github/6.0.0/docs/resources/repository) | resource |
40-
| [github_team_repository.self](https://registry.terraform.io/providers/integrations/github/6.0.0/docs/resources/team_repository) | resource |
38+
| [github_branch_protection.self](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection) | resource |
39+
| [github_repository.self](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource |
40+
| [github_repository_webhook.self](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_webhook) | resource |
41+
| [github_team_repository.self](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_repository) | resource |
4142

4243
## Inputs
4344

@@ -71,6 +72,7 @@ No modules.
7172
| <a name="input_topics"></a> [topics](#input\_topics) | The topics of the repository | `list(string)` | `[]` | no |
7273
| <a name="input_visibility"></a> [visibility](#input\_visibility) | The visibility of the repository | `string` | `"private"` | no |
7374
| <a name="input_vulnerability_alerts"></a> [vulnerability\_alerts](#input\_vulnerability\_alerts) | Whether the repository has vulnerability alerts enabled | `bool` | `false` | no |
75+
| <a name="input_webhooks"></a> [webhooks](#input\_webhooks) | The URLs of the webhooks | <pre>list(object({<br> active = bool<br> events = list(string)<br> content_type = string<br> url = string<br> }))</pre> | `[]` | no |
7476

7577
## Outputs
7678

build-configs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: terraform-github-repository
3+
template: terraform-module
4+
parameters:
5+
nix:
6+
cachix:
7+
binaryCache: altf4llc-os
8+
providers:
9+
- github

flake.lock

Lines changed: 13 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
{
2-
description = "terraform-github-repository";
3-
4-
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
53

64
outputs = inputs @ {
75
flake-parts,
86
nixpkgs,
97
...
108
}:
119
flake-parts.lib.mkFlake {inherit inputs;} {
12-
systems = ["x86_64-linux" "aarch64-darwin" "x86_64-darwin"];
10+
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
11+
1312
perSystem = {
1413
config,
15-
self',
16-
inputs',
1714
pkgs,
1815
system,
1916
...
2017
}: let
21-
inherit (pkgs) just terraform-docs;
22-
terraform = pkgs.terraform.withPlugins (p: [
23-
(pkgs.terraform-providers.mkProvider {
24-
hash = "sha256-y8DMpNSySMbe7E+sGVQcQdEyulq4Wnp5ryYD7FQO/fc=";
25-
homepage = "https://registry.terraform.io/providers/integrations/github";
26-
owner = "integrations";
27-
repo = "terraform-provider-github";
28-
rev = "v6.0.0";
29-
vendorHash = null;
30-
})
18+
inherit (pkgs) just mkShell terraform-docs;
19+
terraform = pkgs.terraform.withPlugins (ps: [
20+
ps.github
3121
]);
3222
in {
3323
_module.args.pkgs = import nixpkgs {
@@ -36,10 +26,10 @@
3626
};
3727

3828
devShells = {
39-
default = pkgs.mkShell {
40-
buildInputs = [
29+
default = mkShell {
30+
inputsFrom = [config.packages.default];
31+
nativeBuildInputs = [
4132
just
42-
terraform
4333
terraform-docs
4434
];
4535
};
@@ -49,13 +39,13 @@
4939
default =
5040
pkgs.runCommand "default"
5141
{
42+
nativeBuildInputs = [terraform];
5243
src = ./.;
5344
} ''
5445
mkdir -p $out
5546
cp -R $src/*.tf $out
56-
57-
${terraform}/bin/terraform -chdir="$out" init
58-
${terraform}/bin/terraform -chdir="$out" validate
47+
terraform -chdir="$out" init
48+
terraform -chdir="$out" validate
5949
'';
6050
};
6151
};

justfile

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
_default:
22
just --list
33

4-
build:
5-
nix build --json --no-link --print-build-logs
6-
7-
cache-build cache_name="altf4llc-os":
8-
just build \
9-
| jq -r '.[].outputs | to_entries[].value' \
10-
| cachix push {{ cache_name }}
11-
12-
cache-inputs cache_name="altf4llc-os":
13-
nix flake archive --json \
14-
| jq -r '.path,(.inputs|to_entries[].value.path)' \
15-
| cachix push "{{ cache_name }}"
16-
17-
cache-shell cache_name="altf4llc-os":
18-
nix develop --profile "dev-profile" -c true
19-
cachix push "{{ cache_name }}" "dev-profile"
20-
214
check:
225
nix flake check
236

@@ -29,5 +12,8 @@ docs:
2912
init:
3013
terraform init
3114

15+
package:
16+
nix build --json --no-link --print-build-logs .
17+
3218
validate:
3319
terraform validate

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ resource "github_branch_protection" "self" {
6464
required_approving_review_count = var.required_approving_review_count
6565
}
6666
}
67+
68+
resource "github_repository_webhook" "self" {
69+
for_each = toset(var.webhooks)
70+
71+
active = each.value.active
72+
events = each.value.events
73+
repository = github_repository.self.name
74+
75+
configuration {
76+
content_type = each.value.content_type
77+
insecure_ssl = false
78+
url = each.value.url
79+
}
80+
}

0 commit comments

Comments
 (0)