equinix/terraform-provider-metal

hybrid network device unbonded via terraform.

gricuk opened this issue · 3 comments

I trying to create metal_device with hybrid-bonded network including 2 vlans

//metal device test
resource "metal_device" "test" {
  hostname         = "test"
  plan             = "c3.small.x86"
  metro            = "fr"
  operating_system = "ubuntu_20_04"
  billing_cycle    = "hourly"
  project_id       = metal_project.project.id
}

resource "metal_device_network_type" "test" {
  device_id = metal_device.test.id
  type      = "hybrid"
}

resource "metal_port_vlan_attachment" "test_vlan3001" {
  device_id = metal_device_network_type.test.id
  port_name = "bond0"
  vlan_vnid = metal_vlan.vlan_frankfurt1.vxlan
}

resource "metal_port_vlan_attachment" "test_vlan3002" {
  device_id = metal_device_network_type.test.id
  port_name = "bond0"
  vlan_vnid = metal_vlan.vlan_frankfurt2.vxlan
}

### Expected Behavior
Terraform should create metal device with layer 3 and then convert network type to Hybrid-bonded with 2 vlans.

### Actual Behavior
Terraform created metal device and set hybrid-unbonded network type with 2 vlans.

When I try to do the same via UI - it works as expected.

@gricuk sorry for the late response here.

To get hybrid-bonded, you can remove the metal_device_network_type resource. The EM API will automatically use hybrid-bonded if a layer3 device has VLAN attachments made to it. You could also set the metal_device_network_type.type to layer3 for the same effect, but that is the default so you don't need anything at all.

Relates to equinix/terraform-provider-equinix#193

This question has come up a few times in different places. The metal_device_network_type documentation should include a note about this.

Effectively:

The Terraform mode hybrid is hybrid-unbonded as it is called in other places. This is what this mode has always meant in the Terraform provider, the keyword hasn't changed for compatibility reasons.

The default mode (layer3) is how you can achieve hybrid-bonded states. You do not need a metal_device_network_type resource at all to use this, just attach VLANs to the device in the default mode (or set metal_device_network_type mode to layer3, this is not recommended because the API returns 422 errors when the desired state is already set). Use the upcoming metal_port resource instead (#116).

@gricuk The metal_port resource was released at the end of September in v3.2.0.

See https://registry.terraform.io/providers/equinix/metal/latest/docs/guides/network_types for details on how to achieve different network modes using the metal_port and metal_device_network_type resources.