Skip to content

Commit

Permalink
github verified domains
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Aug 21, 2023
1 parent 0ad3d6d commit e85c564
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 6 deletions.
36 changes: 36 additions & 0 deletions lib/constructs/GitHubPagesCloudflareDomainConstruct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Record, RecordConfig } from "@cdktf/provider-cloudflare/lib/record"
import { Zone } from "@cdktf/provider-cloudflare/lib/zone"
import { Construct } from "constructs"

export type GitHubPagesCloudflareDomainConstructProperties = {
organization: string
repository: string
subdomain: string
zone: Zone
cdk?: {
record?: RecordConfig
}
}

export class GitHubPagesCloudflareDomainConstruct extends Construct {
public readonly record: Record

public constructor(
scope: Construct,
id: string,
props: GitHubPagesCloudflareDomainConstructProperties,
) {
super(scope, id)

const { cdk, organization, repository, subdomain, zone } = props

this.record = new Record(this, "record", {
comment: `GitHub pages domain for https://github.com/${organization}/${repository}`,
name: subdomain,
type: "CNAME",
value: `${organization}.github.io`,
zoneId: zone.id,
...cdk?.record,
})
}
}
30 changes: 30 additions & 0 deletions lib/constructs/GitHubVerifiedCloudflareDomainConstruct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Zone } from "@cdktf/provider-cloudflare/lib/zone"
import { Record } from "@cdktf/provider-cloudflare/lib/record"
import { Construct } from "constructs"

export type GitHubVerifiedCloudflareDomainConstructProperties = {
subdomain: string
txtValue: string
zone: Zone
}

export class GitHubVerifiedCloudflareDomainConstruct extends Construct {
public constructor(
scope: Construct,
id: string,
props: GitHubVerifiedCloudflareDomainConstructProperties,
) {
super(scope, id)

const { zone, subdomain, txtValue } = props

new Record(this, "txt", {
comment: "GitHub verification",
name: subdomain,
proxied: false,
type: "TXT",
value: txtValue,
zoneId: zone.id,
})
}
}
32 changes: 32 additions & 0 deletions lib/stacks/LShayCcStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Construct } from "constructs"

import {
BaseTerraformStack,
BaseTerraformStackProperties,
} from "./BaseTerraformStack"
import { CloudflareZonesStack } from "./CloudflareZoneStack"
import { GitHubVerifiedCloudflareDomainConstruct } from "../constructs/GitHubVerifiedCloudflareDomainConstruct"

export type LShayCcStackProperties = BaseTerraformStackProperties & {
zones: CloudflareZonesStack["zones"]
}

export class LShayCcStack extends BaseTerraformStack {
public constructor(
scope: Construct,
id: string,
props: LShayCcStackProperties,
) {
super(scope, id, props)

new GitHubVerifiedCloudflareDomainConstruct(
this,
"lshayCcGitHubVerifiedCloudflareDomain",
{
subdomain: "_github-pages-challenge-lukeshay",
txtValue: "e4df395dccaeff1ba602db6ea481d5",
zone: props.zones.lshayCc.zone,
},
)
}
}
17 changes: 14 additions & 3 deletions lib/stacks/EmailAccountsStack.ts → lib/stacks/LShayDevStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@ import {
} from "./BaseTerraformStack"
import { PrivateEmailCloudflareConstruct } from "../constructs/PrivateEmailCloudflareConstruct"
import { CloudflareZonesStack } from "./CloudflareZoneStack"
import { GitHubVerifiedCloudflareDomainConstruct } from "../constructs/GitHubVerifiedCloudflareDomainConstruct"

export type EmailAccountsStackProperties = BaseTerraformStackProperties & {
export type LShayDevStackProperties = BaseTerraformStackProperties & {
zones: CloudflareZonesStack["zones"]
}

export class EmailAccountsStack extends BaseTerraformStack {
export class LShayDevStack extends BaseTerraformStack {
public constructor(
scope: Construct,
id: string,
props: EmailAccountsStackProperties,
props: LShayDevStackProperties,
) {
super(scope, id, props)

new GitHubVerifiedCloudflareDomainConstruct(
this,
"lshayDevGitHubVerifiedCloudflareDomain",
{
subdomain: "_github-pages-challenge-lukeshay",
txtValue: "176257800080a5579a3c94bd4ee445",
zone: props.zones.lshayDev.zone,
},
)

new PrivateEmailCloudflareConstruct(this, "lshayDevPrivateEmail", {
zone: props.zones.lshayDev.zone,
})
Expand Down
44 changes: 44 additions & 0 deletions lib/stacks/LShayLandStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Construct } from "constructs"

import {
BaseTerraformStack,
BaseTerraformStackProperties,
} from "./BaseTerraformStack"
import { CloudflareZonesStack } from "./CloudflareZoneStack"
import { GitHubVerifiedCloudflareDomainConstruct } from "../constructs/GitHubVerifiedCloudflareDomainConstruct"
import { GitHubPagesCloudflareDomainConstruct } from "../constructs/GitHubPagesCloudflareDomainConstruct"

export type LShayLandStackProperties = BaseTerraformStackProperties & {
zones: CloudflareZonesStack["zones"]
}

export class LShayLandStack extends BaseTerraformStack {
public constructor(
scope: Construct,
id: string,
props: LShayLandStackProperties,
) {
super(scope, id, props)

new GitHubVerifiedCloudflareDomainConstruct(
this,
"lshayLandGitHubVerifiedCloudflareDomain",
{
subdomain: "_github-pages-challenge-lukeshay",
txtValue: "07f7961032705bd6c179eb1abbbecf",
zone: props.zones.lshayLand.zone,
},
)

new GitHubPagesCloudflareDomainConstruct(
this,
"lshayLandUIGitHubPagesCloudflareDomain",
{
organization: "lukeshay",
repository: "ui",
subdomain: "ui",
zone: props.zones.lshayLand.zone,
},
)
}
}
32 changes: 32 additions & 0 deletions lib/stacks/LShayOrgStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Construct } from "constructs"

import {
BaseTerraformStack,
BaseTerraformStackProperties,
} from "./BaseTerraformStack"
import { CloudflareZonesStack } from "./CloudflareZoneStack"
import { GitHubVerifiedCloudflareDomainConstruct } from "../constructs/GitHubVerifiedCloudflareDomainConstruct"

export type LShayOrgStackProperties = BaseTerraformStackProperties & {
zones: CloudflareZonesStack["zones"]
}

export class LShayOrgStack extends BaseTerraformStack {
public constructor(
scope: Construct,
id: string,
props: LShayOrgStackProperties,
) {
super(scope, id, props)

new GitHubVerifiedCloudflareDomainConstruct(
this,
"lshayOrgGitHubVerifiedCloudflareDomain",
{
subdomain: "_github-pages-challenge-lukeshay",
txtValue: "e89dedeff94eca2e3572f64d039707",
zone: props.zones.lshayOrg.zone,
},
)
}
}
32 changes: 32 additions & 0 deletions lib/stacks/LShayXyzStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Construct } from "constructs"

import {
BaseTerraformStack,
BaseTerraformStackProperties,
} from "./BaseTerraformStack"
import { CloudflareZonesStack } from "./CloudflareZoneStack"
import { GitHubVerifiedCloudflareDomainConstruct } from "../constructs/GitHubVerifiedCloudflareDomainConstruct"

export type LShayXyzStackProperties = BaseTerraformStackProperties & {
zones: CloudflareZonesStack["zones"]
}

export class LShayXyzStack extends BaseTerraformStack {
public constructor(
scope: Construct,
id: string,
props: LShayXyzStackProperties,
) {
super(scope, id, props)

new GitHubVerifiedCloudflareDomainConstruct(
this,
"lshayXyzGitHubVerifiedCloudflareDomain",
{
subdomain: "_github-pages-challenge-lukeshay",
txtValue: "258c4ef472de401805fd184a306e2c",
zone: props.zones.lshayXyz.zone,
},
)
}
}
28 changes: 26 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { App } from "cdktf"

import { CloudflareZonesStack } from "./lib/stacks/CloudflareZoneStack"
import { EmailAccountsStack } from "./lib/stacks/EmailAccountsStack"
import { LShayDevStack } from "./lib/stacks/LShayDevStack"
import { BaseTerraformStackProperties } from "./lib/stacks/BaseTerraformStack"
import { LShayCcStack } from "./lib/stacks/LShayCCStack"
import { LShayLandStack } from "./lib/stacks/LShayLandStack"
import { LShayOrgStack } from "./lib/stacks/LShayOrgStack"
import { LShayXyzStack } from "./lib/stacks/LShayXyzStack"

const app = new App()

Expand All @@ -12,7 +16,27 @@ const cloudflareZoneStack = new CloudflareZonesStack(app, "cloudflareZones", {
...baseProperties,
})

new EmailAccountsStack(app, "emailAccounts", {
new LShayCcStack(app, "lshayCc", {
...baseProperties,
zones: cloudflareZoneStack.zones,
})

new LShayDevStack(app, "lshayDev", {
...baseProperties,
zones: cloudflareZoneStack.zones,
})

new LShayLandStack(app, "lshayLand", {
...baseProperties,
zones: cloudflareZoneStack.zones,
})

new LShayOrgStack(app, "lshayOrg", {
...baseProperties,
zones: cloudflareZoneStack.zones,
})

new LShayXyzStack(app, "lshayXyz", {
...baseProperties,
zones: cloudflareZoneStack.zones,
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"get": "cdktf get",
"build": "tsc --noEmit",
"synth": "cdktf synth",
"deploy": "cdktf deploy",
"deploy": "cdktf deploy cloudflareZones lshayCc lshayDev lshayLand lshayOrg lshayXyz",
"compile": "tsc --pretty",
"test": "jest",
"test:watch": "jest --watch",
Expand Down

0 comments on commit e85c564

Please sign in to comment.