TritonDataCenter / terraform-provider-triton

Terraform Joyent Triton provider
https://www.terraform.io/docs/providers/triton/
Mozilla Public License 2.0
15 stars 24 forks source link

triton_machine: New stanza for locality hints/affinity rules #19

Closed jwreagor closed 7 years ago

jwreagor commented 7 years ago

This came up earlier in chat with @sean-. It's a feature request for supporting locality hints/affinity rules when placing Triton containers/VMs. This feature helps establish isolation or affinity of containers across a DC which is critical for implementing HA.

The following JSON snippet defines the existing contract through CloudAPI...

"locality": {
  "strict": false,
  "near": ["af7ebb74-59be-4481-994f-f6e05fa53075"],
  "far": ["da568166-9d93-42c8-b9b2-bce9a6bb7e0a", "d45eb2f5-c80b-4fea-854f-32e4a9441e53"]
}

From the docs...

Typically, Triton will allocate the new instance somewhere reasonable within the cloud. You may want this instance to be placed on the same server as another instance you have, or have it placed on an entirely different server from your existing instances so that you can spread them out. In either case, you can provide locality hints (aka 'affinity' criteria) to CloudAPI.

UUIDs provided should be the ids of instances belonging to you. If there is only a single UUID entry in an array, you can omit the array and provide the UUID string directly as the value to a near/far key.

strict defaults to false, meaning that Triton will attempt to meet all the near and/or far criteria but will still provision the instance when no server fits all the requirements. If strict is set to true, the creation of the new instance will fail if the affinity criteria cannot be met.

We're looking for an API like...

resource "triton_machine" "consul01" {
  name = "consul01"
}

resource "triton_machine" "consul02" {
  name = "consul02"
  locality {
    far_from = [ "${triton_machine.consul01.id}"]
  }
}

resource "triton_machine" "consul03" {
  name = "consul03"
  locality {
    far_from = [ "${triton_machine.consul01.id}", "${triton_machine.consul02.id}"]
  }
}

resource "triton_machine" "nomad01" {
  name = "nomad01"
  locality {
    strict = true
    close_to = [ "${triton_machine.consul01.id}" ]
  }
}

EDIT: Changed new API from near, to close_to.

/cc @jen20 @misterbisson