<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>So, the <code>digitalocean_loadbalancer</code> resource has an optional <code>droplet_tag</code> argument, which can be used to supply a common tag given to the created nodes/droplets.</p>

<p>However, when declaring a load-balancer inside kubernetes, a new one will still be created. So for now at least, it would appear that defining the domain/CNAME record with terraform isn't possible on digitalocean</p>
