Initial commit

This commit is contained in:
Nemo 2017-11-04 19:09:32 +05:30
commit d23827c19a
9 changed files with 364 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
env.sh
.terraform
*.tfstate

42
cloudflare/main.tf Normal file
View File

@ -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"
}

11
cloudflare/variables.tf Normal file
View File

@ -0,0 +1,11 @@
variable "domain" {
type = "string"
}
variable "proxy" {
type = "string"
}
variable "act_ip" {
type = "string"
}

19
docker/data.tf Normal file
View File

@ -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"
}

206
docker/main.tf Normal file
View File

@ -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",
]
}

11
docker/variables.tf Normal file
View File

@ -0,0 +1,11 @@
variable "web_username" {
type = "string"
}
variable "web_password" {
type = "string"
}
variable "mysql_root_password" {
type = "string"
}

26
main.tf Normal file
View File

@ -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}"
}

25
mysql/main.tf Normal file
View File

@ -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"]
# }

21
variables.tf Normal file
View File

@ -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"
}