Skip to content

Commit

Permalink
Adding FTL module (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
clone1018 authored Apr 17, 2021
1 parent f06e0b0 commit af16905
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 197 deletions.
61 changes: 31 additions & 30 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions terraform/ftl-orchestrator.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Orchestrator
resource "digitalocean_droplet" "ftl_orchestrator" {
image = "ubuntu-20-04-x64"
name = var.ftl_orchestrator_hostname
region = "nyc3"
size = "c-4"
private_networking = true
tags = [digitalocean_tag.ftl.id]

ssh_keys = var.digitalocean_live_ssh_keys

connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.digitalocean_priv_key_path)
timeout = "2m"
}
}
resource "uptimerobot_monitor" "ftl_orchestrator_monitor" {
friendly_name = var.ftl_orchestrator_hostname
url = digitalocean_droplet.ftl_orchestrator.ipv4_address
type = "port"
sub_type = "custom"
port = "8085"
}

resource "cloudflare_record" "ftl_orchestrator_lb_record" {
zone_id = lookup(data.cloudflare_zones.glimesh_domain_zones.zones[0], "id")
type = "A"
name = var.ftl_orchestrator_hostname
value = digitalocean_droplet.ftl_orchestrator.ipv4_address
proxied = false
}

137 changes: 137 additions & 0 deletions terraform/ftl-region/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@

terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "2.18.0"
}
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.5.1"
}
uptimerobot = {
source = "louy/uptimerobot"
version = "0.5.1"
}
}
}

data "cloudflare_zones" "glimesh_domain_zones" {
filter {
name = var.cloudflare_domain
status = "active"
}
}

resource "digitalocean_tag" "ftl" {
name = "ftl"
}

resource "digitalocean_tag" "ftl_edge" {
name = "ftl-edge"
}

resource "digitalocean_tag" "ftl_ingest" {
name = "ftl-ingest"
}


# Ingest
resource "digitalocean_droplet" "ftl_ingest" {
count = var.ingest_count
image = "ubuntu-20-04-x64"
name = format("do-%s-ingest%d.%s.live.glimesh.tv", var.do_region, count.index + 1, var.region)
region = var.do_region
size = var.ingest_size
private_networking = true
tags = [digitalocean_tag.ftl.id, digitalocean_tag.ftl_ingest.id]

ssh_keys = var.ssh_keys

connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.digitalocean_priv_key_path)
timeout = "2m"
}
}

resource "uptimerobot_monitor" "ftl_ingest_monitor" {
count = var.ingest_count
friendly_name = element(digitalocean_droplet.ftl_ingest.*.name, count.index)
url = element(digitalocean_droplet.ftl_ingest.*.ipv4_address, count.index)
type = "port"
sub_type = "custom"
port = "8084"
}

resource "cloudflare_record" "ftl_ingest_record" {
count = var.ingest_count
zone_id = lookup(data.cloudflare_zones.glimesh_domain_zones.zones[0], "id")
type = "A"
name = element(digitalocean_droplet.ftl_ingest.*.name, count.index)
value = element(digitalocean_droplet.ftl_ingest.*.ipv4_address, count.index)
proxied = false
}

resource "cloudflare_record" "ftl_ingest_lb_record" {
count = var.ingest_count
zone_id = lookup(data.cloudflare_zones.glimesh_domain_zones.zones[0], "id")
type = "A"
name = "ingest.${var.region}.live.glimesh.tv"
value = element(digitalocean_droplet.ftl_ingest.*.ipv4_address, count.index)
proxied = false
}


# Edge
resource "digitalocean_droplet" "ftl_edge" {
count = var.edge_count
image = "ubuntu-20-04-x64"
name = format("do-%s-edge%d.%s.live.glimesh.tv", var.do_region, count.index + 1, var.region)
region = var.do_region
size = var.edge_size
private_networking = true
tags = [digitalocean_tag.ftl.id, digitalocean_tag.ftl_edge.id]

ssh_keys = var.ssh_keys

connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.digitalocean_priv_key_path)
timeout = "2m"
}
}

resource "uptimerobot_monitor" "ftl_edge_monitor" {
count = var.edge_count
friendly_name = element(digitalocean_droplet.ftl_edge.*.name, count.index)
url = element(digitalocean_droplet.ftl_edge.*.ipv4_address, count.index)
type = "port"
sub_type = "custom"
port = "8084"
}

resource "cloudflare_record" "ftl_edge_record" {
count = var.edge_count
zone_id = lookup(data.cloudflare_zones.glimesh_domain_zones.zones[0], "id")
type = "A"
name = element(digitalocean_droplet.ftl_edge.*.name, count.index)
value = element(digitalocean_droplet.ftl_edge.*.ipv4_address, count.index)
proxied = false
}

resource "cloudflare_record" "ftl_edge_lb_record" {
count = var.edge_count
zone_id = lookup(data.cloudflare_zones.glimesh_domain_zones.zones[0], "id")
type = "A"
name = "edge.${var.region}.live.glimesh.tv"
value = element(digitalocean_droplet.ftl_edge.*.ipv4_address, count.index)
proxied = false
}



25 changes: 25 additions & 0 deletions terraform/ftl-region/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "region" {}
variable "do_region" {}

variable "cloudflare_domain" {
type = string
}

variable "ingest_size" {
type = string
}
variable "ingest_count" {
type = number
}

variable "edge_size" {
type = string
}
variable "edge_count" {
type = number
}

variable "ssh_keys" {
type = list(string)
}

Loading

0 comments on commit af16905

Please sign in to comment.