paultyng / terraform-provider-unifi

Terraform provider for Unifi :satellite:
https://registry.terraform.io/providers/paultyng/unifi/latest/docs
Mozilla Public License 2.0
511 stars 91 forks source link

Error: invalid character '<' looking for beginning of value #296

Closed futojin closed 1 year ago

futojin commented 1 year ago

using "paultyng/unifi" version = "0.38.2" on UDM UniFi OS v1.12.33, Network v7.2.95

upon terraform apply on simple

resource "unifi_network" "wan" {
  name    = "WAN"
  purpose = "wan"
}

Throws

Error: invalid character '<' looking for beginning of value

with unifi_network.wan,
on unifi.tf line 20, in resource "unifi_network" "wan":
20: resource "unifi_network" "wan" {

Any ideas why?

futojin commented 1 year ago

I suspect this is caused by UniFi OS v1.12.33 which somehow breaking the underlying Go parsing of the API response. I don't have enough context and dev environment setup but will try to trace it when I got a chance.

joshuaspence commented 1 year ago

Can you provide debug logs? They might contain credentials so you might want to redact those.

UnifiOS version shouldn't matter as the provider talks to the Network application. I am on the latest version of Unifi Network (7.3) and am not seeing this error.

futojin commented 1 year ago

TLDR: The request caused UDM to return 500 Internal Server Error. Is there anything to be enabled on UDM before it can be controlled by TF? TF Debug generates a lot of text. Here's what I think the relevant logs, with some formatting to help with readability.

2022-12-07T17:36:05.860+1100 [DEBUG] provider.terraform-provider-unifi_v0.38.2.exe: Sending HTTP Request: X-Csrf-Token=82526c53-3b3c-4b32-888f-86f4a287e561 new_logger_warning="This log was generated by a subsystem logger that wasn't created before being used. Use tflog.NewSubsystem to create this logger before it is used." 
tf_http_op_type = request tf_http_req_body =
{
  "auto_scale_enabled": false,
  "dhcpd_boot_enabled": false,
  "dhcpd_boot_server": "",
  "dhcpd_dns_1": "",
  "dhcpd_dns_2": "",
  "dhcpd_dns_3": "",
  "dhcpd_dns_4": "",
  "dhcpd_dns_enabled": false,
  "dhcpd_enabled": false,
  "dhcpd_gateway": "",
  "dhcpd_gateway_enabled": false,
  "dhcpd_ip_1": "",
  "dhcpd_ip_2": "",
  "dhcpd_ip_3": "",
  "dhcpd_leasetime": 86400,
  "dhcpd_mac_1": "",
  "dhcpd_mac_2": "",
  "dhcpd_mac_3": "",
  "dhcpd_ntp_1": "",
  "dhcpd_ntp_2": "",
  "dhcpd_ntp_enabled": false,
  "dhcpd_start": "",
  "dhcpd_stop": "",
  "dhcpd_time_offset_enabled": false,
  "dhcpd_unifi_controller": "",
  "dhcpdv6_dns_auto": true,
  "dhcpdv6_enabled": false,
  "dhcpdv6_leasetime": 86400,
  "dhcpd_wins_1": "",
  "dhcpd_wins_2": "",
  "dhcpd_wins_enabled": false,
  "dhcp_relay_enabled": false,
  "dhcpguard_enabled": false,
  "dpi_enabled": false,
  "dpigroup_id": "",
  "domain_name": "",
  "enabled": true,
  "exposed_to_site_vpn": false,
  "gateway_device": "",
  "igmp_fastleave": false,
  "igmp_querier": "",
  "igmp_snooping": false,
  "igmp_supression": false,
  "ipsec_dynamic_routing": false,
  "ipsec_pfs": false,
  "ipv6_interface_type": "none",
  "ipv6_pd_prefixid": "",
  "ipv6_ra_enabled": false,
  "ipv6_ra_preferred_lifetime": 14400,
  "ipv6_ra_valid_lifetime": 86400,
  "internet_access_enabled": true,
  "intra_network_access_enabled": true,
  "is_nat": false,
  "l2tp_allow_weak_ciphers": false,
  "lte_lan_enabled": false,
  "mac_override": "",
  "mac_override_enabled": false,
  "mdns_enabled": false,
  "name": "WAN",
  "networkgroup": "LAN",
  "pptpc_require_mppe": false,
  "purpose": "wan",
  "radiusprofile_id": "",
  "remote_site_id": "",
  "report_wan_event": false,
  "require_mschapv2": false,
  "upnp_lan_enabled": false,
  "usergroup_id": "",
  "vlan_enabled": false,
  "vpn_client_default_route": false,
  "vpn_client_pull_dns": false,
  "wan_dns1": "",
  "wan_dns2": "",
  "wan_dns3": "",
  "wan_dns4": "",
  "wan_gateway_v6": "",
  "wan_ipv6": "",
  "wan_provider_capabilities": {},
  "wan_smartq_enabled": false,
  "wan_vlan_enabled": false,
  "wan_egress_qos": ""
}
tf_http_trans_id = 21a14175 - 6572 - a578 - ceb7 - 5bad1d69f650 User - Agent = terraform - provider - unifi / 0.1 Accept - Encoding = gzip Content - Type = "application/json; charset=utf-8" @ caller = github.com / hashicorp / terraform - plugin - sdk / v2 @ v2.24.0 / helper / logging / logging_http_transport.go: 157 @ module = provider.Unifi Content - Length = 1797 Cookie = TOKEN = eyJ[snip] - pe5D0VNG4A Host = 192.168.1.1 tf_http_req_uri = /proxy/network / api / s / default  / rest / networkconf tf_http_req_version = HTTP / 1.1 tf_http_req_method = POST timestamp = 2022 - 12 - 07T17: 36: 05.757 + 1100

2022-12-07T17:36:05.874+1100 [DEBUG] provider.terraform-provider-unifi_v0.38.2.exe: Received HTTP Response: Strict-Transport-Security="max-age=15552000; includeSubDomains" X-Download-Options=noopen 

tf_http_res_body="<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} 
.line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1></body></html>" 

@module=provider.Unifi Content-Length=455 X-Frame-Options=SAMEORIGIN new_logger_warning="This log was generated by a subsystem logger that wasn't created before being used. Use tflog.NewSubsystem to create this logger before it is used." 
Content-Type=text/html;charset=utf-8 Vary=Origin tf_http_op_type=response tf_http_res_version=HTTP/1.1 Date="Wed, 07 Dec 2022 06:36:03 GMT" Accept-Ranges=bytes @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.0/helper/logging/logging_http_transport.go:157 X-Csrf-Token=8252[snip]; path=/; samesite=none; secure; httponly" Content-Language=en X-Content-Type-Options=nosniff X-Xss-Protection="1; mode=block" tf_http_res_status_code=500 X-Dns-Prefetch-Control=off tf_http_trans_id=21a14175-6572-a578-ceb7-5bad1d69f650 Connection=keep-alive timestamp=2022-12-07T17:36:05.871+1100

2022-12-07T17:36:05.882+1100 [ERROR] provider.terraform-provider-unifi_v0.38.2.exe: Response contains error diagnostic: tf_provider_addr=provider tf_req_id=40b1168b-c23d-0b25-1639-581c576d3139 tf_resource_type=unifi_network tf_rpc=ApplyResourceChange diagnostic_severity=ERROR tf_proto_version=5.3 @module=sdk.proto diagnostic_detail= diagnostic_summary="invalid character '<' looking for beginning of value" @caller=github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/diag/diagnostics.go:55 timestamp=2022-12-07T17:36:05.871+1100
2022-12-07T17:36:05.887+1100 [ERROR] vertex "unifi_network.wan" error: invalid character '<' looking for beginning of value
╷
│ Error: invalid character '<' looking for beginning of value
│
│   with unifi_network.wan,
│   on unifi.tf line 20, in resource "unifi_network" "wan":
│   20: resource "unifi_network" "wan" {
│
joshuaspence commented 1 year ago

I've never seen that before. No there's nothing you need to do on the UniFi side. Do other resources work?

joshuaspence commented 1 year ago

I think your network resource is incomplete. You need to set other attributes such as wan_type

futojin commented 1 year ago

I just realised the WAN is kind of "read only" - it's not something you can add. After I imported the "WAN", it works. Though not after I almost bricked my (new) UDM. Had to reset to factory settings after experiencing internal server error. Sorry for the confusion. I'm going to close this.