Pulumi DigitalOcean: different name for droplet

117 views Asked by At

I'm creating a droplet in DigitalOcean with Pulumi. I have the following code:

name = "server"

droplet = digitalocean.Droplet(
     name,
     image=_image,
     region=_region,
     size=_size,
)

The server gets created successfully on DigitalOcean but the name in the DigitalOcean console is something like server-0bbc405 (upon each execution, it's a different name).

Why isn't it just the name I provided? How can I achieve that?

1

There are 1 answers

0
Christian Nunciato On BEST ANSWER

This is a result of auto-naming, which is explained here in the Pulumi docs:

https://www.pulumi.com/docs/intro/concepts/resources/names/#autonaming

The extra characters tacked onto the end of the resource name allow you to use the same "logical" name (your "server") with multiple stacks without risk of a collision (as cloud providers often require resources of the same kind to ba named uniquely). Auto-naming looks a bit strange at first, but it's incredibly useful in practice, and once you start working with multiple stacks, you'll almost surely appreciate it.

That said, you can generally override this name by providing a name in your list of resource arguments:

...
name = "server"

droplet = digitalocean.Droplet(
    name,
    name="my-name-override",     # <-- Override auto-naming
    image="ubuntu-18-04-x64",
    region="nyc2",
    size="s-1vcpu-1gb")

.. which would yield the following result:

+ pulumi:pulumi:Stack: (create)
    ...
    + digitalocean:index/droplet:Droplet: (create)
        ...
        name            : "my-name-override"  # <-- As opposed to "server-0bbc405"
        ...

.. but again, it's usually best to go with auto-naming for the reasons specified in the docs. Quoting here:

  • It ensures that two stacks for the same project can be deployed without their resources colliding. The suffix helps you to create multiple instances of your project more easily, whether because you want, for example, many development or testing stacks, or to scale to new regions.
  • It allows Pulumi to do zero-downtime resource updates. Due to the way some cloud providers work, certain updates require replacing resources rather than updating them in place. By default, Pulumi creates replacements first, then updates the existing references to them, and finally deletes the old resources.

Hope it helps!