I’m trying to achieve a setup whereby i can tear down a droplet and reattach it to a volume whenever i need to update code etc.

But after i re attach the volume to the droplet , all the data is gone.
here is my config:

resource "digitalocean_volume" "main-api" {
    region = "lon1"
    name = "ms-vol-two"
    size = 2
    initial_filesystem_type = "ext4"
    description = "File storage for postgres"

resource "digitalocean_droplet" "main-api" {
    image = "docker-18-04"
    name = "main-api"
    region = "lon1"
    size = "512mb"
    private_networking = true
    ssh_keys = [
 ... etc


resource "digitalocean_volume_attachment" "main-api" {
    droplet_id = digitalocean_droplet.main-api.id
    volume_id = digitalocean_volume.main-api.id

When i SSH into the droplet i /mnt/msvoltwo exists but has no data. I can create data there and it saves normally. But when i destroy the main-api droplet and then re run with terraform apply the droplet only has /mnt/msvoltwo but the data is no longer there..?
Thanks, Joe.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Sorry the paths above should be: