paultyng/terraform-provider-unifi

Unable to determine API URL when refreshing unifi_site state

hatboyzero opened this issue · 3 comments

Imported a unifi_site resource using the Default site on my UCK. Went to plan and received the following error:

Waiting for the plan to start...

Terraform v1.0.11
on linux_amd64
Configuring remote state backend...
Initializing Terraform configuration...
unifi_site.site: Refreshing state... [id=60903d6b57b542184f03509c]
╷
│ Error: unable to determine API URL style: Get "https://192.168.1.7": dial tcp 192.168.1.7:443: i/o timeout
│
│   with unifi_site.site,
│   on site.tf line 1, in resource "unifi_site" "site":
│    1: resource "unifi_site" "site" {
│
╵

Can you curl that URL? You probably also need to set allow_insecure = true if you haven't.

allow_insecure = true is set, and access to the API appears fine when I import a site using terraform import, as illustrated in the output below with TF_LOG=TRACE (not including the entire log, just enough to illustrate that the API URL is working for the terraform import operation):

2021-11-21T19:45:25.741-0600 [INFO]  provider.terraform-provider-unifi_v0.34.0.exe: 2021/11/21 19:45:25 [DEBUG] Unifi API Request Details:
---[ REQUEST ]---------------------------------------
GET /proxy/network/status HTTP/1.1
Host: 192.168.1.7
User-Agent: terraform-provider-unifi/0.1
Content-Type: application/json; charset=utf-8
Cookie: TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjc3JmVG9rZW4iOiI0YWM3NmMyYy1lNzY2LTQ5OWUtYWZiOC1mMTU0MDJkZTMyODgiLCJ1c2VySWQiOiI1NTdmZGE3Zi0zODAyLTRjMTYtYmVkNS1lZWZkYWRmNDIxZWYiLCJpYXQiOjE2Mzc1NDU1MjYsImV4cCI6MTYzNzU0OTEyNn0.zwXivPtvPDXt6lfKCTJzKkvuyzScHXk8wcupuB5osZk
X-Csrf-Token: 4ac76c2c-e766-499e-afb8-f15402de3288
Accept-Encoding: gzip


-----------------------------------------------------: timestamp=2021-11-21T19:45:25.741-0600
2021-11-21T19:45:25.785-0600 [INFO]  provider.terraform-provider-unifi_v0.34.0.exe: 2021/11/21 19:45:25 [DEBUG] Unifi API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 200 OK
Connection: close
Content-Length: 76
Accept-Ranges: bytes
Content-Type: application/json;charset=UTF-8
Date: Mon, 22 Nov 2021 01:45:25 GMT
Set-Cookie: TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjc3JmVG9rZW4iOiI0YWM3NmMyYy1lNzY2LTQ5OWUtYWZiOC1mMTU0MDJkZTMyODgiLCJ1c2VySWQiOiI1NTdmZGE3Zi0zODAyLTRjMTYtYmVkNS1lZWZkYWRmNDIxZWYiLCJwYXNzd29yZFJldmlzaW9uIjoxNjM3MjkyNTMxLCJpYXQiOjE2Mzc1NDU1MjYsImV4cCI6MTYzNzU0OTEyNn0.yAYkh8M-3ghA_JpOyv8V74mwUtPL4BOzZjKaw
YpmVho; path=/; samesite=strict; secure; httponly
Strict-Transport-Security: max-age=15552000; includeSubDomains
Vary: Origin
X-Content-Type-Options: nosniff
X-Dns-Prefetch-Control: off
X-Download-Options: noopen
X-Frame-Options: DENY
X-Xss-Protection: 1; mode=block

{
 "meta": {
  "rc": "ok",
  "uuid": "44488255-067c-599f-914a-3e4c26084ec9"
 },
 "data": []
}
-----------------------------------------------------: timestamp=2021-11-21T19:45:25.784-0600

The issue was the agent on which the plan was running didn't have access to that endpoint, and the terraform import was run local to the network itself. FWIW, if you're using Terraform Cloud for your backend, make sure to configure the associated workspace as Local instead of Remote.