0

Here is an example of creating a managed Kubernetes cluster on DigitalOcean.

import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const foo = new digitalocean.KubernetesCluster("foo", {
    region: "nyc1",
    version: "1.20.2-do.0",
    nodePool: {
        name: "front-end-pool",
        size: "s-2vcpu-2gb",
        nodeCount: 3,
    },
});

Example code taken from the Pulumi DigitalOcean package documentation.

How do I retrieve the droplet node IPv4 addresses for use in say creating DnsRecord resources?

const _default = new digitalocean.Domain("default", {name: "example.com"});

// This code doesn't work because foo.nodePool is just the inputs.
const dnsRecords = foo.nodePool.nodes(node => new digitalocean.DnsRecord("www", {
    domain: _default.name,
    type: "A",
    value: node.ipv4Address,
}));

1 Answer 1

1

DigitalOcean doesn't return a list of node IP addresses from the Kubernetes cluster you created. You can retrieve these values using the getDroplet function.

However, you'll need to do this iteration inside an apply() like so:

const addresses = foo.nodePool.nodes.apply(
    nodes => nodes.forEach(
        (node) => {
            let n = digitalocean.getDropletOutput({
                name: node.name
            })
            new digitalocean.DnsRecord("www", {
                domain: domain.name,
                type: "A",
                value: n.ipv4Address,
            })
        }
    )
)

Using an apply here lets us wait until the foo.nodePool.nodes has been created by the API. We can then iterate over it like a normal array, get the droplet, assign it to the variable n and then create a new DNS record for each of the nodes

2
  • getDropletOutput returns a promse doesn't it need awaiting?
    – jshbrntt
    Jan 6, 2022 at 17:10
  • not if you're passing the result to another resource, no.
    – jaxxstorm
    Jan 6, 2022 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.