From f2314ac214f6de1b74fe7baa0f7e55033d4a61c8 Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Fri, 16 Oct 2020 21:33:46 -0400 Subject: [PATCH] Fix some issues in examples so they run --- docs/guides/csv-users.md | 9 ++------- docs/index.md | 4 ++++ docs/resources/user.md | 2 +- examples/csv_users/users.csv | 5 ++--- examples/csv_users/users.tf | 4 ---- examples/provider/provider.tf | 4 ++++ examples/provider/test.auto.tfvars | 6 ++++++ examples/provider/variables.tf | 4 ++++ examples/resources/unifi_firewall_group/test.auto.tfvars | 2 ++ examples/resources/unifi_firewall_rule/test.auto.tfvars | 2 ++ examples/resources/unifi_network/test.auto.tfvars | 1 + examples/resources/unifi_user/resource.tf | 2 +- examples/resources/unifi_user/test.auto.tfvars | 1 + 13 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 examples/provider/test.auto.tfvars create mode 100644 examples/resources/unifi_firewall_group/test.auto.tfvars create mode 100644 examples/resources/unifi_firewall_rule/test.auto.tfvars create mode 100644 examples/resources/unifi_network/test.auto.tfvars create mode 100644 examples/resources/unifi_user/test.auto.tfvars diff --git a/docs/guides/csv-users.md b/docs/guides/csv-users.md index ceee802..09e41d9 100644 --- a/docs/guides/csv-users.md +++ b/docs/guides/csv-users.md @@ -10,9 +10,8 @@ description: |- Given a CSV file with the following content: ```csv -mac,name,note,network,fixed_ip -00:00:00:00:00:00,My Device,custom note,,, -00:00:00:00:00:00,My Device,custom note,network name to lookup,10.0.3.4 +mac,name,note +01:23:45:67:89:AB,My Device,custom note ``` You could create/manage a `unifi_user` for every row/MAC address in the CSV with the following config: @@ -31,10 +30,6 @@ resource "unifi_user" "user" { # append an optional additional note note = trimspace("${each.value.note}\n\nmanaged by TF") - fixed_ip = each.value.fixed_ip - # this assumes there is a unifi_network for_each with names - network_id = each.value.network != "" ? unifi_network.vlan[each.value.network].id : "" - allow_existing = true skip_forget_on_destroy = true } diff --git a/docs/index.md b/docs/index.md index 4f998bc..dd90a8f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,6 +17,10 @@ provider "unifi" { password = var.password # optionally use UNIFI_PASSWORD env var api_url = var.api_url # optionally use UNIFI_API env var + # you may need to allow insecure TLS communications unless you have configured + # certificates for your controller + allow_insecure = var.insecure # optionally use UNIFI_INSECURE env var + # if you are not configuring the default site, you can change the site # site = "foo" or optionally use UNIFI_SITE env var } diff --git a/docs/resources/user.md b/docs/resources/user.md index dc103ed..485334e 100644 --- a/docs/resources/user.md +++ b/docs/resources/user.md @@ -20,7 +20,7 @@ resource "unifi_user" "test" { name = "some client" note = "my note" - fixed_ip = "10.1.10.50" + fixed_ip = "10.0.0.50" network_id = unifi_network.my_vlan.id } ``` diff --git a/examples/csv_users/users.csv b/examples/csv_users/users.csv index 92fb444..580b412 100644 --- a/examples/csv_users/users.csv +++ b/examples/csv_users/users.csv @@ -1,3 +1,2 @@ -mac,name,note,network,fixed_ip -00:00:00:00:00:00,My Device,custom note,,, -00:00:00:00:00:00,My Device,custom note,network name to lookup,10.0.3.4 +mac,name,note +01:23:45:67:89:AB,My Device,custom note diff --git a/examples/csv_users/users.tf b/examples/csv_users/users.tf index 7b73f78..59bdc8c 100644 --- a/examples/csv_users/users.tf +++ b/examples/csv_users/users.tf @@ -11,10 +11,6 @@ resource "unifi_user" "user" { # append an optional additional note note = trimspace("${each.value.note}\n\nmanaged by TF") - fixed_ip = each.value.fixed_ip - # this assumes there is a unifi_network for_each with names - network_id = each.value.network != "" ? unifi_network.vlan[each.value.network].id : "" - allow_existing = true skip_forget_on_destroy = true } \ No newline at end of file diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index b038131..2039fea 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -3,6 +3,10 @@ provider "unifi" { password = var.password # optionally use UNIFI_PASSWORD env var api_url = var.api_url # optionally use UNIFI_API env var + # you may need to allow insecure TLS communications unless you have configured + # certificates for your controller + allow_insecure = var.insecure # optionally use UNIFI_INSECURE env var + # if you are not configuring the default site, you can change the site # site = "foo" or optionally use UNIFI_SITE env var } \ No newline at end of file diff --git a/examples/provider/test.auto.tfvars b/examples/provider/test.auto.tfvars new file mode 100644 index 0000000..2992b73 --- /dev/null +++ b/examples/provider/test.auto.tfvars @@ -0,0 +1,6 @@ +username = "tfacctest" +password = "tfacctest1234" + +# this assumes the default port for acc testing +api_url = "https://localhost:8443/api/" +insecure = true \ No newline at end of file diff --git a/examples/provider/variables.tf b/examples/provider/variables.tf index a448f11..340d09d 100644 --- a/examples/provider/variables.tf +++ b/examples/provider/variables.tf @@ -5,4 +5,8 @@ variable "password" { } variable "api_url" { +} + +variable "insecure" { + default = false } \ No newline at end of file diff --git a/examples/resources/unifi_firewall_group/test.auto.tfvars b/examples/resources/unifi_firewall_group/test.auto.tfvars new file mode 100644 index 0000000..c2fe9cf --- /dev/null +++ b/examples/resources/unifi_firewall_group/test.auto.tfvars @@ -0,0 +1,2 @@ +# these values are used in tests +laptop_ips = ["192.168.1.25"] \ No newline at end of file diff --git a/examples/resources/unifi_firewall_rule/test.auto.tfvars b/examples/resources/unifi_firewall_rule/test.auto.tfvars new file mode 100644 index 0000000..4de35ff --- /dev/null +++ b/examples/resources/unifi_firewall_rule/test.auto.tfvars @@ -0,0 +1,2 @@ +# these values are used in tests +ip_address = "192.168.1.1" \ No newline at end of file diff --git a/examples/resources/unifi_network/test.auto.tfvars b/examples/resources/unifi_network/test.auto.tfvars new file mode 100644 index 0000000..ec90fb0 --- /dev/null +++ b/examples/resources/unifi_network/test.auto.tfvars @@ -0,0 +1 @@ +vlan_id = 41 \ No newline at end of file diff --git a/examples/resources/unifi_user/resource.tf b/examples/resources/unifi_user/resource.tf index f1f2f8b..765c263 100644 --- a/examples/resources/unifi_user/resource.tf +++ b/examples/resources/unifi_user/resource.tf @@ -3,6 +3,6 @@ resource "unifi_user" "test" { name = "some client" note = "my note" - fixed_ip = "10.1.10.50" + fixed_ip = "10.0.0.50" network_id = unifi_network.my_vlan.id } \ No newline at end of file diff --git a/examples/resources/unifi_user/test.auto.tfvars b/examples/resources/unifi_user/test.auto.tfvars new file mode 100644 index 0000000..9d14417 --- /dev/null +++ b/examples/resources/unifi_user/test.auto.tfvars @@ -0,0 +1 @@ +vlan_id = 42 \ No newline at end of file