kreuzwerker / terraform-provider-docker

Terraform Docker provider
Mozilla Public License 2.0
609 stars 187 forks source link

Support for Docker Cluster Volumes #619

Open StoneMonarch opened 4 months ago

StoneMonarch commented 4 months ago

Community Note

Description

Support for all possible options in the docker cli command docker volume create allowing for Cluster Volumes to be created.

The current implementation only creates a volume on the node that terraform connects to, causing issues when the service and volume are on differant nodes.

The current workaround for this is to create each volume everytime it is needed in the docker_service resource.

New or Affected Resource(s)

Potential Terraform Configuration

resource "docker_volume" "test" {
  name = "test"
  driver_opts = {
    type   = "nfs"
    o      = "addr=test.server,rw"
    device = ":/mnt/Puddle/test"
  }
  scope  = "multi"
  sharing = "all"
  # All other `docker volume create` options
}

References

dantedevenir commented 2 months ago
/* 
The Problem:
 resource "docker_volume" "tmp_volume" {
    name = "tmp_volume"
    driver_opts = {
        "type" = "none"
        "device" = "${path.cwd}/_bindfolder"
        "o" = "bind"
    }
} */
 //Ugly Solution:
resource "null_resource" "set_volume_permissions" {
    provisioner "local-exec" {
        command = <<-EOT
            docker volume create \
                --name tmp_volume \
                --opt type=none \
                --opt device=${path.cwd}/_bindfolder \
                --opt o=bind
        EOT
    }
}