Giving your servers fun pet names with Terraform

You are probably aware that that Terraform have a random number module that works like this:

resource "random_integer" "server-id" {
  min = 100
  max = 999
}

However, this isn’t very helpful as is, because it would regenerate new numbers after each Terraform run.

You can introduce a “keepers”-stanza that makes the random number dependent on the input, it works like this:

resource "random_integer" "server-id" {
  min = 100
  max = 999

  keepers = {
    image = data.digitalocean_images.server-images.images.0.image
  }
}

So now Terraform will only change the number when data.digitalocean_images.server-images.images.0.image changes, very handy!

So what about those pet names then?! #

The random2-module provides us with a random_pet-resource that works like this:

resource "random_pet" "server-pet" {
  length = 2

  keepers = {
    image = data.digitalocean_images.server-images.images.0.image
  }
}

And it can be used like this:

resource "digitalocean_droplet" "server" {
  name = "server-${random_pet.server-pet.id}${random_integer.server-id.result}"

Examples on some fun names I’ve had:

 
1
Kudos
 
1
Kudos

Now read this

Tsohost.com stores passwords in cleartext

Okay, it is 2015, we all know that is it a horrendously bad idea to store passwords in cleartext. Yet, when I log in to Tsohost’s interface I am greeted with this: Ugh! So either they store one version of the password in cleartext, and... Continue →