Report this

What is the reason for this report?

Volume data not persisting with Terraform

Posted on April 16, 2020

Hi,

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 = [
		var.ssh_fingerprint
	]
 ... 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/ms_vol_two 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/ms_vol_two but the data is no longer there…? Thanks, Joe.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Sorry the paths above should be:

/mnt/ms_vol_two

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.