Skip to content

Commit

Permalink
Fix interface conversion errors
Browse files Browse the repository at this point in the history
and inability to use non-int named tables (e.g. `default`).

Closes #34.
  • Loading branch information
OJFord committed May 21, 2024
1 parent f83c215 commit 8f16d02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/data-sources/config_document.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data "wireguard_config_document" "peer1" {
"2606:4700:4700:0:0:0:0:64",
"2606:4700:4700:0:0:0:0:6400",
]
routing_table = "123"
peer {
public_key = wireguard_asymmetric_key.peer2.public_key
Expand Down Expand Up @@ -66,7 +67,7 @@ output "peer1" {
- `post_up` (List of String) Scripts to run after setting up the interface. (`wg-quick`/apps only.)
- `pre_down` (List of String) Scripts to run before tearing down the interface. (`wg-quick`/apps only.)
- `pre_up` (List of String) Script to run before setting up the interface. (`wg-quick`/apps only.)
- `routing_table` (Number) Controls the routing table (or "off") to which routes are added. (`wg-quick`/apps only.)
- `routing_table` (String) Controls the routing table (or "off") to which routes are added. (`wg-quick`/apps only.)

### Read-Only

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data "wireguard_config_document" "peer1" {
"2606:4700:4700:0:0:0:0:64",
"2606:4700:4700:0:0:0:0:6400",
]
routing_table = "123"

peer {
public_key = wireguard_asymmetric_key.peer2.public_key
Expand Down
12 changes: 6 additions & 6 deletions provider/data_source_wireguard_config_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func dataSourceWireguardConfigDocument() *schema.Resource {

"routing_table": {
Description: "Controls the routing table (or \"off\") to which routes are added. (`wg-quick`/apps only.)",
Type: schema.TypeInt,
Type: schema.TypeString,
Optional: true,
},

Expand Down Expand Up @@ -280,28 +280,28 @@ func dataSourceWireguardConfigDocumentRead(d *schema.ResourceData, m interface{}
cfg.RoutingTable = &rt
}

if vals := d.Get("pre_up").(*schema.Set).List(); len(vals) > 0 {
if vals := d.Get("pre_up").([]interface{}); len(vals) > 0 {
cfg.PreUp = make([]string, len(vals))
for i, v := range vals {
cfg.PreUp[i] = v.(string)
}
}

if vals := d.Get("post_up").(*schema.Set).List(); len(vals) > 0 {
if vals := d.Get("post_up").([]interface{}); len(vals) > 0 {
cfg.PostUp = make([]string, len(vals))
for i, v := range vals {
cfg.PostUp[i] = v.(string)
}
}

if vals := d.Get("pre_down").(*schema.Set).List(); len(vals) > 0 {
if vals := d.Get("pre_down").([]interface{}); len(vals) > 0 {
cfg.PreDown = make([]string, len(vals))
for i, v := range vals {
cfg.PreDown[i] = v.(string)
}
}

if vals := d.Get("post_down").(*schema.Set).List(); len(vals) > 0 {
if vals := d.Get("post_down").([]interface{}); len(vals) > 0 {
cfg.PostDown = make([]string, len(vals))
for i, v := range vals {
cfg.PostDown[i] = v.(string)
Expand All @@ -323,7 +323,7 @@ func dataSourceWireguardConfigDocumentRead(d *schema.ResourceData, m interface{}
peerCfg.PresharedKey = &psk
}

if vals := peer["allowed_ips"].(*schema.Set).List(); len(vals) > 0 {
if vals := peer["allowed_ips"].([]interface{}); len(vals) > 0 {
peerCfg.AllowedIPs = make([]string, len(vals))
for i, v := range vals {
peerCfg.AllowedIPs[i] = v.(string)
Expand Down

0 comments on commit 8f16d02

Please sign in to comment.