<p>I'm learning about creating a k8s cluster on DO using terraform, I've been trying to take the <code>ID</code> of the single K8s node I've created, and reference it from the loadbalancer.</p>

<p>The main reasoning for this is so that I can declare the FQDN in the <code>.tf</code> file.</p>

<p>First, here is the cluster declaration:</p>

<pre><code>
variable "digitalocean_token" {}

provider "digitalocean" {
  token = "${var.digitalocean_token}"
}

resource "digitalocean_kubernetes_cluster" "foo" {
  name    = "foo"
  region  = "nyc1"
  version = "1.12.1-do.2"

  node_pool {
    name       = "woker-pool"
    size       = "s-1vcpu-2gb"
    node_count = 1
  }
}

</code></pre>

<p>And here is the load balancer declaration:</p>

<pre><code>resource "digitalocean_loadbalancer" "foo" {
  name = "k8s-lb.nyc1"
  region = "nyc1"

  forwarding_rule {
    entry_port = 80
    entry_protocol = "http"

    target_port     = 80
    target_protocol = "http"
  }
  droplet_ids = ["${digitalocean_kubernetes_cluster.foo.node_pool.0.id}"]
}

output "loadbalancer_ip" {
  value = "${digitalocean_loadbalancer.foo.ip}"
}

resource "digitalocean_record" "terraform" {
  domain = "example.com" # "${digitalocean_domain.example.name}"
  type   = "A"
  name   = "terraform"
  value  =  "${digitalocean_loadbalancer.foo.ip}"
}

# Output the FQDN for the record
output "fqdn" {
  value = "${digitalocean_record.terraform.fqdn}"
}

</code></pre>

<p>I'm guessing that maybe the <code>digitalocean_loadbalancer</code> resources is only setup to work with individual droplets?</p>

<hr>

<p>Here are the output errors: when I run <code>terraform apply</code>:</p>

<pre><code>* output.loadbalancer_ip: Resource 'digitalocean_loadbalancer.foo' not found for variable 'digitalocean_loadbalancer.foo.ip'

* digitalocean_record.terraform: Resource 'digitalocean_loadbalancer.foo' not found for variable 'digitalocean_loadbalancer.foo.ip'

* digitalocean_loadbalancer.foo: droplet_ids.0: cannot parse '' as int: strconv.ParseInt: parsing "d4292e64-9c0a-4afb-83fc-83f239bcb4af": invalid syntax
</code></pre>

<hr>

<p>Pt. 2</p>

<p>I added a <code>digitalocean_droplet</code> resource, to see what kind of id was passed to the load balancer. </p>

<pre><code>resource "digitalocean_droplet" "web" {
  name      = "web-1"
  size      = "s-1vcpu-1gb"
  image     = "ubuntu-18-04-x64"
  region    = "nyc1"
}
</code></pre>

<p><code>digitalocean_kubernetes_cluster.foo.node_pool.0.id = '6ae6a787-d837-4e78-a915-cb52155f66fe'</code></p>

<p><code>digitalocean_droplet.web.id = 132533158</code></p>

<p>You're using the wrong attribute reference for your load balancer droplet ids.</p>

<p><code>droplet_ids = ["${digitalocean_kubernetes_cluster.foo.node_pool.0.id}"]</code></p>

<p>This will use the <code>node_pool</code> id linked <a href="https://www.terraform.io/docs/providers/do/r/kubernetes_cluster.html#id-1" rel="nofollow noreferrer">here</a></p>

<p>What you actually need to do is use the <code>node_pool</code> <em>nodes</em> id, which is referenced <a href="https://www.terraform.io/docs/providers/do/r/kubernetes_cluster.html#id-2" rel="nofollow noreferrer">here</a></p>

<pre><code>droplet_ids = "${digitalocean_kubernetes_cluster.foo.node_pool.0.nodes}"
</code></pre>

<p>The next problem you're going to have is that this returns a list of maps, and you'll need to build a list of ids from that. I'm not currently sure how to solve that, I'm afraid, but this should move you along hopefully.</p>

<p>It seems from your answer however, that what you want to do is update DNS for your loadbalancer.</p>

<p>You can do this <a href="https://github.com/kubernetes-incubator/external-dns" rel="nofollow noreferrer">external-dns</a> using the <a href="https://github.com/kubernetes-incubator/external-dns/blob/master/docs/tutorials/digitalocean.md" rel="nofollow noreferrer">digitalocean provider</a></p>

<p>Simply deploy this as a pod, specifying the required configuration, and ensure that the arg <code>--source=service</code> is set.</p>

<p>If you want to go a step further, and allow updating DNS with specific hostname, deploy an ingress controller like nginx-ingress and specify ingresses for your applications. The external-dns deployment (if you set <code>--source=ingress</code>) will the hostname from your ingress and update DNS for you.</p>
