terraform-provider-unifi icon indicating copy to clipboard operation
terraform-provider-unifi copied to clipboard

Terraform import of unifi_device returning error

Open alisonjenkins opened this issue 3 years ago • 4 comments

When importing a unifi_device I am receiving the following error:

terraform import unifi_device.office_switch 'f4:92:bf:8b:7b:65'
unifi_device.office_switch: Importing from ID "f4:92:bf:8b:7b:65"...

Error: unable to decode body: GET s/default/stat/device unable to unmarshal alias: unable to unmarshal alias: json: cannot unmarshal number into Go struct field .ht of type string

Do you have any advice on how to debug the response as this was previously working so I am wondering if this is due to an update of the Unifi Dream Machine's Network Management module.

alisonjenkins avatar Apr 13 '21 18:04 alisonjenkins

This may be a bug that was recently fixed in the SDK, hopefully will ship a new version shortly that fixes some of these marshalling issues.

Are you on the latest version of the provider?

paultyng avatar Apr 16 '21 17:04 paultyng

Hey Paul,

Yes I am on 0.26.0.

May I ask though... how do you find the API info and debug requests to the API at current? Do you use mitmproxy or something similar?

I am interested in helping to do some development on this provider (and also contemplating working on a Terraform provider of my own) so any advice on how to get started would be appreciated.

Thanks,

Alan Jenkins

alisonjenkins avatar Apr 19 '21 14:04 alisonjenkins

Confirmed this on 0.26.0 w/ UDM Pro Firmware 1.8.6 and Network 6.0.43.

chrishas35 avatar Apr 22 '21 23:04 chrishas35

I am seeing a similar issue, just with .stp_priority on 6.2.26 on a self-hosted controller:

❯ terraform import unifi_device.love-loft 74:ac:b9:a8:d6:96
unifi_device.love-loft: Importing from ID "74:ac:b9:a8:d6:96"...

│ Error: unable to decode body: GET s/default/stat/device unable to unmarshal alias: json: cannot unmarshal number into Go struct field .stp_priority of type string

kradalby avatar Jun 27 '21 13:06 kradalby

I'm seeing the same issue as @kradalby, when planning:

│ Error: unable to decode body: GET s/default/stat/device unable to unmarshal alias: json: cannot unmarshal number into Go struct field .stp_priority of type string
│ 
│   with unifi_device.kjokken,
│   on aps.tf line 15, in resource "unifi_device" "kjokken":
│   15: resource "unifi_device" "kjokken" {

I've enabled STP under Networks in the GUI, and overridden the manual configuration for a switch. Reverting the change gives the same behaviour. Should it be changed to numberOrString here?

evenh avatar Oct 30 '22 10:10 evenh

@evenh I think you are correct, when I just inspected my traffic i saw "stp_priority": "32768"

paultyng avatar Oct 31 '22 19:10 paultyng

I'll do a quick update and regenerate the SDK and bump the version.

paultyng avatar Oct 31 '22 19:10 paultyng

This fix should go out in v0.38.2, I'm not 100% sure it will fix this, but worth a shot!

paultyng avatar Oct 31 '22 20:10 paultyng

If it doesn't fix it, just let me know here and I'll reopen it

paultyng avatar Oct 31 '22 20:10 paultyng

Confirming this had been an issue and is now fixed in v0.38.2 w/ UDM Pro Firmware 1.12.30 and Network 7.2.94/7.2.95. Thank you!

woneill avatar Nov 02 '22 01:11 woneill