Automatically Depart Terminated Supervisors in Terraform

For anyone using Terraform to manage hosts running Supervisors, we have found that explicitly departing those Supervisors when hosts are terminated is helpful. The code we use to accomplish this look like this:

  provisioner "remote-exec" {
    when       = "destroy"
    inline = [
      "set -ex",
      "sudo hab sup depart $(cat /hab/sup/default/MEMBER_ID)"

This gets the member id for the Supervisor on the host that’s about to be destroyed and departs that ID from the ring before termination.