From e8dcd00e87d283768208600332c23e92e708022c Mon Sep 17 00:00:00 2001
From: Nemo <me@captnemo.in>
Date: Tue, 07 Aug 2018 02:55:46 +0530
Subject: [PATCH] Minor fixes in container zipmapping

---
 echoserver.tf               | 11 +++++++++++
 requestbin.tf               |  1 +
 docker/debug.tf             | 11 -----------
 modules/container/locals.tf |  4 ++++
 modules/container/main.tf   | 65 +++++++++++++++++++++++++++++++++++++++++++++--------------------
 modules/container/vars.tf   |  8 +++-----
 6 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/echoserver.tf b/echoserver.tf
new file mode 100644
index 0000000..23675cd 100644
--- /dev/null
+++ a/echoserver.tf
@@ -1,0 +1,11 @@
+module "echo-server" {
+  source = "modules/container"
+  name   = "echo-server"
+  image  = "jmalloc/echo-server:latest"
+
+  web {
+    expose = "true"
+    port   = 8080
+    host   = "debug.${var.root-domain},debug.in.${var.root-domain}"
+  }
+}
diff --git a/requestbin.tf b/requestbin.tf
index 9fac647..2aba230 100644
--- a/requestbin.tf
+++ a/requestbin.tf
@@ -6,6 +6,7 @@
   // Default is port 80
   web {
     expose = true
+    port   = "8000"
     host   = "requestbin.${var.root-domain}"
   }
 
diff --git a/docker/debug.tf b/docker/debug.tf
deleted file mode 100644
index 40011ef..0000000 100644
--- a/docker/debug.tf
+++ /dev/null
@@ -1,11 +1,0 @@
-module "echo-server" {
-  source = "../modules/container"
-  name   = "echo-server"
-  image  = "jmalloc/echo-server:latest"
-
-  web {
-    expose = true
-    port   = 8080
-    domain = "debug.${var.domain},debug.in.${var.domain}"
-  }
-}
diff --git a/modules/container/locals.tf b/modules/container/locals.tf
index 03d6daa..36da5d0 100644
--- a/modules/container/locals.tf
+++ a/modules/container/locals.tf
@@ -9,6 +9,10 @@
     "traefik.protocol"      = "${lookup(var.web, "protocol", "http")}"
   }
 
+  resource {
+    "memory" = "${lookup(var.resource, "memory", 64)}"
+  }
+
   traefik_common_labels {
     "traefik.enable" = "true"
 
diff --git a/modules/container/main.tf b/modules/container/main.tf
index 0cc2b01..9ef703c 100644
--- a/modules/container/main.tf
+++ a/modules/container/main.tf
@@ -18,9 +18,8 @@
   user       = "${var.user}"
   networks   = ["${var.networks}"]
 
-  # memory     = "${lookup(var.resource, "memory", "64")}"
+  memory = "${local.resource["memory"]}"
 
-
   # Look at this monstrosity
   # And then https://github.com/hashicorp/terraform/issues/12453#issuecomment-365569618
   # for why this is needed
@@ -28,71 +27,75 @@
   labels = "${merge(local.default_labels,
     zipmap(
       concat(
-        keys(local.traefik_common_labels),
-        split(",",
+        keys(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", keys(local.traefik_common_labels))
+            join("~", keys(local.traefik_common_labels))
         )
-      ),concat(
-        values(local.traefik_common_labels),
-        split(",",
+      ),
+      concat(
+        values(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", values(local.traefik_common_labels))
+            join("~", values(local.traefik_common_labels))
         )
       )
     ),
-
     zipmap(
       concat(
-        keys(local.web),
-        split(",",
+        keys(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", keys(local.web))
+            join("~", keys(local.web))
         )
-      ),concat(
-        values(local.web),
-        split(",",
+      ),
+      concat(
+        values(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", values(local.web))
+            join("~", values(local.web))
         )
       )
     ),
+
 
     zipmap(
       concat(
-        keys(local.traefik_common_labels),
-        split(",",
+        keys(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", keys(local.traefik_common_labels))
+            join("~", keys(local.traefik_common_labels))
         )
-      ),concat(
-        values(local.traefik_common_labels),
-        split(",",
+      ),
+      concat(
+        values(local.default_labels),
+        split("~",
           lookup(var.web, "expose", "false") == "false" ?
             "" :
-            join(",", values(local.traefik_common_labels))
+            join("~", values(local.traefik_common_labels))
         )
       )
     ),
     zipmap(
       concat(
-        keys(local.traefik_auth_labels),
-        split(",",
+        keys(local.default_labels),
+        split("~",
           lookup(var.web, "auth", "false") == "false" ?
             "" :
-            join(",", keys(local.traefik_auth_labels))
+            join("~", keys(local.traefik_auth_labels))
         )
-      ),concat(
-        values(local.traefik_auth_labels),
-        split(",",
+      ),
+      concat(
+        values(local.default_labels),
+        split("~",
           lookup(var.web, "auth", "false") == "false" ?
             "" :
-            join(",", values(local.traefik_auth_labels))
+            join("~", values(local.traefik_auth_labels))
         )
       )
     )
diff --git a/modules/container/vars.tf b/modules/container/vars.tf
index e53865f..b3ff5fb 100644
--- a/modules/container/vars.tf
+++ a/modules/container/vars.tf
@@ -68,8 +68,8 @@
   description = "Web Configuration"
 
   default = {
-    expose    = "false"
-    basicauth = "false"
+    expose = "false"
+    auth   = "false"
   }
 }
 
@@ -80,7 +80,5 @@
 variable "resource" {
   description = "Resource usage for the container"
 
-  default = {
-    memory = ""
-  }
+  default = {}
 }
--
rgit 0.1.5