CDK for dnscontrol simplifies DNS management using the Cloud Development Kit (CDK).
The document is here: https://tky2240.github.io/cdk-for-dnscontrol/.
- Node.js >= 22
- Go >= 1.23.0
Install the CLI and library:
# Install CLI
go install github.com/tky2240/cdk-for-dnscontrol/cdk-dnscontrol-cli@latest
# Install CDK library
npm install @tky2240/cdk-for-dnscontrol
This example is based on the official dnscontrol tutorial.
Create lib/example-stack.ts
:
// filepath: ./lib/example-stack.ts
import { Construct } from "constructs";
import {
DnscontrolDomain,
DnscontrolDomainProps,
DnscontrolProvider,
DnscontrolDomainProviderProps,
DnscontrolRegistrar,
DnscontrolStack,
asIPv4Address,
} from "@tky2240/cdk-for-dnscontrol";
import { DnscontrolARecord } from "@tky2240/cdk-for-dnscontrol/domain-modifier/record";
import * as recordFunction from "@tky2240/cdk-for-dnscontrol/domain-modifier/function"
export class ExampleStack extends DnscontrolStack {
constructor(scope: Construct, id: string) {
super(scope, id, {});
const provider = new DnscontrolProvider(this, "MyProvider", {
providerName: "bind",
});
const registrar = new DnscontrolRegistrar(this, "MyRegistrar", {
registrarName: "none",
});
new ExampleDomain(this, "MyDomain", {
domainName: "example.com",
registrar: registrar,
domainProviderPropsList: [
{
domainProviderName: provider.providerName,
},
],
});
}
}
interface ExampleDomainProps extends DnscontrolDomainProps {
readonly domainName: string;
readonly registrar: DnscontrolRegistrar;
readonly domainProviderPropsList: readonly DnscontrolDomainProviderProps[];
}
export class ExampleDomain extends DnscontrolDomain {
constructor(scope: DnscontrolStack, id: string, props: ExampleDomainProps) {
super(scope, id, props);
// CDK style
new DnscontrolARecord(this, "MyARecord", {
label: "@",
ip: asIPv4Address("1.2.3.4"),
});
// or you can use dnscontrol style
recordFunction.A(this, "@", "2.3.4.5");
}
}
Create bin/index.ts
:
// filepath: ./bin/index.ts
import { App } from "@tky2240/cdk-for-dnscontrol";
import { ExampleStack } from "../lib/example-stack";
const app = new App();
new ExampleStack(app, "ExampleStack");
app.synth();
Create creds.json
:
// filepath: ./creds.json
{
"bind": {
"TYPE": "BIND"
}
}
Use the following commands to manage DNS configurations:
# Show configuration differences
cdk-dnscontrol-cli diff
# Deploy DNS configurations
cdk-dnscontrol-cli deploy
After applying, the zone file will be generated in the output directory.
- Cannot use
IMPORT
andTRANSFORM
. - The following functions are not supported:
FETCH
HASH
PANIC
getConfiguredDomains
- Cannot use
require
andrequire_glob
. - If you use
D_EXTEND
, records are flattened in the CDK code.- It is recommended to split records into constructs instead of using
D_EXTEND
.
- It is recommended to split records into constructs instead of using
Use the following command to migrate from dnsconfig.js
:
cdk-dnscontrol migrate
Create bin/index.ts
:
// filepath: ./bin/index.ts
import { App } from "@tky2240/cdk-for-dnscontrol";
import { MigrationStack } from "../lib/stacks";
const app = new App();
new MigrationStack(app, "MigrationStack");
app.synth();
Create creds.json
:
// filepath: ./creds.json
{
"bind": {
"TYPE": "BIND"
}
}
Use the following commands to manage DNS configurations:
# Show configuration differences
cdk-dnscontrol-cli diff
# Deploy DNS configurations
cdk-dnscontrol-cli deploy
After applying, the zone file will be generated in the output directory.
The diff
command compares the current DNS configurations with the desired state defined in your CDK code. It synthesizes the CDK application and displays the differences without applying any changes.
cdk-dnscontrol-cli diff
Use the --cdk-entry-point
(or -i
) flag to specify a custom entry point for the CDK application:
cdk-dnscontrol-cli diff --cdk-entry-point ./custom-entry.ts
The deploy
command applies the desired DNS configurations defined in your CDK code. It synthesizes the CDK application and pushes the changes to the DNS provider.
cdk-dnscontrol-cli deploy
Use the --cdk-entry-point
(or -i
) flag to specify a custom entry point for the CDK application:
cdk-dnscontrol-cli deploy --cdk-entry-point ./custom-entry.ts
The migrate
command helps convert an existing dnsconfig.js
file into CDK code. It generates CDK constructs and stacks based on the DNS configurations defined in the dnsconfig.js
file.
cdk-dnscontrol-cli migrate
Use the following flags to customize the migration process:
--dnsconfig
(or-d
): Specify the path to thednsconfig.js
file. Defaults to./dnsconfig.js
.--outputDir
(or-o
): Specify the output directory for the generated CDK code. Defaults to./lib/stacks
.
Example:
cdk-dnscontrol-cli migrate --dnsconfig ./path/to/dnsconfig.js --outputDir ./custom/output/dir
Contributions are welcome! Please open an issue or submit a pull request.
- General
- Publish jsii packages
- Write documentation:
- Examples
- API docs
- Migration guide
- Tutorial
- FAQ
- Add CI/CD
- CDK
- Add Aspects
- Add CDK constructs
- CLI
- Support other languages
- Add options for
creds.json