From 8f16d024b03b970dabb3723f9f5b6baf33a1190d Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Tue, 21 May 2024 20:47:11 +0100 Subject: [PATCH] Fix interface conversion errors and inability to use non-int named tables (e.g. `default`). Closes #34. --- docs/data-sources/config_document.md | 3 ++- .../wireguard_config_document/data-source.tf | 1 + provider/data_source_wireguard_config_document.go | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/data-sources/config_document.md b/docs/data-sources/config_document.md index b35613c..5822997 100644 --- a/docs/data-sources/config_document.md +++ b/docs/data-sources/config_document.md @@ -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 @@ -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 diff --git a/examples/data-sources/wireguard_config_document/data-source.tf b/examples/data-sources/wireguard_config_document/data-source.tf index 04d59e4..eddd5dc 100644 --- a/examples/data-sources/wireguard_config_document/data-source.tf +++ b/examples/data-sources/wireguard_config_document/data-source.tf @@ -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 diff --git a/provider/data_source_wireguard_config_document.go b/provider/data_source_wireguard_config_document.go index e40ea07..d576e74 100644 --- a/provider/data_source_wireguard_config_document.go +++ b/provider/data_source_wireguard_config_document.go @@ -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, }, @@ -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) @@ -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)