paultyng/terraform-provider-unifi

Provider seems to require site now

JonTheNiceGuy opened this issue · 4 comments

I followed the details on the overview page of the documentation, like this:

terraform {
  required_providers {
    unifi = {
      source  = "paultyng/unifi"
      version = "0.41.0"
    }
  }
}

provider "unifi" {
  api_url        = var.unifi_api_url
  allow_insecure = var.unifi_insecure
  username       = var.unifi_username
  password       = var.unifi_password
}

I then tried to create a resource as follows:

locals {
  vlans = {
    88 = "test"
  }
}

resource "unifi_network" "vlans" {
  for_each = local.vlans
  name     = each.value != "" ? each.value : "VLAN ${each.key}"
  purpose  = "vlan-only"
  vlan_id  = each.key
}

Having run terraform init and terraform apply I got this:

unifi_network.vlans["88"]: Creating...
╷
│ Error: api.err.VlanUsed (400 ) for POST https://redacted:8443/api/s/default/rest/networkconf
│ 
│   with unifi_network.vlans["88"],
│   on resources.tf line 18, in resource "unifi_network" "vlans":
│   18: resource "unifi_network" "vlans" {
│ 
╵

By adding the site parameter to the provider I made it work!

provider "unifi" {
  api_url        = var.unifi_api_url
  allow_insecure = var.unifi_insecure
  username       = var.unifi_username
  password       = var.unifi_password
  site           = "default"
}

I don't know how to explain the behaviour you are seeing but you can see from the error message that it is using the default site: https://redacted:8443/api/s/default/rest/networkconf

Does it reproduce consistently? What version of UniFi Network are you using?

Agreed, it should be working, and yet... shrug

From the GUI; I see "Network 7.3.83"

Nope, it's not consistent. I must have just had a glitch. Sorry!!