Skip to content

Commit

Permalink
Add support for dhcp.dnsmasq
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joneshf authored Apr 8, 2023
1 parent cf40679 commit bd3e38d
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/data-sources/dhcp_dnsmasq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "openwrt_dhcp_dnsmasq Data Source - openwrt"
subcategory: ""
description: |-
A lightweight DHCP and caching DNS server.
---

# openwrt_dhcp_dnsmasq (Data Source)

A lightweight DHCP and caching DNS server.

## Example Usage

```terraform
data "openwrt_dhcp_dnsmasq" "testing" {
id = "testing"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) Name of the section. This name is only used when interacting with UCI directly.

### Read-Only

- `authoritative` (Boolean) Force dnsmasq into authoritative mode. This speeds up DHCP leasing. Used if this is the only server on the network.
- `domain` (String) DNS domain handed out to DHCP clients.
- `domainneeded` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
- `ednspacket_max` (Number) Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder.
- `expandhosts` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
- `leasefile` (String) Store DHCP leases in this file.
- `local` (String) Look up DNS entries for this domain from `/etc/hosts`.
- `localise_queries` (Boolean) Choose IP address to match the incoming interface if multiple addresses are assigned to a host name in `/etc/hosts`.
- `localservice` (Boolean) Accept DNS queries only from hosts whose address is on a local subnet.
- `readethers` (Boolean) Read static lease entries from `/etc/ethers`, re-read on SIGHUP.
- `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.
- `rebind_protection` (Boolean) Enables DNS rebind attack protection by discarding upstream RFC1918 responses.
- `resolvfile` (String) Specifies an alternative resolv file.


73 changes: 73 additions & 0 deletions docs/resources/dhcp_dnsmasq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "openwrt_dhcp_dnsmasq Resource - openwrt"
subcategory: ""
description: |-
A lightweight DHCP and caching DNS server.
---

# openwrt_dhcp_dnsmasq (Resource)

A lightweight DHCP and caching DNS server.

## Example Usage

```terraform
resource "openwrt_dhcp_dnsmasq" "this" {
domain = "testing"
expandhosts = true
id = "testing"
local = "/testing/"
rebind_localhost = true
rebind_protection = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) Name of the section. This name is only used when interacting with UCI directly.

### Optional

- `authoritative` (Boolean) Force dnsmasq into authoritative mode. This speeds up DHCP leasing. Used if this is the only server on the network.
- `domain` (String) DNS domain handed out to DHCP clients.
- `domainneeded` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
- `ednspacket_max` (Number) Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder.
- `expandhosts` (Boolean) Never forward queries for plain names, without dots or domain parts, to upstream nameservers.
- `leasefile` (String) Store DHCP leases in this file.
- `local` (String) Look up DNS entries for this domain from `/etc/hosts`.
- `localise_queries` (Boolean) Choose IP address to match the incoming interface if multiple addresses are assigned to a host name in `/etc/hosts`.
- `localservice` (Boolean) Accept DNS queries only from hosts whose address is on a local subnet.
- `readethers` (Boolean) Read static lease entries from `/etc/ethers`, re-read on SIGHUP.
- `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.
- `rebind_protection` (Boolean) Enables DNS rebind attack protection by discarding upstream RFC1918 responses.
- `resolvfile` (String) Specifies an alternative resolv file.

## Import

Import is supported using the following syntax:

```shell
# Find the Terraform id from LuCI's JSON-RPC API.
# One way to find this information is with `curl` and `jq`:
#
# curl \
# --data '{"id": 0, "method": "foreach", "params": ["dhcp", "dnsmasq"]}' \
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
# | jq '.result | map({terraformId: .[".name"]})'
#
# This command will output something like:
#
# [
# {
# "terraformId": "cfg123456",
# }
# ]
#
# We'd then use the information to import the appropriate resource:

terraform import openwrt_dhcp_dnsmasq.this cfg123456
```
3 changes: 3 additions & 0 deletions examples/data-sources/openwrt_dhcp_dnsmasq/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "openwrt_dhcp_dnsmasq" "testing" {
id = "testing"
}
19 changes: 19 additions & 0 deletions examples/resources/openwrt_dhcp_dnsmasq/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Find the Terraform id from LuCI's JSON-RPC API.
# One way to find this information is with `curl` and `jq`:
#
# curl \
# --data '{"id": 0, "method": "foreach", "params": ["dhcp", "dnsmasq"]}' \
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
# | jq '.result | map({terraformId: .[".name"]})'
#
# This command will output something like:
#
# [
# {
# "terraformId": "cfg123456",
# }
# ]
#
# We'd then use the information to import the appropriate resource:

terraform import openwrt_dhcp_dnsmasq.this cfg123456
8 changes: 8 additions & 0 deletions examples/resources/openwrt_dhcp_dnsmasq/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "openwrt_dhcp_dnsmasq" "this" {
domain = "testing"
expandhosts = true
id = "testing"
local = "/testing/"
rebind_localhost = true
rebind_protection = true
}
40 changes: 40 additions & 0 deletions openwrt/dhcp/dnsmasq/acceptance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//go:build acceptance.test

package dnsmasq_test

import (
"context"
"fmt"
"log"
"os"
"testing"

"github.com/joneshf/terraform-provider-openwrt/internal/acceptancetest"
"github.com/ory/dockertest/v3"
)

var (
dockerPool *dockertest.Pool
)

func TestMain(m *testing.M) {
var (
code int
err error
tearDown func()
)
ctx := context.Background()
tearDown, dockerPool, err = acceptancetest.Setup(ctx)
defer func() {
tearDown()
os.Exit(code)
}()
if err != nil {
fmt.Printf("Problem setting up tests: %s", err)
code = 1
return
}

log.Printf("Running tests")
code = m.Run()
}
Loading

0 comments on commit bd3e38d

Please sign in to comment.