feat: CDKTF | migrate DNS system to cdktf

This commit is contained in:
2025-07-15 11:25:22 +05:00
parent 5b352cbb7e
commit 910f1d06a3
4 changed files with 53 additions and 4 deletions

1
.envrc
View File

@@ -1,2 +1 @@
use flake use flake
export SHELL=$(which bash)

View File

@@ -3,7 +3,7 @@ provider: pihole
policy: upsert-only policy: upsert-only
txtOwnerId: "homelab" txtOwnerId: "homelab"
pihole: pihole:
server: https://pihole.dogar.dev server: http://pihole-web.pihole-system.svc.cluster.local
extraEnvVars: extraEnvVars:
- name: EXTERNAL_DNS_PIHOLE_PASSWORD - name: EXTERNAL_DNS_PIHOLE_PASSWORD
valueFrom: valueFrom:

12
main.ts
View File

@@ -13,6 +13,7 @@ import { AuthentikServer } from "./authentik";
import { RedisCluster } from "./redis"; import { RedisCluster } from "./redis";
import { CertManager } from "./cert-manager"; import { CertManager } from "./cert-manager";
import { Manifest } from "@cdktf/provider-kubernetes/lib/manifest"; import { Manifest } from "@cdktf/provider-kubernetes/lib/manifest";
import { PiHole } from "./pihole";
dotenv.config(); dotenv.config();
@@ -55,8 +56,6 @@ class Homelab extends TerraformStack {
}, },
}); });
const certManagerApiVersion = "cert-manager.io/v1";
new Longhorn(this, "longhorn", { new Longhorn(this, "longhorn", {
namespace: "longhorn-system", namespace: "longhorn-system",
name: "longhorn", name: "longhorn",
@@ -67,6 +66,15 @@ class Homelab extends TerraformStack {
}, },
}); });
new PiHole(this, "pihole", {
namespace: "pihole-system",
provider: helm,
name: "pihole",
version: "2.26.1",
});
const certManagerApiVersion = "cert-manager.io/v1";
new CertManager(this, "cert-manager", { new CertManager(this, "cert-manager", {
certManagerApiVersion, certManagerApiVersion,
name: "cert-manager", name: "cert-manager",

42
pihole/index.ts Normal file
View File

@@ -0,0 +1,42 @@
import * as fs from "fs";
import { HelmProvider } from "@cdktf/provider-helm/lib/provider";
import { Release } from "@cdktf/provider-helm/lib/release";
import { Construct } from "constructs";
type PiHoleOptions = {
provider: HelmProvider;
version: string;
name: string;
namespace: string;
};
export class PiHole extends Construct {
constructor(scope: Construct, id: string, options: PiHoleOptions) {
super(scope, id);
new Release(this, id, {
...options,
repository: "https://mojo2600.github.io/pihole-kubernetes",
chart: "pihole",
createNamespace: true,
values: [
fs.readFileSync("helm/values/pihole.values.yaml", {
encoding: "utf8",
}),
],
});
new Release(this, "external-dns", {
provider: options.provider,
name: "externaldns-pihole",
namespace: options.namespace,
repository: "https://charts.bitnami.com/bitnami",
chart: "external-dns",
values: [
fs.readFileSync("helm/values/externaldns.values.yaml", {
encoding: "utf8",
}),
],
});
}
}