resource "docker_image" "octoprint" {
  provider = docker.printi
  name     = "octoprint"
  build {
    context = "${path.module}/printers"
    target  = "octoprint-mjpg-streamer"
    tag     = ["ti-octoprint:latest"]
  }
}

resource "docker_volume" "ender5plus" {
  provider = docker.printi
  name     = "ender5plus_config"
}
resource "scratch_string" "arse" {
  in = yamlencode(docker_image.octoprint)
}

resource "docker_container" "ender5plus" {
  image    = docker_image.octoprint.image_id
  provider = docker.printi
  name     = "ender5plus"
  env = [
    "ENABLE_MJPG_STREAMER=false"
  ]
  network_mode = "bridge"
  restart      = "always"
  ports {
    internal = 80
    external = 3000
  }
  devices {
    host_path      = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A602AFFK-if00-port0"
    container_path = "/dev/ttyACM0"
    permissions    = "rwm"
  }
  volumes {
    container_path = "/octoprint"
    #host_path = docker_volume.ender5plus.name
    volume_name = docker_volume.ender5plus.name
  }
}