From 840ce49e981580d139e3de602b24c00fa9010be7 Mon Sep 17 00:00:00 2001
From: Nemo <me@captnemo.in>
Date: Tue, 21 Aug 2018 08:58:10 +0530
Subject: [PATCH] radicale: Migrate to container module

---
 main.tf               |  1 -
 radicale/main.tf      | 79 +++++++++++++++++++++++++++++++++++++------------------------------------------
 radicale/variables.tf |  4 ----
 3 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/main.tf b/main.tf
index b4599a3..add3ba4 100644
--- a/main.tf
+++ a/main.tf
@@ -56,7 +56,6 @@
 module "radicale" {
   source             = "radicale"
   domain             = "radicale.bb8.fun"
-  traefik-labels     = "${var.traefik-common-labels}"
   traefik-network-id = "${module.docker.traefik-network-id}"
 }
 
diff --git a/radicale/main.tf b/radicale/main.tf
index 490c5b4..f532d7c 100644
--- a/radicale/main.tf
+++ a/radicale/main.tf
@@ -1,50 +1,39 @@
-data "docker_registry_image" "radicale" {
-  name = "tomsquest/docker-radicale:latest"
-}
-
-resource "docker_image" "radicale" {
-  name          = "${data.docker_registry_image.radicale.name}"
-  pull_triggers = ["${data.docker_registry_image.radicale.sha256_digest}"]
-}
-
-resource "docker_container" "radicale" {
-  name  = "radicale"
-  image = "${docker_image.radicale.latest}"
-
-  labels = "${merge(
-    var.traefik-labels, map(
-      "traefik.port", 5232,
-      "traefik.frontend.rule","Host:${var.domain}"
-  ))}"
-
-  volumes {
-    host_path      = "/mnt/xwing/data/radicale"
-    container_path = "/data"
-  }
-
-  volumes {
-    host_path      = "/mnt/xwing/config/radicale"
-    container_path = "/config"
+module "container" {
+  name   = "radicale"
+  source = "../modules/container"
+  image  = "tomsquest/docker-radicale:latest"
+
+  web {
+    expose = true
+    port   = 5232
+    host   = "${var.domain}"
   }
 
-  upload {
-    content = "${file("${path.module}/config")}"
-    file    = "/config/config"
-  }
-
-  upload {
-    content = "${file("${path.module}/logging.conf")}"
-    file    = "/config/logging"
-  }
+  volumes = [
+    {
+      host_path      = "/mnt/xwing/data/radicale"
+      container_path = "/data"
+    },
+    {
+      host_path      = "/mnt/xwing/config/radicale"
+      container_path = "/config"
+    },
+  ]
+
+  uploads = [
+    {
+      content = "${file("${path.module}/config")}"
+      file    = "/config/config"
+    },
+    {
+      content = "${file("${path.module}/logging.conf")}"
+      file    = "/config/logging"
+    },
+    {
+      content = "${file("${path.module}/users")}"
+      file    = "/config/users"
+    },
+  ]
 
-  upload {
-    content = "${file("${path.module}/users")}"
-    file    = "/config/users"
-  }
-
   networks = ["${var.traefik-network-id}"]
-
-  restart               = "unless-stopped"
-  destroy_grace_seconds = 10
-  must_run              = true
 }
diff --git a/radicale/variables.tf b/radicale/variables.tf
index 500e0e6..b443d2f 100644
--- a/radicale/variables.tf
+++ a/radicale/variables.tf
@@ -1,9 +1,5 @@
 variable "domain" {
   type = "string"
 }
 
-variable "traefik-labels" {
-  type = "map"
-}
-
 variable "traefik-network-id" {}
--
rgit 0.1.5