From d23827c19a823e64477505158a43701740776bd1 Mon Sep 17 00:00:00 2001 From: Nemo Date: Sat, 4 Nov 2017 19:09:32 +0530 Subject: [PATCH] Initial commit --- .gitignore | 3 + cloudflare/main.tf | 42 ++++++++ cloudflare/variables.tf | 11 +++ docker/data.tf | 19 ++++ docker/main.tf | 206 ++++++++++++++++++++++++++++++++++++++++ docker/variables.tf | 11 +++ main.tf | 26 +++++ mysql/main.tf | 25 +++++ variables.tf | 21 ++++ 9 files changed, 364 insertions(+) create mode 100644 .gitignore create mode 100644 cloudflare/main.tf create mode 100644 cloudflare/variables.tf create mode 100644 docker/data.tf create mode 100644 docker/main.tf create mode 100644 docker/variables.tf create mode 100644 main.tf create mode 100644 mysql/main.tf create mode 100644 variables.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9df7ff --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +env.sh +.terraform +*.tfstate \ No newline at end of file diff --git a/cloudflare/main.tf b/cloudflare/main.tf new file mode 100644 index 0000000..2ef76e2 --- /dev/null +++ b/cloudflare/main.tf @@ -0,0 +1,42 @@ +resource "cloudflare_record" "home-wildcard" { + domain = "${var.domain}" + name = "*.in" + value = "192.168.1.111" + type = "A" + ttl = 300 +} + +resource "cloudflare_record" "home" { + domain = "${var.domain}" + name = "in" + value = "192.168.1.111" + type = "A" +} + +resource "cloudflare_record" "internet" { + domain = "${var.domain}" + name = "@" + value = "${var.proxy}" + type = "CNAME" +} + +resource "cloudflare_record" "internet-wildcard" { + domain = "${var.domain}" + name = "*.bb8.fun" + value = "${var.proxy}" + type = "CNAME" +} + +resource "cloudflare_record" "act" { + domain = "${var.domain}" + name = "act" + value = "${var.act_ip}" + type = "A" +} + +resource "cloudflare_record" "act-wildcard" { + domain = "${var.domain}" + name = "*.act" + value = "${var.act_ip}" + type = "A" +} \ No newline at end of file diff --git a/cloudflare/variables.tf b/cloudflare/variables.tf new file mode 100644 index 0000000..ff07cd8 --- /dev/null +++ b/cloudflare/variables.tf @@ -0,0 +1,11 @@ +variable "domain" { + type = "string" +} + +variable "proxy" { + type = "string" +} + +variable "act_ip" { + type = "string" +} \ No newline at end of file diff --git a/docker/data.tf b/docker/data.tf new file mode 100644 index 0000000..bda834d --- /dev/null +++ b/docker/data.tf @@ -0,0 +1,19 @@ +data "docker_registry_image" "mariadb" { + name = "mariadb:10.3" +} + +data "docker_registry_image" "emby" { + name = "emby/embyserver:latest" +} + +data "docker_registry_image" "transmission" { + name = "linuxserver/transmission:latest" +} + +data "docker_registry_image" "flexget" { + name = "cpoppema/docker-flexget" +} + +data "docker_registry_image" "couchpotato" { + name = "linuxserver/couchpotato:latest" +} \ No newline at end of file diff --git a/docker/main.tf b/docker/main.tf new file mode 100644 index 0000000..894ad0d --- /dev/null +++ b/docker/main.tf @@ -0,0 +1,206 @@ +resource "docker_image" "emby" { + name = "${data.docker_registry_image.emby.name}" + pull_triggers = ["${data.docker_registry_image.emby.sha256_digest}"] +} + +resource "docker_image" "mariadb" { + name = "${data.docker_registry_image.mariadb.name}" + pull_triggers = ["${data.docker_registry_image.mariadb.sha256_digest}"] +} + +resource "docker_image" "transmission" { + name = "${data.docker_registry_image.transmission.name}" + pull_triggers = ["${data.docker_registry_image.transmission.sha256_digest}"] +} + +resource "docker_image" "flexget" { + name = "${data.docker_registry_image.flexget.name}" + pull_triggers = ["${data.docker_registry_image.flexget.sha256_digest}"] +} + +resource "docker_image" "couchpotato" { + name = "${data.docker_registry_image.couchpotato.name}" + pull_triggers = ["${data.docker_registry_image.couchpotato.sha256_digest}"] +} + +resource "docker_volume" "mariadb_volume" { + name = "mariadb_volume" +} + +resource docker_container "transmission" { + name = "transmission" + image = "${docker_image.transmission.latest}" + + ports { + internal = 9091 + external = 9091 + ip = "10.8.0.14" + } + + ports { + internal = 51413 + external = 51413 + ip = "192.168.1.111" + protocol = "udp" + } + + volumes { + host_path = "/mnt/xwing/config/transmission" + container_path = "/config" + } + + volumes { + host_path = "/mnt/xwing/media/DL" + container_path = "/downloads" + } + + volumes { + host_path = "/mnt/xwing/data/watch/transmission" + container_path = "/watch" + } + + env = [ + "PGID=1003", + "PUID=1000", + "TZ=Asia/Kolkata", + ] + + memory = 512 + + restart = "on-failure" +} + +resource "docker_container" "mariadb" { + name = "mariadb" + image = "${docker_image.mariadb.latest}" + + volumes { + volume_name = "${docker_volume.mariadb_volume.name}" + container_path = "/var/lib/mysql" + host_path = "${docker_volume.mariadb_volume.mountpoint}" + } + + ports { + internal = 3306 + external = 3306 + ip = "192.168.1.111" + } + + memory = 512 + + restart = "on-failure" + + env = [ + "MYSQL_ROOT_PASSWORD=${var.mysql_root_password}", + ] +} + +resource "docker_container" "emby" { + name = "emby" + image = "${docker_image.emby.latest}" + + volumes { + host_path = "/mnt/xwing/config/emby" + container_path = "/config" + } + + volumes { + host_path = "/mnt/xwing/media" + container_path = "/media" + } + + ports { + internal = 8096 + external = 8096 + ip = "0.0.0.0" + } + + memory = 512 + + restart = "on-failure" + + # Running as lounge:tatooine + env = [ + "APP_USER=lounge", + "APP_UID=1004", + "APP_GID=1003", + "APP_CONFIG=/mnt/xwing/config", + "TZ=Asia/Kolkata", + ] +} + +resource "docker_container" "flexget" { + name = "flexget" + image = "${docker_image.flexget.latest}" + + volumes { + host_path = "/mnt/xwing/config/flexget" + container_path = "/config" + } + + volumes { + host_path = "/mnt/xwing/media/DL" + container_path = "/downloads" + } + + volumes { + host_path = "/mnt/xwing/media/TV" + container_path = "/tv" + } + + ports { + internal = 5050 + external = 5050 + ip = "0.0.0.0" + } + + memory = 512 + + restart = "on-failure" + + # Running as lounge:tatooine + env = [ + "PUID=1004", + "PGID=1003", + "WEB_PASSWD=${var.web_password}", + "TORRENT_PLUGIN=transmission", + "FLEXGET_LOG_LEVEL=info", + ] +} + +resource "docker_container" "couchpotato" { + name = "couchpotato" + image = "${docker_image.couchpotato.latest}" + + volumes { + host_path = "/mnt/xwing/config/couchpotato" + container_path = "/config" + } + + volumes { + host_path = "/mnt/xwing/media/DL" + container_path = "/downloads" + } + + volumes { + host_path = "/mnt/xwing/media/Movies" + container_path = "/movies" + } + + ports { + internal = 5050 + external = 5051 + ip = "0.0.0.0" + } + + memory = 512 + + restart = "on-failure" + + # Running as lounge:tatooine + env = [ + "PUID=1004", + "PGID=1003", + "TZ=Asia/Kolkata", + ] +} diff --git a/docker/variables.tf b/docker/variables.tf new file mode 100644 index 0000000..d06977f --- /dev/null +++ b/docker/variables.tf @@ -0,0 +1,11 @@ +variable "web_username" { + type = "string" +} + +variable "web_password" { + type = "string" +} + +variable "mysql_root_password" { + type = "string" +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e7ade4a --- /dev/null +++ b/main.tf @@ -0,0 +1,26 @@ +provider "docker" { + host = "tcp://nemo:${var.docker_pass}@docker.in.bb8.fun:80/" +} + +provider "cloudflare" { + email = "bb8@captnemo.in" + token = "${var.cloudflare_key}" +} + +module "cloudflare" { + source = "cloudflare" + domain = "bb8.fun" + proxy = "sydney.captnemo.in" + act_ip = "10.242.36.126" +} + +module "mysql" { + source = "mysql" +} + +module "docker" { + source = "docker" + web_username = "${var.web_username}" + web_password = "${var.web_password}" + mysql_root_password = "${var.mysql_root_password}" +} diff --git a/mysql/main.tf b/mysql/main.tf new file mode 100644 index 0000000..b4caf26 --- /dev/null +++ b/mysql/main.tf @@ -0,0 +1,25 @@ +# This is pending on https://github.com/hashicorp/go-version/pull/34 +# provider "mysql" { +# endpoint = "docker.captnemo.in:3306" +# username = "root" +# password = "" +# } +# Create a Database +# resource "mysql_database" "kodi" { +# name = "kodi" +# lifecycle { +# prevent_destroy = true +# } +# } +# resource "mysql_user" "kodi" { +# user = "kodi" +# host = "127.0.0.1" +# password = "" +# } +# resource "mysql_grant" "kodi" { +# user = "${mysql_user.kodi.user}" +# host = "${mysql_user.kodi.host}" +# database = "kodi" +# privileges = ["SUPER"] +# } + diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..2e2221f --- /dev/null +++ b/variables.tf @@ -0,0 +1,21 @@ +variable "docker_pass" { + type = "string" + description = "Password for docker" +} + +variable "cloudflare_key" { + type = "string" + description = "cloudflare API Key" +} + +variable "web_username" { + type = "string" +} + +variable "web_password" { + type = "string" +} + +variable "mysql_root_password" { + type = "string" +} \ No newline at end of file