Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for setting dns configuration to be pushed to nodes #3

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BGP or OSPF.
Pools, Networks, and Memberships. [ZeroTier Central](https://my.zerotier.com) is our SaaS
offering, which is driven by the
[ZeroTier Terraform Provider](https://registry.terraform.io/providers/zerotier/zerotier/latest).

## Usage

Before we begin, we will need to log into [my.zerotier.com](https://my.zerotier.com) and create an API
Expand Down Expand Up @@ -95,6 +95,13 @@ Terraform will perform the following actions:
+ route {
+ target = "10.9.8.0/24"
}
+ dns {
+ domain = "example.com"
+ servers = [
+ "10.10.10.1",
+ "10.10.10.2",
]
}
}

Plan: 1 to add, 0 to change, 0 to destroy.
Expand All @@ -116,7 +123,7 @@ module.this["hello_zerotier"].zerotier_network.this: Creation complete after 1s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
```

Check that it was created in the [ZeroTier Central Webui](my.zerotier.com)
Check that it was created in the [ZeroTier Central Webui](my.zerotier.com)

![](https://i.imgur.com/V5N04ew.png)

Expand Down
25 changes: 25 additions & 0 deletions examples/setting-dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Single Network with DNS configuration

You can set DNS search domain and DNS servers to push to all zerotier nodes via the central API.

A node running the ZeroTier agent will need to run
```
zerotier-cli set <networkId> allowDNS=1
```
for these settings to be applied

## Usage

To run this example you need to:

First, log into [my.zerotier.com](https://my.zerotier.com) and create an API
token under the [Account](https://my.zerotier.com/account) section.

Next, export the `ZEROTIER_CENTRAL_TOKEN` variable in your shell or
Terraform workspace.

```
terraform init
terraform plan
terraform apply
```
13 changes: 13 additions & 0 deletions examples/setting-dns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "this" {
for_each = var.zerotier_networks
source = "../../"
name = each.key
description = each.value.description
subnets = each.value.subnets
flow_rules = each.value.flow_rules
dns = each.value.dns
}

output "this" {
value = module.this
}
16 changes: 16 additions & 0 deletions examples/setting-dns/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "zerotier_networks" {
default = {
setting_dns = {
description = "Hello Zerotier!"
subnets = ["10.9.76.0/24"]
flow_rules = "accept;"
dns = {
domain = "example.com"
servers = [
"10.10.10.1",
"10.10.10.2"
]
}
}
}
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ resource "zerotier_network" "this" {
via = route.value.via
}
}

dns {
domain = var.dns.domain
servers = var.dns.servers
}
}
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ output "creation_time" {
output "id" {
value = zerotier_network.this.id
}

output "dns" {
value = zerotier_network.this.dns
}
20 changes: 20 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,23 @@ variable "subnets" {
type = list(string)
default = []
}

variable "dns" {
description = "DNS settings to be pushed down to client"
type = object({
domain = string
servers = list(string)
})
default = {
domain = ""
servers = []
}
validation {
condition = can([for s in var.dns.servers : cidrnetmask("${s}/32")])
error_message = "dns.servers should be a valid IPv4 address."
}
validation {
condition = var.dns.domain == "" ? true : can(regex("^[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,6}$", var.dns.domain))
error_message = "dns.domain should be a valid domain name."
}
}