Skip to content

Commit

Permalink
Add support for network.interface
Browse files Browse the repository at this point in the history
Much like the `network.device`, we add support for both the Data Source
and Resource. Since `network.device` is so complex, we're only
implementing a subset of it.

Also like the `network.device`, the documentation is less than ideal.
It's separated into multiple pages. And each page is slightly different.
Maybe there's just a different way to find all of this information?

Branch: joneshf/add-support-for-network-interface
Pull-Request: #109
  • Loading branch information
joneshf authored Mar 24, 2023
1 parent fe45a0f commit d604b35
Show file tree
Hide file tree
Showing 8 changed files with 700 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/data-sources/network_interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "openwrt_network_interface Data Source - openwrt"
subcategory: ""
description: |-
A logic network.
---

# openwrt_network_interface (Data Source)

A logic network.

## Example Usage

```terraform
data "openwrt_network_interface" "br_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

- `auto` (Boolean) Specifies whether to bring up this interface on boot.
- `device` (String) Name of the (physical or virtual) device. This name is what the device is known as in LuCI or the `name` field in Terraform. This is not the UCI config name.
- `disabled` (Boolean) Disables this interface.
- `dns` (List of String) DNS servers
- `gateway` (String) Gateway of the interface
- `ip6assign` (Number) Delegate a prefix of given length to this interface
- `ipaddr` (String) IP address of the interface
- `macaddr` (String) Override the MAC Address of this interface.
- `mtu` (Number) Override the default MTU on this interface.
- `netmask` (String) Netmask of the interface
- `peerdns` (Boolean) Use DHCP-provided DNS servers.
- `proto` (String) The protocol type of the interface. Currently, only "dhcp, and "static" are supported.
- `reqaddress` (String) Behavior for requesting address. Can only be one of "force", "try", or "none".
- `reqprefix` (String) Behavior for requesting prefixes. Currently, only "auto" is supported.


89 changes: 89 additions & 0 deletions docs/resources/network_interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "openwrt_network_interface Resource - openwrt"
subcategory: ""
description: |-
A logic network.
---

# openwrt_network_interface (Resource)

A logic network.

## Example Usage

```terraform
resource "openwrt_network_device" "br_testing" {
id = "br_testing"
name = "br-testing"
ports = [
"eth0",
"eth1",
"eth2.20",
]
type = "bridge"
}
resource "openwrt_network_interface" "testing" {
device = openwrt_network_device.br_testing.name
dns = [
"9.9.9.9",
"1.1.1.1",
]
id = "testing"
ipaddr = "192.168.3.1"
netmask = "255.255.255.0"
proto = "static"
}
```

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

### Required

- `device` (String) Name of the (physical or virtual) device. This name is what the device is known as in LuCI or the `name` field in Terraform. This is not the UCI config name.
- `id` (String) Name of the section. This name is only used when interacting with UCI directly.
- `proto` (String) The protocol type of the interface. Currently, only "dhcp, and "static" are supported.

### Optional

- `auto` (Boolean) Specifies whether to bring up this interface on boot.
- `disabled` (Boolean) Disables this interface.
- `dns` (List of String) DNS servers
- `gateway` (String) Gateway of the interface
- `ip6assign` (Number) Delegate a prefix of given length to this interface
- `ipaddr` (String) IP address of the interface
- `macaddr` (String) Override the MAC Address of this interface.
- `mtu` (Number) Override the default MTU on this interface.
- `netmask` (String) Netmask of the interface
- `peerdns` (Boolean) Use DHCP-provided DNS servers.
- `reqaddress` (String) Behavior for requesting address. Can only be one of "force", "try", or "none".
- `reqprefix` (String) Behavior for requesting prefixes. Currently, only "auto" is supported.

## Import

Import is supported using the following syntax:

```shell
# Find the Terraform id is the same as the UCI name from LuCI's JSON-RPC API.
# It is also generally the lower-cased version of the interface name in LuCI's web UI.
# One way to find this information is with `curl` and `jq`:
#
# curl \
# --data '{"id": 0, "method": "foreach", "params": ["network", "interface"]}' \
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
# | jq '.result | map(.[".name"])'
#
# This command will output something like:
#
# [
# "loopback",
# "wan",
# "wan6"
# ]
#
# We'd then use the information to import the appropriate resource:

terraform import openwrt_network_interface.loopback loopback
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "openwrt_network_interface" "br_testing" {
id = "testing"
}
20 changes: 20 additions & 0 deletions examples/resources/openwrt_network_interface/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Find the Terraform id is the same as the UCI name from LuCI's JSON-RPC API.
# It is also generally the lower-cased version of the interface name in LuCI's web UI.
# One way to find this information is with `curl` and `jq`:
#
# curl \
# --data '{"id": 0, "method": "foreach", "params": ["network", "interface"]}' \
# http://192.168.1.1/cgi-bin/luci/rpc/uci?auth=$AUTH_TOKEN \
# | jq '.result | map(.[".name"])'
#
# This command will output something like:
#
# [
# "loopback",
# "wan",
# "wan6"
# ]
#
# We'd then use the information to import the appropriate resource:

terraform import openwrt_network_interface.loopback loopback
22 changes: 22 additions & 0 deletions examples/resources/openwrt_network_interface/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "openwrt_network_device" "br_testing" {
id = "br_testing"
name = "br-testing"
ports = [
"eth0",
"eth1",
"eth2.20",
]
type = "bridge"
}

resource "openwrt_network_interface" "testing" {
device = openwrt_network_device.br_testing.name
dns = [
"9.9.9.9",
"1.1.1.1",
]
id = "testing"
ipaddr = "192.168.3.1"
netmask = "255.255.255.0"
proto = "static"
}
Loading

0 comments on commit d604b35

Please sign in to comment.