resource "docker_image" "influxdb" {
  name = "influxdb:2.7.3"
}

resource "docker_volume" "influxdb" {
  name = "influxdb"
}

resource "docker_container" "influxdb" {
  image      = docker_image.influxdb.image_id
  name       = "influxdb"
  privileged = false
  must_run   = true

  networks_advanced {
    name = data.docker_network.traefik.name
  }

  command = [
    "--reporting-disabled",
  ]

  dynamic "labels" {
    for_each = [
      { label = "traefik.enable", value = "true" },
      { label = "traefik.docker.network", value = data.docker_network.traefik.name },
      { label = "traefik.http.routers.influxdb.rule", value = "Host(`influxdb.vpn.trygvis.io`)" },
      { label = "traefik.http.routers.influxdb.entrypoints", value = "websecure" },
      { label = "traefik.http.routers.influxdb.tls.certresolver", value = "linode" },
    ]
    content {
      label = labels.value["label"]
      value = labels.value["value"]
    }
  }

  env = [
  ]

  volumes {
    volume_name    = docker_volume.influxdb.name
    container_path = "/var/lib/influxdb2"
  }
}