I’m creating a volume from a snapshot and attaching it to a droplet. I’m attempting to mount the volume when it is created. According to the answer to the following question, all I need to do is specify “initial_filesystem_type”
However, although the volume is attached to the droplet, it is not being mounted.
resource "digitalocean_droplet" "droplet-instance" {
for_each = var.droplets
image = each.value.image
name = each.key
region = each.value.region
size = each.value.size
ssh_keys = each.value.ssh_keys
}
data "digitalocean_volume_snapshot" "droplet-snapshot" {
name = "${var.snapshot_name}"
}
resource "digitalocean_volume" "droplet-volume" {
for_each = var.droplets
region = each.value.region
name = "${each.key}-volume"
size = data.digitalocean_volume_snapshot.droplet-snapshot.min_disk_size
snapshot_id = data.digitalocean_volume_snapshot.droplet-snapshot.id
initial_filesystem_type = "ext4"
description = "an example volume"
}
resource "digitalocean_volume_attachment" "droplet-volume-attachment" {
for_each = var.droplets
droplet_id = digitalocean_droplet.droplet-instance[each.key].id
volume_id = digitalocean_volume.droplet-volume[each.key].id
}
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.
For anyone looking for an answer, I got it to work using a
null_resource
with aprovisioner
. The scripts to actually mount the volume are somewhat configurable.Using the volume_ids = [“${digitalocean_volume.VOLUME_NAME_HERE.id}”] approach had the same undesired results for me. The volume is successfully attached to the droplet, however it is not mounted on the file system.
I assume it was mounted under the “/mnt” directory for you?
Hey there, @julianbroudou,
So, I recreated the answer to the other question and it seems it did not work for me either. However, I tried another method (from Terraform docs) and it did the job just fine!
Instead of doing a whole new block of digitalocean_volume_attachment, you can simply add the following line in your digitalocean_droplet block. It goes like this:
volume_ids = [“${digitalocean_volume.VOLUME_NAME_HERE.id}”]
We have an array of volume IDs (in my case only 1 element) which is doing the same thing as digitalocean_volume_attachment.
In short, I would recommend deleting the digitalocean_volume_attachment block, and instead simply include the volume_ids argument in your digitalocean_droplet block.
I hope this helps, and please let me know if that solved your issue!
Best, Dennis