DimensionDataResearch / terraform-provider-ddcloud

Terraform provider for Dimension Data cloud compute.
MIT License
16 stars 13 forks source link

Merge ddcloud_server_nic into ddcloud_server #68

Closed tintoy closed 7 years ago

tintoy commented 7 years ago

Implements #56.


Due to a limitation arising from differences between the CloudControl model and the Terraform life-cycle model, additional network adapters in a server are currently modelled as separate resources (see previous discussion relating to this change in #33 and #52). This is inelegant and unintuitive.

Now, however, I've worked out a way that we can do better :)

We now have the ability to match up network adapters by index (ddcloud_server.network_adapter is a List instead of a Set).

So for the simplest (default) case, you'd have something like:

resource "ddcloud_server" "server1" {
  name = "server1"

  # ...

  # Equivalent to primary_adapter_ipv4 = "10.0.12.30"
  #
  # This works because the default value for the index property is 0 (i.e. the primary adapter).
  network_adapter {
    ipv4 = "10.0.12.30"
  }
}

Or with multiple adapters:

resource "ddcloud_server" "server1" {
  name = "server1"

  # ...

  # Equivalent to primary_adapter_ipv4 = "10.0.12.30"
  network_adapter {
    ipv4  = "10.0.12.30"
  }

  # Equivalent to ddcloud_server_nic
  network_adapter {
    vlan  = "${var.vlan_id}"
    type  = "VMXNET3"
  }

  # Equivalent to ddcloud_server_nic
  network_adapter {
    ipv4  = "10.1.17.10"
    type  = "E1000"
  }
}

Note that the adapters must appear in the same order that they appear in CloudControl (with the primary network adapter being first, at index 0).

When we create each network adapter, we can store a calculated id property on it representing the adapter Id from CloudControl. This Id allows us to match up the adapter state with information returned by CloudControl.

tintoy commented 7 years ago

This feature is sufficiently mature to be merged back into the v1.2 branch.