From 1926474aa42fc862c55b1be5d01d44b02f5f7107 Mon Sep 17 00:00:00 2001
From: Nemo <me@captnemo.in>
Date: Tue, 23 Jan 2018 12:11:43 +0530
Subject: [PATCH] Create a new airsonic database

---
 main.tf                    | 11 +++++++----
 variables.tf               |  2 ++
 docker/main.tf             |  6 +++---
 monitoring/transmission.tf |  2 +-
 mysql/main.tf              | 18 ++++++++++++++++++
 mysql/variables.tf         |  4 ++++
 6 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/main.tf b/main.tf
index d94433b..cbfe13f 100644
--- a/main.tf
+++ a/main.tf
@@ -5,11 +5,12 @@
 }
 
 module "mysql" {
-  source                = "mysql"
-  mysql_root_password   = "${var.mysql_root_password}"
-  mysql_lychee_password = "${var.mysql_lychee_password}"
-  mysql_kodi_password   = "${var.mysql_kodi_password}"
-  lychee_ip             = "${module.docker.lychee-ip}"
+  source                  = "mysql"
+  mysql_root_password     = "${var.mysql_root_password}"
+  mysql_lychee_password   = "${var.mysql_lychee_password}"
+  mysql_airsonic_password = "${var.mysql_airsonic_password}"
+  mysql_kodi_password     = "${var.mysql_kodi_password}"
+  lychee_ip               = "${module.docker.lychee-ip}"
 }
 
 module "docker" {
diff --git a/variables.tf b/variables.tf
index 2524023..6da20ad 100644
--- a/variables.tf
+++ a/variables.tf
@@ -17,6 +17,8 @@
 
 variable "mysql_lychee_password" {}
 
+variable "mysql_airsonic_password" {}
+
 variable "mysql_kodi_password" {}
 
 variable "wiki_session_secret" {
diff --git a/docker/main.tf b/docker/main.tf
index 9ef72f5..6a44216 100644
--- a/docker/main.tf
+++ a/docker/main.tf
@@ -157,9 +157,9 @@
   }
 
   labels {
-    "traefik.enable" = "true"
-    "traefik.port"   = "4040"
-    "traefik.frontend.rule" = "Host:airsonic.in.${var.domain},airsonic.${var.domain}"
+    "traefik.enable"                  = "true"
+    "traefik.port"                    = "4040"
+    "traefik.frontend.rule"           = "Host:airsonic.in.${var.domain},airsonic.${var.domain}"
     "traefik.frontend.passHostHeader" = "true"
   }
 
diff --git a/monitoring/transmission.tf b/monitoring/transmission.tf
index c3e0018..2019849 100644
--- a/monitoring/transmission.tf
+++ a/monitoring/transmission.tf
@@ -7,7 +7,7 @@
   links = ["transmission"]
 
   env = [
-    "TRANSMISSION_ADDR=http://transmission:9091"
+    "TRANSMISSION_ADDR=http://transmission:9091",
   ]
 
   restart               = "unless-stopped"
diff --git a/mysql/main.tf b/mysql/main.tf
index 1f368de..d94e904 100644
--- a/mysql/main.tf
+++ a/mysql/main.tf
@@ -17,3 +17,21 @@
   database   = "${mysql_database.lychee.name}"
   privileges = ["ALL"]
 }
+
+# Create a Database
+resource "mysql_database" "airsonic" {
+  name = "airsonic"
+}
+
+resource "mysql_user" "airsonic" {
+  user               = "airsonic"
+  host               = "%"
+  plaintext_password = "${var.mysql_airsonic_password}"
+}
+
+resource "mysql_grant" "airsonic" {
+  user       = "${mysql_user.airsonic.user}"
+  host       = "${mysql_user.airsonic.host}"
+  database   = "${mysql_database.airsonic.name}"
+  privileges = ["ALL"]
+}
diff --git a/mysql/variables.tf b/mysql/variables.tf
index 2990d8d..a8bd97f 100644
--- a/mysql/variables.tf
+++ a/mysql/variables.tf
@@ -6,6 +6,10 @@
   type = "string"
 }
 
+variable "mysql_airsonic_password" {
+  type = "string"
+}
+
 variable "mysql_kodi_password" {
   type = "string"
 }
--
rgit 0.1.5