paultyng/terraform-provider-unifi

wrong handling of imported network resource

Tommi2Day opened this issue · 0 comments

to temporary mitigate problems i described in #168 i tried to use an imported network resource to retrieving an accepted networkid for user resource. But here i ran into the next issues.
Importing network resource was fine

resource "unifi_network" "vlan" {
}

terraform import unifi_network.vlan name="Vlan170-PVE Netboot"
unifi_network.vlan: Import prepared!
  Prepared unifi_network for import
unifi_network.vlan: Refreshing state... [id=6118f3fa5e1bf36442b2bf88]

Import successful!

terraform state show unifi_network.vlan
# unifi_network.vlan:
resource "unifi_network" "vlan" {
    dhcp_dns            = [
        "192.168.101.100",
    ]
    dhcp_enabled        = true
    dhcp_lease          = 86400
    dhcp_start          = "192.168.170.30"
    dhcp_stop           = "192.168.170.254"
    dhcpd_boot_enabled  = true
    dhcpd_boot_filename = "sidero.kpxe"
    dhcpd_boot_server   = "192.168.101.100"
    domain_name         = "home.local"
    id                  = "6118f3fa5e1bf36442b2bf88"
    igmp_snooping       = false
    ipv6_interface_type = "none"
    ipv6_ra_enable      = false
    name                = "Vlan170-PVE Netboot"
    network_group       = "LAN"
    purpose             = "corporate"
    site                = "default"
    subnet              = "192.168.170.0/24"
    vlan_id             = 170
    wan_dns             = []
    wan_egress_qos      = 0
}

if i try to use it it complains about missing mandantory fields (which may be ok)

terraform plan
╷
│ Error: Missing required argument
│
│   on main.tf line 2, in resource "unifi_network" "vlan":
│    2: resource "unifi_network" "vlan" {
│
│ The argument "name" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│
│   on main.tf line 2, in resource "unifi_network" "vlan":
│    2: resource "unifi_network" "vlan" {
│
│ The argument "purpose" is required, but no definition was found.

if i add these mandantory fields into the resource terraform will update it with empty fields instead of doing nothing as expected

resource "unifi_network" "vlan" {
  name="Vlan170-PVE Netboot"
  purpose="corporate"
}
terraform plan
unifi_network.vlan: Refreshing state... [id=6118f3fa5e1bf36442b2bf88]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # unifi_network.vlan will be updated in-place
  ~ resource "unifi_network" "vlan" {
      ~ dhcp_dns            = [
          - "192.168.101.100",
        ]
      - dhcp_enabled        = true -> null
      - dhcp_start          = "192.168.170.30" -> null
      - dhcp_stop           = "192.168.170.254" -> null
      - dhcpd_boot_enabled  = true -> null
      - dhcpd_boot_filename = "sidero.kpxe" -> null
      - dhcpd_boot_server   = "192.168.101.100" -> null
      - domain_name         = "home.local" -> null
        id                  = "6118f3fa5e1bf36442b2bf88"
        name                = "Vlan170-PVE Netboot"
      - subnet              = "192.168.170.0/24" -> null
      - vlan_id             = 170 -> null
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.