Volume data not persisting with Terraform


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 =
	volume_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.


Submit an 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: