Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wan_vlan is not always an int #89

Closed
T4cC0re opened this issue Jan 2, 2021 · 4 comments
Closed

wan_vlan is not always an int #89

T4cC0re opened this issue Jan 2, 2021 · 4 comments
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@T4cC0re
Copy link

T4cC0re commented Jan 2, 2021

I wanted to import my current WAN network into the terraform state via

terraform import unifi_network.wan 5b69042b78118a0f722cb8b2

But I got this error:

Error: unable to decode body: GET s/default/rest/networkconf/5b69042b78118a0f722cb8b2 unable to unmarshal alias: json: cannot unmarshal string into Go struct field .wan_vlan of type int

Looking at the JSON from the API, it is clear why: (formatted for readability and some values removed)

{
  "meta":{
    "rc":"ok"
  },
  "data":[
    {
      "_id":"5b69042b78118a0f722cb8b2",
      "site_id":"5b69038878118a0f722cb893",
      "purpose":"wan",
      "name":"WAN",
      "wan_type":"dhcp",
      "wan_type_v6":"dhcpv6",
      "wan_egress_qos":"",
      "wan_dhcpv6_pd_size":58,
      "wan_smartq_enabled":false,
      "wan_vlan_enabled":false,
      "wan_dhcp_options":[ ],
      "wan_dns1":"1.1.1.1",
      "wan_dns2":"1.0.0.1",
      "wan_vlan":""
    }
  ]
}

wan_vlan is expected to be an int, but is a string.

I have yet to test my theory, but I bet it would be possible to unmarshal into a json.Token and only if wan_vlan_enabled is true, actually set wan_vlan (and use an int typecast).

I would assume, this is the same for wan_egress_qos.

I'll fork this provider and try to provide a fix for this.

@T4cC0re
Copy link
Author

T4cC0re commented Jan 2, 2021

I found the issue in go-unifi. I managed to import state with my forked code. I Will clean it up accordingly and also file an issue (and PR) there.

@T4cC0re
Copy link
Author

T4cC0re commented Jan 2, 2021

I provided a fix for go-unifi. If that is accepted and this provided updated to the new version, this issue would be solved.

@paultyng
Copy link
Owner

paultyng commented Jan 3, 2021

Merged in go-unifi and released as 1.11.0, I think an automatic PR should show up here soonish, but if not I will bump it tomorrow.

@paultyng paultyng added bug Something isn't working dependencies Pull requests that update a dependency file labels Jan 3, 2021
@paultyng
Copy link
Owner

paultyng commented Jan 4, 2021

Just released this in v0.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants