-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote exec of volume mount doesn't work. #1060
Comments
Due to the way Terraform builds its dependency graph, the volume will not be attached to the Droplet before the Pre-formatted volumes are mounted automatically. By setting the resource "digitalocean_droplet" "nottoboard-web" {
image = "docker-20-04"
name = "nottoboard-web"
region = "lon1"
size = "s-1vcpu-1gb"
ssh_keys = [
data.digitalocean_ssh_key.nottoboard.id
]
}
resource "digitalocean_volume" "notto-media-1" {
name = "notto-media-1"
region = "lon1"
size = 10
initial_filesystem_type = "ext4"
description = "volume for storing django media file uploads"
}
resource "digitalocean_volume_attachment" "notto-media-1" {
droplet_id = digitalocean_droplet.nottoboard-web.id
volume_id = digitalocean_volume.notto-media-1.id
} If you need to interact with the volume from the resource "digitalocean_droplet" "nottoboard-web" {
image = "docker-20-04"
name = "nottoboard-web"
region = "nyc1"
size = "s-1vcpu-1gb"
ssh_keys = [
data.digitalocean_ssh_key.nottoboard.id
]
volume_ids = [ digitalocean_volume.notto-media-1.id ]
connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.pvt_key)
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"cloud-init status --wait",
"touch /mnt/notto_media_1/foo",
"echo 'hello world' > /mnt/notto_media_1/foo",
]
}
}
resource "digitalocean_volume" "notto-media-1" {
name = "notto-media-1"
region = "nyc1"
size = 10
initial_filesystem_type = "ext4"
description = "volume for storing django media file uploads"
} In this example, the Droplet depends on the volume. So the volume will be created before the Droplet. Also note the usage of |
Thanks very much @andrewsomething that's great. Let me know if you want me to close this issue, thank you. |
Glad that was helpful! |
I want to mount my volume for my droplet via a call to a remote exec:
This doesn't work, if i ssh into the droplet where the remote exec is called in, I get no mounted volume:
I therefore have to stop my docker compose stack, mount it manually in the droplet, then restart the docker compose stack, this works.
Is there a way to run this mounting from the terraform config script with a remote exec call? I use docker's bind volume to bind to the volume disc via docker compose volume bind:
The main terraform config:
The text was updated successfully, but these errors were encountered: