Skip to content

Commit bd3e38d

Browse files
authored
Add support for dhcp.dnsmasq
Moving on to DHCP stuff, we want to be able to configure the Dnsmasq stuff. As with all of the other resources we add, this is only a subset of what's available. We'll flesh out more as time goes on. Branch: joneshf/add-support-for-dhcp-dnsmasq Pull-Request: #127
1 parent cf40679 commit bd3e38d

File tree

9 files changed

+557
-0
lines changed

9 files changed

+557
-0
lines changed

docs/data-sources/dhcp_dnsmasq.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "openwrt_dhcp_dnsmasq Data Source - openwrt"
4+
subcategory: ""
5+
description: |-
6+
A lightweight DHCP and caching DNS server.
7+
---
8+
9+
# openwrt_dhcp_dnsmasq (Data Source)
10+
11+
A lightweight DHCP and caching DNS server.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "openwrt_dhcp_dnsmasq" "testing" {
17+
id = "testing"
18+
}
19+
```
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `id` (String) Name of the section. This name is only used when interacting with UCI directly.
27+
28+
### Read-Only
29+
30+
- `authoritative` (Boolean) Force dnsmasq into authoritative mode. This speeds up DHCP leasing. Used if this is the only server on the network.
31+
- `domain` (String) DNS domain handed out to DHCP clients.
32+
- `domainneeded` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
33+
- `ednspacket_max` (Number) Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder.
34+
- `expandhosts` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
35+
- `leasefile` (String) Store DHCP leases in this file.
36+
- `local` (String) Look up DNS entries for this domain from `/etc/hosts`.
37+
- `localise_queries` (Boolean) Choose IP address to match the incoming interface if multiple addresses are assigned to a host name in `/etc/hosts`.
38+
- `localservice` (Boolean) Accept DNS queries only from hosts whose address is on a local subnet.
39+
- `readethers` (Boolean) Read static lease entries from `/etc/ethers`, re-read on SIGHUP.
40+
- `rebind_localhost` (Boolean) Allows upstream 127.0.0.0/8 responses, required for DNS based blocklist services. Only takes effect if rebind protection is enabled.
41+
- `rebind_protection` (Boolean) Enables DNS rebind attack protection by discarding upstream RFC1918 responses.
42+
- `resolvfile` (String) Specifies an alternative resolv file.
43+
44+

docs/resources/dhcp_dnsmasq.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "openwrt_dhcp_dnsmasq Resource - openwrt"
4+
subcategory: ""
5+
description: |-
6+
A lightweight DHCP and caching DNS server.
7+
---
8+
9+
# openwrt_dhcp_dnsmasq (Resource)
10+
11+
A lightweight DHCP and caching DNS server.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "openwrt_dhcp_dnsmasq" "this" {
17+
domain = "testing"
18+
expandhosts = true
19+
id = "testing"
20+
local = "/testing/"
21+
rebind_localhost = true
22+
rebind_protection = true
23+
}
24+
```
25+
26+
<!-- schema generated by tfplugindocs -->
27+
## Schema
28+
29+
### Required
30+
31+
- `id` (String) Name of the section. This name is only used when interacting with UCI directly.
32+
33+
### Optional
34+
35+
- `authoritative` (Boolean) Force dnsmasq into authoritative mode. This speeds up DHCP leasing. Used if this is the only server on the network.
36+
- `domain` (String) DNS domain handed out to DHCP clients.
37+
- `domainneeded` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
38+
- `ednspacket_max` (Number) Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder.
39+
- `expandhosts` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
40+
- `leasefile` (String) Store DHCP leases in this file.
41+
- `local` (String) Look up DNS entries for this domain from `/etc/hosts`.
42+
- `localise_queries` (Boolean) Choose IP address to match the incoming interface if multiple addresses are assigned to a host name in `/etc/hosts`.
43+
- `localservice` (Boolean) Accept DNS queries only from hosts whose address is on a local subnet.
44+
- `readethers` (Boolean) Read static lease entries from `/etc/ethers`, re-read on SIGHUP.
45+
- `rebind_localhost` (Boolean) Allows upstream 127.0.0.0/8 responses, required for DNS based blocklist services. Only takes effect if rebind protection is enabled.
46+
- `rebind_protection` (Boolean) Enables DNS rebind attack protection by discarding upstream RFC1918 responses.
47+
- `resolvfile` (String) Specifies an alternative resolv file.
48+
49+
## Import
50+
51+
Import is supported using the following syntax:
52+
53+
```shell
54+
# Find the Terraform id from LuCI's JSON-RPC API.
55+
# One way to find this information is with `curl` and `jq`:
56+
#
57+
# curl \
58+
# --data '{"id": 0, "method": "foreach", "params": ["dhcp", "dnsmasq"]}' \
59+
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
60+
# | jq '.result | map({terraformId: .[".name"]})'
61+
#
62+
# This command will output something like:
63+
#
64+
# [
65+
# {
66+
# "terraformId": "cfg123456",
67+
# }
68+
# ]
69+
#
70+
# We'd then use the information to import the appropriate resource:
71+
72+
terraform import openwrt_dhcp_dnsmasq.this cfg123456
73+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "openwrt_dhcp_dnsmasq" "testing" {
2+
id = "testing"
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Find the Terraform id from LuCI's JSON-RPC API.
2+
# One way to find this information is with `curl` and `jq`:
3+
#
4+
# curl \
5+
# --data '{"id": 0, "method": "foreach", "params": ["dhcp", "dnsmasq"]}' \
6+
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
7+
# | jq '.result | map({terraformId: .[".name"]})'
8+
#
9+
# This command will output something like:
10+
#
11+
# [
12+
# {
13+
# "terraformId": "cfg123456",
14+
# }
15+
# ]
16+
#
17+
# We'd then use the information to import the appropriate resource:
18+
19+
terraform import openwrt_dhcp_dnsmasq.this cfg123456
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "openwrt_dhcp_dnsmasq" "this" {
2+
domain = "testing"
3+
expandhosts = true
4+
id = "testing"
5+
local = "/testing/"
6+
rebind_localhost = true
7+
rebind_protection = true
8+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build acceptance.test
2+
3+
package dnsmasq_test
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"log"
9+
"os"
10+
"testing"
11+
12+
"github.com/joneshf/terraform-provider-openwrt/internal/acceptancetest"
13+
"github.com/ory/dockertest/v3"
14+
)
15+
16+
var (
17+
dockerPool *dockertest.Pool
18+
)
19+
20+
func TestMain(m *testing.M) {
21+
var (
22+
code int
23+
err error
24+
tearDown func()
25+
)
26+
ctx := context.Background()
27+
tearDown, dockerPool, err = acceptancetest.Setup(ctx)
28+
defer func() {
29+
tearDown()
30+
os.Exit(code)
31+
}()
32+
if err != nil {
33+
fmt.Printf("Problem setting up tests: %s", err)
34+
code = 1
35+
return
36+
}
37+
38+
log.Printf("Running tests")
39+
code = m.Run()
40+
}

0 commit comments

Comments
 (0)