Remove ECS terraform from repo, updated README (#49)

This commit is contained in:
David Zhao
2021-07-12 16:13:41 -07:00
committed by GitHub
parent d38fc43b89
commit 0cf6efdae9
13 changed files with 10 additions and 562 deletions
-2
View File
@@ -1,2 +0,0 @@
.terraform*
terraform.tfstate*
-72
View File
@@ -1,72 +0,0 @@
locals {
livekit_config = {
port = var.http_port
rtc = {
port_range_start = var.udp_port_start
port_range_end = var.udp_port_end
tcp_port = var.rtc_tcp_port
udp_port = var.rtc_udp_port
use_external_ip = true
}
turn = {
enabled = var.turn_enabled
tcp_port = var.turn_tcp_port
udp_port = var.turn_udp_port
port_range_start = var.turn_port_start
port_range_end = var.turn_port_end
}
development = true
keys = var.api_keys
redis = {
address = var.redis_address
}
}
// mapping contains only the main listening ports
// other UDP ports don't have to be mapped, due to using host-mode
port_mapping = [
{
containerPort = var.http_port
protocol = "tcp"
},
{
containerPort = var.turn_tcp_port
protocol = "tcp"
},
{
containerPort = var.turn_udp_port
protocol = "udp"
},
{
containerPort = var.rtc_udp_port
protocol = "udp"
},
{
containerPort = var.rtc_tcp_port
protocol = "tcp"
}
]
task_config = [{
name = "livekit"
image = "livekit/livekit-server:${var.livekit_version}"
cpu = 1024
memory = 1024
essential = true
environment = [
{
name = "LIVEKIT_CONFIG"
value = yamlencode(local.livekit_config)
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
"awslogs-region" = var.region
"awslogs-group" = "livekit"
"awslogs-stream-prefix" = var.name
}
},
portMappings = local.port_mapping
}]
}
-26
View File
@@ -1,26 +0,0 @@
data "aws_ami" "ecs_ami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-*-amazon-ecs-optimized"]
}
}
module "app_ecs_cluster" {
source = "trussworks/ecs-cluster/aws"
name = "livekit"
environment = var.name
image_id = data.aws_ami.ecs_ami.image_id
instance_type = var.instance_type
vpc_id = var.vpc_id
subnet_ids = var.subnet_ids
security_group_ids = concat(var.security_groups, [aws_security_group.main.id])
desired_capacity = var.nodes
max_size = var.max_nodes
min_size = var.min_nodes
}
-46
View File
@@ -1,46 +0,0 @@
resource "aws_ecs_task_definition" "livekit" {
family = "service"
container_definitions = jsonencode(local.task_config)
network_mode = "host"
execution_role_arn = aws_iam_role.ecs_role.arn
}
resource "aws_ecs_service" "livekit" {
name = "livekit-${var.name}"
cluster = module.app_ecs_cluster.ecs_cluster_arn
task_definition = aws_ecs_task_definition.livekit.arn
desired_count = var.nodes
force_new_deployment = true
launch_type = "EC2"
placement_constraints {
// one instance per node
type = "distinctInstance"
}
ordered_placement_strategy {
type = "spread"
field = "instanceId"
}
// load balancer for HTTP port
load_balancer {
target_group_arn = aws_lb_target_group.http.arn
container_name = "livekit"
container_port = var.http_port
}
depends_on = [
aws_lb_listener.http
]
// lifecycle {
// ignore_changes = [desired_count]
// }
}
resource "aws_cloudwatch_log_group" "livekit" {
name = "livekit"
retention_in_days = 7
}
-53
View File
@@ -1,53 +0,0 @@
# name of the livekit cluster, resources will be called `livekit-${name}`
name = "demo"
# type of instance to use
instance_type = "t3.small"
# limits to the number of nodes to run
max_nodes = 2
# minimum number of nodes to run
min_nodes = 1
# initially use this number of nodes
nodes = 1
# VPC to create the cluster in
vpc_id = ""
# List of subnet IDs to create the cluster in
subnet_ids = []
# region to use, must match AWS_REGION environment variable
region = "us-east-1"
# additional security groups to attach the cluster to.
# include security group of the redis instance to allow access
security_groups = [
""
]
# Livekit configuration
# address and port to redis instance
redis_address = ""
# list of API keys and secrets
api_keys = {
"key" = "secret"
}
# UDP port range for WebRTC, uncomment to override
// udp_port_start = 9000
// udp_port_end = 11000
# Use embedded TURN server, defaults true
// turn_enabled = true
// turn_tcp_port = 3478
// turn_udp_port = 3479
# UDP port range for embedded TURN server
// turn_port_start = 11001
// turn_port_end = 13000
-26
View File
@@ -1,26 +0,0 @@
// role for ECS execution
resource "aws_iam_role" "ecs_role" {
name = "livekit-${var.name}-execution"
assume_role_policy = <<ROLE_POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
ROLE_POLICY
}
resource "aws_iam_role_policy_attachment" "ecs_role-attach" {
role = aws_iam_role.ecs_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
-29
View File
@@ -1,29 +0,0 @@
// configure target group
resource "aws_lb_target_group" "http" {
name = "livekit-${var.name}-http"
port = 80
protocol = "HTTP"
vpc_id = data.aws_vpc.main.id
}
resource "aws_lb" "main" {
name = "livekit-${var.name}-http"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb.id]
subnets = var.subnet_ids
}
resource "aws_lb_listener" "http" {
load_balancer_arn = aws_lb.main.arn
port = "80"
protocol = "HTTP"
// ssl_policy = "ELBSecurityPolicy-2016-08"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.http.arn
}
}
-131
View File
@@ -1,131 +0,0 @@
#
# The following variables need to be set:
# AWS_ACCESS_KEY_ID (or reads from ~/.aws/credentials)
# AWS_SECRET_ACCESS_KEY (or reads from ~/.aws/credentials)
# AWS_REGION
#
provider "aws" {
}
# name of the cluster
variable "name" {
type = string
}
# type of instance to deploy on
variable "instance_type" {
type = string
default = "t3.small"
}
variable "nodes" {
type = number
default = 1
}
variable "min_nodes" {
type = number
default = 1
}
variable "max_nodes" {
type = number
}
variable "region" {
type = string
}
# target CPU utilization
variable "target_cluster_utilization" {
type = number
default = 90
}
# VPC to launch the cluster in
variable "vpc_id" {
type = string
}
# launch in the following subnet ids
variable "subnet_ids" {
type = list(string)
}
# additional security groups to associate with
# i.e. security group of the Redis instance
variable "security_groups" {
type = list(string)
default = []
}
# livekit config
variable "livekit_version" {
type = string
default = "latest"
}
variable "http_port" {
type = number
default = 7880
}
// not set by default, prefers rtc_udp_port
variable "udp_port_start" {
type = number
default = 0
}
// not set by default, prefers rtc_udp_port
variable "udp_port_end" {
type = number
default = 0
}
variable "rtc_tcp_port" {
type = number
default = 7881
}
variable "rtc_udp_port" {
type = number
default = 9000
}
variable "api_keys" {
type = map(string)
}
variable "redis_address" {
type = string
default = ""
}
variable "turn_enabled" {
type = bool
default = false
}
variable "turn_tcp_port" {
type = number
default = 3478
}
variable "turn_udp_port" {
type = number
default = 3479
}
variable "turn_port_start" {
type = number
default = 12000
}
variable "turn_port_end" {
type = number
default = 14000
}
output "livekit_lb" {
value = aws_lb.main.dns_name
}
-111
View File
@@ -1,111 +0,0 @@
data "aws_vpc" "main" {
id = var.vpc_id
}
resource "aws_security_group" "main" {
name = "livekit-${var.name}"
description = "Allow LiveKit inbound TCP and UDP traffic"
vpc_id = data.aws_vpc.main.id
ingress {
description = "UDP port range for ICE"
from_port = var.udp_port_start
to_port = var.udp_port_end
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "UDP port for ICE"
from_port = var.rtc_udp_port
to_port = var.rtc_udp_port
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "TCP port for ICE"
from_port = var.rtc_tcp_port
to_port = var.rtc_tcp_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "UDP port for TURN"
from_port = var.turn_port_start
to_port = var.turn_port_end
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
// for TURN server
ingress {
description = "TURN TCP"
from_port = var.turn_tcp_port
to_port = var.turn_tcp_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
// for TURN server
ingress {
description = "TURN UDP"
from_port = var.turn_udp_port
to_port = var.turn_udp_port
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "internal traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [data.aws_vpc.main.cidr_block]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "livekit"
}
}
resource "aws_security_group" "lb" {
name = "livekit-${var.name}-lb"
description = "Load balancer traffic"
vpc_id = data.aws_vpc.main.id
ingress {
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "livekit"
}
}
-7
View File
@@ -1,7 +0,0 @@
# Redis Terraform
Creates a Redis elasticache cluster. Run it like the following
`AWS_REGION=<region> terraform apply`
Enter a name for the cluster, as well as the subnet ids that Redis should be created in
-33
View File
@@ -1,33 +0,0 @@
#
# The following variables need to be set:
# AWS_ACCESS_KEY_ID (or reads from ~/.aws/credentials)
# AWS_SECRET_ACCESS_KEY (or reads from ~/.aws/credentials)
# AWS_REGION
#
provider "aws" {
}
# type of instance to deploy on
# see: https://aws.amazon.com/elasticache/pricing/
variable "instance_type" {
type = string
default = "cache.t3.micro"
}
# name of the cluster
variable "cluster_id" {
type = string
}
# launch in the following subnet ids
variable "subnet_ids" {
type = list(string)
}
variable "security_groups" {
type = list(string)
}
output "address" {
value = "${aws_elasticache_cluster.main.cache_nodes[0].address}:${aws_elasticache_cluster.main.cache_nodes[0].port}"
}
-18
View File
@@ -1,18 +0,0 @@
resource "aws_elasticache_cluster" "main" {
cluster_id = var.cluster_id
engine = "redis"
node_type = var.instance_type
num_cache_nodes = 1
parameter_group_name = "default.redis6.x"
# strangely terraform requires you to change to a specific version when
# modifying the resource.
engine_version = "6.x"
subnet_group_name = aws_elasticache_subnet_group.main.name
security_group_ids = var.security_groups
port = 6379
}
resource "aws_elasticache_subnet_group" "main" {
name = var.cluster_id
subnet_ids = var.subnet_ids
}