-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
wireless.wifi-device
We move on to the wireless stuff. First up is `wireless.wifi-device`. We only handle a small subset of the options, since it's pretty extensive what all this config can do. We'll have to expand this later. But, it should be enough for simpler purposes. Branch: joneshf/add-support-for-wireless-wifi-device Pull-Request: #121
- Loading branch information
Showing
10 changed files
with
578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "openwrt_wireless_wifi_device Data Source - openwrt" | ||
subcategory: "" | ||
description: |- | ||
The physical radio device. | ||
--- | ||
|
||
# openwrt_wireless_wifi_device (Data Source) | ||
|
||
The physical radio device. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "openwrt_wireless_wifi_device" "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 | ||
|
||
- `band` (String) Channel width. Must be one of: "2g", "5g", "6g". | ||
- `cell_density` (Number) Configures data rates based on the coverage cell density. Must be one of 0, 1, 2, 3. | ||
- `channel` (String) The wireless channel. Currently, only "auto" is supported. | ||
- `country` (String) Two-digit country code. E.g. "US". | ||
- `htmode` (String) Channel width. Must be one of: "HE20", "HE40", "HE80", "HE160", "HT20", "HT40", "HT40-", "HT40+", "NONE", "VHT20", "VHT40", "VHT80", "VHT160". | ||
- `path` (String) Path of the device in `/sys/devices`. | ||
- `type` (String) The type of device. Currently only "mac80211" is supported. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "openwrt_wireless_wifi_device Resource - openwrt" | ||
subcategory: "" | ||
description: |- | ||
The physical radio device. | ||
--- | ||
|
||
# openwrt_wireless_wifi_device (Resource) | ||
|
||
The physical radio device. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "openwrt_wireless_wifi_device" "five_ghz" { | ||
band = "5g" | ||
channel = "auto" | ||
id = "cfg123456" | ||
type = "mac80211" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `channel` (String) The wireless channel. Currently, only "auto" is supported. | ||
- `id` (String) Name of the section. This name is only used when interacting with UCI directly. | ||
- `type` (String) The type of device. Currently only "mac80211" is supported. | ||
|
||
### Optional | ||
|
||
- `band` (String) Channel width. Must be one of: "2g", "5g", "6g". | ||
- `cell_density` (Number) Configures data rates based on the coverage cell density. Must be one of 0, 1, 2, 3. | ||
- `country` (String) Two-digit country code. E.g. "US". | ||
- `htmode` (String) Channel width. Must be one of: "HE20", "HE40", "HE80", "HE160", "HT20", "HT40", "HT40-", "HT40+", "NONE", "VHT20", "VHT40", "VHT80", "VHT160". | ||
- `path` (String) Path of the device in `/sys/devices`. | ||
|
||
## 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": ["wireless", "wifi-device"]}' \ | ||
# 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", | ||
# }, | ||
# { | ||
# "terraformId": "cfg123457", | ||
# } | ||
# ] | ||
# | ||
# We'd then use the information to import the appropriate resource: | ||
|
||
terraform import openwrt_wireless_wifi_device.five_ghz cfg123456 | ||
``` |
3 changes: 3 additions & 0 deletions
3
examples/data-sources/openwrt_wireless_wifi_device/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "openwrt_wireless_wifi_device" "testing" { | ||
id = "testing" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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": ["wireless", "wifi-device"]}' \ | ||
# 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", | ||
# }, | ||
# { | ||
# "terraformId": "cfg123457", | ||
# } | ||
# ] | ||
# | ||
# We'd then use the information to import the appropriate resource: | ||
|
||
terraform import openwrt_wireless_wifi_device.five_ghz cfg123456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "openwrt_wireless_wifi_device" "five_ghz" { | ||
band = "5g" | ||
channel = "auto" | ||
id = "cfg123456" | ||
type = "mac80211" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//go:build acceptance.test | ||
|
||
package wifidevice_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/joneshf/terraform-provider-openwrt/internal/acceptancetest" | ||
"github.com/joneshf/terraform-provider-openwrt/lucirpc" | ||
"github.com/ory/dockertest/v3" | ||
"golang.org/x/crypto/ssh" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
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() | ||
} | ||
|
||
// runOpenWrtServerWithWireless starts an OpenWrt server, | ||
// and sets up the wireless config. | ||
// Without setting up the config, | ||
// the tests in this package will fail. | ||
func runOpenWrtServerWithWireless( | ||
ctx context.Context, | ||
dockerPool dockertest.Pool, | ||
t *testing.T, | ||
) (*lucirpc.Client, string) { | ||
openWrtServer := acceptancetest.RunOpenWrtServer( | ||
ctx, | ||
dockerPool, | ||
t, | ||
) | ||
sshURL := fmt.Sprintf("%s:%d", openWrtServer.Hostname, openWrtServer.SSHPort) | ||
sshConfig := &ssh.ClientConfig{ | ||
Auth: []ssh.AuthMethod{ | ||
ssh.Password(openWrtServer.Password), | ||
}, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
User: openWrtServer.Username, | ||
} | ||
sshClient, err := ssh.Dial("tcp", sshURL, sshConfig) | ||
assert.NilError(t, err) | ||
t.Cleanup(func() { | ||
sshClient.Close() | ||
}) | ||
session, err := sshClient.NewSession() | ||
assert.NilError(t, err) | ||
t.Cleanup(func() { | ||
session.Close() | ||
}) | ||
err = session.Run("touch /etc/config/wireless") | ||
assert.NilError(t, err) | ||
client, err := lucirpc.NewClient( | ||
ctx, | ||
openWrtServer.Scheme, | ||
openWrtServer.Hostname, | ||
openWrtServer.HTTPPort, | ||
openWrtServer.Username, | ||
openWrtServer.Password, | ||
) | ||
assert.NilError(t, err) | ||
providerBlock := openWrtServer.ProviderBlock() | ||
return client, providerBlock | ||
} |
Oops, something went wrong.