'terraform doesnt create docker volumes

I am trying to create a docker image and mount two volumes which I have defined as variables. The problem that I have is that the volumes do not get created locally.

# main.tf
resource "docker_container" "pihole" {
  name  = var.container_name
  image = docker_image.pihole.latest
...
  dynamic "volumes" {
    for_each = var.volume_mappings
    iterator = each
    content {
      volume_name    = each.value.volume_name
      host_path      = each.value.host_path
      container_path = each.value.container_path
      read_only      = each.value.read_only
    }
  }
...

# variables.tf
variable "volume_mappings" {
  description = "List of all the volume mappings"
  type        = list(any)
  default = [
    {
      volume_name    = "data"
      host_path      = "/terraform/pihole/etc-pihole/"
      container_path = "/etc/pihole/"
      read_only      = false
    },
    {
      volume_name    = "dnsmasq"
      host_path      = "/terraform/pihole/etc-dnsmasq.d/"
      container_path = "/etc/dnsmasq.d/"
      read_only      = false
    }
  ]
}

When I try to find the volumes it says that they are in /var/lib/docker/volumes, location which does not exist on my disk.

darcey@darcey-5200u:~/Desktop/terraform/pihole$ sudo docker inspect 954 | grep volume
                "Type": "volume",
                "Source": "/var/lib/docker/volumes/data/_data",
                "Type": "volume",
                "Source": "/var/lib/docker/volumes/dnsmasq/_data",

Same thing applies for when I inspect the volumes

darcey@darcey-5200u:~/Desktop/terraform/pihole$ sudo docker volume ls
DRIVER    VOLUME NAME
local     data
local     dnsmasq
darcey@darcey-5200u:~/Desktop/terraform/pihole$ sudo docker volume inspect data
[
    {
        "CreatedAt": "2022-03-05T22:35:00Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/data/_data",
        "Name": "data",
        "Options": null,
        "Scope": "local"
    }
]
darcey@darcey-5200u:~/Desktop/terraform/pihole$ sudo docker volume inspect dnsmasq
[
    {
        "CreatedAt": "2022-03-05T22:33:52Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/dnsmasq/_data",
        "Name": "dnsmasq",
        "Options": null,
        "Scope": "local"
    }
]

Any idea why's that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source