Cloud-init files are essentially bootstrap codes, that run before each startup, and can - among others - modify files, set up services, create users, etc.
Not all types of droplets support all functionalities of cloud-init, for example CoreOS uses it's own implementation, with a very limited subset of valid values.
To use this in terraform, simply provide the cloud-init file during droplet creation:
main.tf:
resource "digitalocean_droplet" "web" { image = "coreos-stable" name = "web" region = "lon1" size = "2gb" private_networking = true ssh_keys = ["${digitalocean_ssh_key.dodemo.id}"] user_data = "${file("web.conf")}" }
web.conf:
#cloud-config coreos: units: - name: "etcd2.service" command: "start" - name: "fleet.service" command: "start"
This will for example create a droplet, where CoreOS will run etcd2 and fleet during startup
You can find some more examples in this repository, where I show how one can use these configuration options to set up some simple docker based services on CoreOS