paultyng/terraform-provider-unifi

Error: unable to decode body: GET s/default/get/setting/mgmt unable to unmarshal alias: json: cannot unmarshal object into Go struct field .x_ssh_keys of type string

BJ42V opened this issue · 2 comments

BJ42V commented

does not work unifi_setting_mgmt resource.

about

I set up the unifi_setting_mgmt resource as per the reference document, but I got a json unmarshal error.
There appears to be a difference between the structure used by the provider and the data type the API was expecting.

expected

  • I had hoped to be able to manage the site.
    https://${UDMP IP Addr}/network/site/default/settings/site
  • Or, they expected to be able to manage automatic system upgrades.
    https://${UDMP IP Addr}/settings/updates

system environment

device

  • UniFi Dream Machine Pro

controler

  • Firmware
    • 1.9.3
  • Netowrk App
    • 6.2.25

terraform

$ terraform version 
Terraform v1.0.0
on darwin_amd64
+ provider registry.terraform.io/paultyng/unifi v0.27.0

issue

error

Error: unable to decode body: GET s/default/get/setting/mgmt unable to unmarshal alias: json: cannot unmarshal object into Go struct field .x_ssh_keys of type string

sample code

locals {
  site_id = toset([
    "sample",
  ])
}

resource "unifi_site" "default" {
  for_each = local.site_id

  description = each.key
}

resource "unifi_setting_mgmt" "default" {
  for_each = local.site_id

  site         = unifi_site.default[each.key].name
  auto_upgrade = true
}

execute command

validate

$ terraform validate                                                                      
Success! The configuration is valid.

plan

$ terraform plan -var-file secret.tfvars
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # unifi_setting_mgmt.default will be created
  + resource "unifi_setting_mgmt" "default" {
      + auto_upgrade = true
      + id           = (known after apply)
      + site         = "default"
    }

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

import

$ terraform import -var-file secret.tfvars 'unifi_setting_mgmt.default["sample"]' default
unifi_setting_mgmt.default["sample"]: Importing from ID "default"...
unifi_setting_mgmt.default["sample"]: Import prepared!
  Prepared unifi_setting_mgmt for import
unifi_setting_mgmt.default["sample"]: Refreshing state... [id=default]
Error: unable to decode body: GET s/default/get/setting/mgmt unable to unmarshal alias: json: cannot unmarshal object into Go struct field .x_ssh_keys of type string

apply

$ terraform apply -var-file secret.tfvars -auto-approve -no-color
unifi_setting_mgmt.default["sample"]: Importing from ID "default"...
unifi_setting_mgmt.default["sample"]: Import prepared!
  Prepared unifi_setting_mgmt for import
unifi_setting_mgmt.default["sample"]: Refreshing state... [id=default]
Error: unable to decode body: GET s/default/get/setting/mgmt unable to unmarshal alias: json: cannot unmarshal object into Go struct field .x_ssh_keys of type string

hypothesis

  • The unifi_site resource has been created/imported correctly.
  • The unifi_setting_mgmt resource cannot be created or imported, resulting in the above error.
  • The site id and other attributes set in the unifi_setting_mgmt resource may be of the wrong type.
  • The Go structure field .x_ssh_keys may be of the wrong type.

and more

  • If you go to dashboard>settings>site, you can set several items other than auto_upgrade, so it is necessary for the terraform provider to be able to set these values as well.
    https://${UDMP IP Addr}/network/site/default/settings/site

reference docs

Should be fixed by paultyng/go-unifi#36

BJ42V commented

@joshuaspence
Thank you for sharing.
This Issue will be closed.