Open joshuaspence opened 3 years ago
On an unrelated note, dhcp
seems to be a valid value for wan_type
, contrary to this provider's documentation.
The same thing happens with some other default values that Terraform tries to apply:
dhcp_lease
to 86400
.ipv6_interface_type
to "none"
.Actually this seems to be a problem with all networks created by the provider, I think, I just hadn't noticed it as I had imported my networks into Terraform rather than letting Terraform create them.
I created two almost-identical subnets, one via the UI and the other with Terraform.
When creating via the UI, the POST request looked like this:
{
"dhcp_relay_enabled": false,
"dhcpd_dns_enabled": false,
"dhcpd_enabled": false,
"dhcpd_gateway_enabled": false,
"dhcpd_leasetime": 86400,
"dhcpd_time_offset_enabled": false,
"enabled": true,
"gateway_type": "default",
"ip_subnet": "192.168.50.1/24",
"ipv6_interface_type": "none",
"ipv6_pd_start": "::2",
"ipv6_pd_stop": "::7d1",
"is_nat": true,
"name": "Test 1",
"networkgroup": "LAN",
"purpose": "corporate",
"vlan": "50",
"vlan_enabled": true
}
The API response was
{
"data": [
{
"_id": "603edf20ddb88d4a962a7f2b",
"dhcp_relay_enabled": false,
"dhcpd_dns_enabled": false,
"dhcpd_enabled": false,
"dhcpd_gateway_enabled": false,
"dhcpd_leasetime": 86400,
"dhcpd_time_offset_enabled": false,
"enabled": true,
"gateway_type": "default",
"ip_subnet": "192.168.50.1/24",
"ipv6_interface_type": "none",
"ipv6_pd_start": "::2",
"ipv6_pd_stop": "::7d1",
"is_nat": true,
"name": "Test 1",
"networkgroup": "LAN",
"purpose": "corporate",
"site_id": "60375bd3ddb88d0148571192",
"vlan": "50",
"vlan_enabled": true
}
],
"meta": {
"rc": "ok"
}
}
When creating via Terraform, the POST request:
{
"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": false,
"dhcpdv6_enabled": false,
"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,
"ip_subnet": "192.168.51.1/24",
"ipv6_interface_type": "none",
"ipv6_pd_prefixid": "",
"ipv6_ra_enabled": false,
"is_nat": false,
"lte_lan_enabled": false,
"name": "Test 2",
"networkgroup": "LAN",
"pptpc_require_mppe": false,
"purpose": "corporate",
"radiusprofile_id": "",
"remote_site_id": "",
"report_wan_event": false,
"require_mschapv2": false,
"upnp_lan_enabled": false,
"usergroup_id": "",
"vlan": 51,
"vlan_enabled": true,
"vpn_client_default_route": false,
"vpn_client_pull_dns": false,
"wan_dns1": "",
"wan_dns2": "",
"wan_dns3": "",
"wan_dns4": "",
"wan_gateway": "",
"wan_gateway_v6": "",
"wan_ipv6": "",
"wan_smartq_enabled": false,
"wan_vlan_enabled": false
}
And the reponse:
{
"meta": {
"rc": "ok"
},
"data": [
{
"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": false,
"dhcpdv6_enabled": false,
"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,
"ip_subnet": "192.168.51.1/24",
"ipv6_interface_type": "none",
"ipv6_pd_prefixid": "",
"ipv6_ra_enabled": false,
"is_nat": false,
"lte_lan_enabled": false,
"name": "Test 2",
"networkgroup": "LAN",
"pptpc_require_mppe": false,
"purpose": "corporate",
"radiusprofile_id": "",
id": "",
"report_wan_event": false,
"require_mschapv2": false,
"upnp_lan_enabled": false,
"usergroup_id": "",
"vlan": 51,
"vlan_enabled": true,
"vpn_client_default_route": false,
"vpn_client_pull_dns": false,
"wan_dns1": "",
"wan_dns2": "",
"wan_dns3": "",
"wan_dns4": "",
"wan_gateway": "",
"wan_gateway_v6": "",
"wan_ipv6": "",
"wan_smartq_enabled": false,
"wan_vlan_enabled": false,
"site_id": "60375bd3ddb88d0148571192",
"_id": "603edfbaddb88d4a962a80bc"
}
]
}
Also some warnings in the Terraform logs that may or may not be relevant:
2021/03/03 12:00:41 [WARN] Provider "registry.terraform.io/paultyng/unifi" produced an unexpected new value for unifi_network.test, but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
- .x_wan_password: was null, but now cty.StringVal("")
- .igmp_snooping: was null, but now cty.False
- .wan_username: was null, but now cty.StringVal("")
- .ipv6_ra_enable: was null, but now cty.False
- .ipv6_static_subnet: was null, but now cty.StringVal("")
- .wan_ip: was null, but now cty.StringVal("")
- .domain_name: was null, but now cty.StringVal("")
- .ipv6_pd_interface: was null, but now cty.StringVal("")
- .wan_networkgroup: was null, but now cty.StringVal("")
- .dhcp_enabled: was null, but now cty.False
- .dhcp_start: was null, but now cty.StringVal("")
- .wan_type: was null, but now cty.StringVal("")
- .ipv6_pd_prefixid: was null, but now cty.StringVal("")
- .subnet: was cty.StringVal("192.168.51.1/24"), but now cty.StringVal("192.168.51.0/24")
- .dhcp_stop: was null, but now cty.StringVal("")
This may be related to the v6 controller, I haven't tested it very thoroughly in it yet, my UDM just was upgraded recently, I'll need to take a peek.
What version of the controller are you using and how are you running it (docker, UDM, UDM-Pro?, etc.)?
Controller version is 6.0.45 and it's currently running as a Home Assistant add-on (so Docker).
Still investigating this, the tests all run against docker so that's at least not the issue.
It seems like you are aware and already doing this, but I think the main thing to be aware of for anyone else coming to this issue is that the UI will be defaulting a lot of things that Terraform won't, so you'll have to be a lot more explicit in Terraform. Doing an import after configuring in the UI and updating your configuration until there is no diff is probably the easiest way to achieve this, but this may be an issue of Terraform not managing some of the newer v6 settings or something.
Just added a number of WAN settings for static WAN configuration in #119 based on your work and someone else's. I'll publish a new version of the provider shortly and we can see if that helps and what other fields we may need to address.
We may still need to include #118, just didn't get a chance to look at it yet, but hopefully this coming week.
No problem. I managed the solve the issue by modifying the network config in MongoDB and so it's easy for me to test this now, I can just restore a backup if it breaks things.
It looks like this same situation is going to happen for the other network types as well (VPN, etc). I need to get a VPN setup manually and look at the responses there.
I am affected by this issue as well. Is there a solution or workaround apart from fiddling with the mongo database? I'd rather avoid changing anything by bypassing the unifi api..
Ah nevermind. I just found out that I had to set network_group to an empty string instead of null for wan networks..
Terraform wanted to set
network_group
to"LAN"
(the default value) on my WAN network, but doing so seemed to break things somehow. Before applying this change, this is what I saw in the UI:After Terraform set
network_group
, the network appears to have been dissociated from the gateway device:This is what the WAN network looked like from the API before and after setting
network_group
:Before
After
I'm happy to submit a PR to fix this, although I'm not sure why no-one else is reporting any issues...,.