Fix some issues in examples so they run

This commit is contained in:
Paul Tyng
2020-10-16 21:33:46 -04:00
parent b8e573fdf1
commit f2314ac214
13 changed files with 30 additions and 16 deletions

View File

@@ -10,9 +10,8 @@ description: |-
Given a CSV file with the following content: Given a CSV file with the following content:
```csv ```csv
mac,name,note,network,fixed_ip mac,name,note
00:00:00:00:00:00,My Device,custom note,,, 01:23:45:67:89:AB,My Device,custom note
00:00:00:00:00:00,My Device,custom note,network name to lookup,10.0.3.4
``` ```
You could create/manage a `unifi_user` for every row/MAC address in the CSV with the following config: 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 # append an optional additional note
note = trimspace("${each.value.note}\n\nmanaged by TF") 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 allow_existing = true
skip_forget_on_destroy = true skip_forget_on_destroy = true
} }

View File

@@ -17,6 +17,10 @@ provider "unifi" {
password = var.password # optionally use UNIFI_PASSWORD env var password = var.password # optionally use UNIFI_PASSWORD env var
api_url = var.api_url # optionally use UNIFI_API 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 # if you are not configuring the default site, you can change the site
# site = "foo" or optionally use UNIFI_SITE env var # site = "foo" or optionally use UNIFI_SITE env var
} }

View File

@@ -20,7 +20,7 @@ resource "unifi_user" "test" {
name = "some client" name = "some client"
note = "my note" note = "my note"
fixed_ip = "10.1.10.50" fixed_ip = "10.0.0.50"
network_id = unifi_network.my_vlan.id network_id = unifi_network.my_vlan.id
} }
``` ```

View File

@@ -1,3 +1,2 @@
mac,name,note,network,fixed_ip mac,name,note
00:00:00:00:00:00,My Device,custom note,,, 01:23:45:67:89:AB,My Device,custom note
00:00:00:00:00:00,My Device,custom note,network name to lookup,10.0.3.4
1 mac,name,note,network,fixed_ip mac name note
2 00:00:00:00:00:00,My Device,custom note,,, 01:23:45:67:89:AB My Device custom note
00:00:00:00:00:00,My Device,custom note,network name to lookup,10.0.3.4

View File

@@ -11,10 +11,6 @@ resource "unifi_user" "user" {
# append an optional additional note # append an optional additional note
note = trimspace("${each.value.note}\n\nmanaged by TF") 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 allow_existing = true
skip_forget_on_destroy = true skip_forget_on_destroy = true
} }

View File

@@ -3,6 +3,10 @@ provider "unifi" {
password = var.password # optionally use UNIFI_PASSWORD env var password = var.password # optionally use UNIFI_PASSWORD env var
api_url = var.api_url # optionally use UNIFI_API 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 # if you are not configuring the default site, you can change the site
# site = "foo" or optionally use UNIFI_SITE env var # site = "foo" or optionally use UNIFI_SITE env var
} }

View File

@@ -0,0 +1,6 @@
username = "tfacctest"
password = "tfacctest1234"
# this assumes the default port for acc testing
api_url = "https://localhost:8443/api/"
insecure = true

View File

@@ -5,4 +5,8 @@ variable "password" {
} }
variable "api_url" { variable "api_url" {
}
variable "insecure" {
default = false
} }

View File

@@ -0,0 +1,2 @@
# these values are used in tests
laptop_ips = ["192.168.1.25"]

View File

@@ -0,0 +1,2 @@
# these values are used in tests
ip_address = "192.168.1.1"

View File

@@ -0,0 +1 @@
vlan_id = 41

View File

@@ -3,6 +3,6 @@ resource "unifi_user" "test" {
name = "some client" name = "some client"
note = "my note" note = "my note"
fixed_ip = "10.1.10.50" fixed_ip = "10.0.0.50"
network_id = unifi_network.my_vlan.id network_id = unifi_network.my_vlan.id
} }

View File

@@ -0,0 +1 @@
vlan_id = 42