kreuzwerker/terraform-provider-docker

Support for Docker Cluster Volumes

Opened this issue ยท 2 comments

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

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)

  • docker_volume

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

/* 
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
	}
}

Cluster volume support does not apply to the local / default volume plugin.
You need to install a docker CSI volume plugin and explicitly reference it from docker_volume.driver for the "cluster" options to docker volume create... to have any effect or meaning.

If you fill out all the volume_options in the docker_service.mounts definition, docker will create the volume on each node as tasks are scheduled on that node as long as a volume with that name does not already exist.