equinix/terraform-provider-metal

Improve Shared Connection usability

displague opened this issue · 6 comments

Shared metal_connection resources automatically provision Virtual Circuit resources.

To consume these resources you must with a shared connection:

  • create metal_vlan resources (very likely to need these, especially for dynamic projects)
  • create a metal_connection resource
  • apply or import the metal_connection
  • create a metal_virtual_circuit
  • import the automatically created metal_virtual_circuit
  • apply vlan changes to the metal_virtual_circuit

This becomes a manual process because the metal_cirtual_circuit must be imported.

What could improve the experience when working with shared connections?

I propose one of the following, but am open to other approaches:

resource "metal_connection_shared" "shared" {
   # connection params, except type which is always shared. 
   #  options unique to dedicated connections may be removed.
    name            = "My Interconnection"
    organization_id = local.my_organization_id
    project_id      = local.my_project_id
    metro           = "sv"
    redundancy      = "redundant"
    # implied / type            = "shared"

   # virtual-circuit params
    port_id = data.metal_connection.test.ports[0].id
    vlan_id = metal_vlan.test.id
    nni_vlan = 1056
   # inferred  / connection_id = local.conn_id
   # duplicated / project_id = local.project_id
}

Alternatively:

resource "metal_virtual_circuit_attachment" "test" {
    connection_id = local.conn_id
    project_id = local.project_id
   # does not create a new VC, applies settings to the matching virtual connection or errors if it is not matched

    port_id = data.metal_connection.test.ports[0].id
    vlan_id = metal_vlan.test.id
    nni_vlan = 1056
}

I'd love your feedback here, @christianhxc

Another approach could be:

resource "metal_connection" "shared" {
   # connection params, except type which is always shared. 
   #  options unique to dedicated connections may be removed.
    name            = "My Interconnection"
    organization_id = local.my_organization_id
    project_id      = local.my_project_id
    metro           = "sv"
    redundancy      = "redundant"
    # implied / type            = "shared"

   virtual-circuit { # would this field only be available for type=shared?
      vlan_id = metal_vlan.test.id
     #  nni_vlan = 1056, this is only a dedicated property, iirc
   }
}

@t0mk What are your thoughts?

t0mk commented

@displague A simple solution would be to export virtual_circuit ID like in the connection datasource
https://github.com/equinix/terraform-provider-metal/blob/main/metal/datasource_metal_connection.go#L140

Then the IDs can be used with the virtual circuit datasource

@jordan0day described expected changes to the shared connection API that could improve the experience here.

Closing this because the upstream API now accepts vlans as a root-level shared connection creation parameter. This is similar to the proposed interface here: #150 (comment).

This was introduced in https://github.com/equinix/terraform-provider-metal/pull/207/files#diff-63a950afa0409fa1aa9c2cc132c53a37ac6fab157008148f2702bc098e05c58aR36