Support for network types per bond, and for the new hybrid-bonded type
Fixes #231
@displague will probably not be happy about the format of this PR, but I think this is the best way to add support for network type per bond (like it's in the UI), and for the hybrid-bonded network type.
I initally wanted to create a separate netwokr type transitions for the hybrid-bonded, but I realized it's very hard to do well. The hybrid-mixed type is reported when we assign a VLAN to a layer3 bond port of a device (of certain plans). The assigned VLAN is the only difference between layer3 and hybrid-bonded types. I think it's best to merge those two types, and leave the VLAN assignment up to the user.
If we assume a VLAN ID as a part of the network type hybrid-bonded, we would need to keep track of the assigned VLAN, and remove it once it's converted to some other network type. Problem is, that user can assign more vlans to the bond port later on. This is not hard to sanitize in the Golang SDK, but it would be disturbing for new terraform resource device_bond_network_type. If a user will assign VLANs explicitly in other resources, the device_bond_network_type will not be importable, because we can't say which was the VLAN that put it to the hybrid-bonded type. We will also need to store the inital VLAN id locally.
If we (sort of) merge the l3 and h-bonded types, we can achieve all that is possible in the UI, and we have a good chance to make the bond network state controllable in Terraform.
I put the new code intentionaly to new files, so that it can be reviewed easier.
Putting a device to hybrid-mixed network type is illustrated in TestAccPortBondNetworkStateHybridBonded. You should run the test in some faciltiy where c3.small.x86 is available, e.g.
PACKNGO_TEST_FACILITY=ny5 PACKNGO_DEBUG=1 PACKNGO_TEST_ACTUAL_API=1 go test -v -timeout=20m -run=TestAccPortBondNetworkStateHybridBonded
To illustrate how we could do hybrid-bonded in TF:
// substitute "packet" for "metal"
locals {
project_id = "<uuid>"
}
resource "packet_device" "test" {
hostname = "test"
plan = "c1.small.x86"
facilities = ["ny5"]
operating_system = "ubuntu_16_04"
billing_cycle = "hourly"
project_id = local.project_id
}
resource "packet_vlan" "test" {
facility = "ny5"
project_id = local.project_id
}
resource "packet_port_vlan_attachment" "test" {
count = local.device_count
device_id = packet_device_network_type.test.id
port_name = "bond0"
vlan_vnid = packet_vlan.test.vxlan
}
resource "packet_device_bond_network_type" "test" {
depends_on = [packet_port_vlan_attachment.test]
device_id = packet_device.test.id
bond_port = "bond0"
type = "hybrid-bonded"
}
.. there would be a diffSuppress making type hybrid-bonded and layer3 the same. The TF configuration would be a bit different from the web console, but enough documentation would clear it up I think.