Skip to content

Commit 6be0ac2

Browse files
committed
Initial commit of Terraform config to build AMS/livefeed demos on AWS
0 parents  commit 6be0ac2

7 files changed

+278
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.terraform
3+
terraform.tfstate
4+
terraform.tfstate.backup

cloud-init.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
echo "add public keys to authorized_keys"
4+
5+
read -r -d '' public_keys <<'EOF'
6+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1Te88nbLhOWlvjPJ8Ig4ZnNcfBrCb6Q5OaKOEhvaJ/xNm6ZjqcAo4tF0UklTyLAFwAb08E9ibE2lyu7BEq307q8v7yyu6n/L8riJraEVltLre+ZWBRCCZkts/EhnFjiRxSJ+3rZXLxAGCDStHC6X1dlZu9d50KH/GDBXEBYMCsMUdWd57DFLHZALg0CpSlkNCijzdD1mxjRu9bh7HfXYE9421UzswfPyuPC5bUM1uctYhD4muDq4PHmw2VpCSHVRuSmDUeTVPpg/PI4YJ7zBxIdu32hB2CaG6VMRWDUX7dDR1tjtK3jDuC8OOhAB9Fl6nv7Grp9GPQzKfP5SsAIxv jgrevich
7+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDDpJR60jRCwIWLylRj1NPweE9r6KB4W6Nvh2VSgpt64mJrNNBITpaN7EJt6TTHVJzVfGjdZdrc34mJEH9Jh8xzFH51IlIjcPoq4FgtU2D1fyWL8KL+TpmXefcHeQYGkJv5qBf1Glg8laEjgCZ+7j//Jqm9Brg2tKULkDVxy8S/kD7dfh4VWFa7mKfgAZfnEwSW0FYHB9bhTDUJQGR6sHcN057ACFxO1JZbB6be/OssgKrzhJGaVyFJuKUwKUqaeTzJkuRqO/SgCvQnzx+I6eKofjCgi9HI4OhsNjlURJOW93t2aHt7j6g5H1UZeeyMVt6RmsLg/+Jtws/aM2K9bJLMYB1BB0B5rl1Q5FZ5FNsC5CdbwcBxSnTWkjfw9YGjlrCtQy70sNJ+evxjfVAcKnDVlzqGU1z6eZiiNgFubrLAsPip0HRbqTUCDtiwoTvciy+Ik/ywQlsa0Z0rmnrVhK4c8/GLXJUtU6s5oJ3iBZcUY6jTMC18JdL+eQbcOE1AQXxp25D52mF89syXufh1ZoZWYLTx3Q27/ZQv1tXFFi5sGDEGPHKFkW55PBREu8go9LlX4+9UXAdGkXFnvW41Hao8in6BuHDnERPF3k9rHd/uF5KECBujZp9OAdGDg+nD5XZ6lGNNg7f1+4ihBAGweoS7pDoZFgRvXLPXcw36Ly+rEQ== [email protected]
8+
EOF
9+
10+
echo $public_keys >> /home/ubuntu/.ssh/authorized_keys
11+
12+
echo "install docker"
13+
export DEBIAN_FRONTEND=noninteractive
14+
sudo snap install -y docker
15+
sudo apt update
16+
sudo apt install -y docker.io
17+
18+
echo "start and enable docker on restart"
19+
sudo systemctl start docker
20+
sudo systemctl enable docker
21+
22+
echo "add ubuntu user to docker group so docker can be used without sudo"
23+
sudo usermod -aG docker ubuntu
24+
25+
echo "create a new shell with the ubuntu user and updated group"
26+
sudo su - ubuntu
27+
28+
echo "clone dockerized AMS"
29+
git clone https://github.com/veriskope/docker-adobe-media-server.git
30+
31+
echo "build AMS container"
32+
cd docker-adobe-media-server
33+
docker build --tag=ams .
34+
echo "start container and map ports"
35+
docker run -p 80:80 -p 443:443 -p 1111:1111 -p 1935:1935 --name ams -d ams
36+
37+
echo "docker install and setup is done"

ec2.tf

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# https://cloud-images.ubuntu.com/locator/ec2/
2+
# ubuntu 18.04 lts hvm:instance-store ami-04aa802b835dec952
3+
# ubuntu 18.04 lts hvm:ebs-ssd ami-06d51e91cea0dac8d
4+
5+
resource "aws_instance" "ams_5015" {
6+
ami = "ami-06d51e91cea0dac8d"
7+
instance_type = "t2.micro"
8+
key_name = "${aws_key_pair.default.key_name}"
9+
subnet_id = "${aws_subnet.ams_a.id}"
10+
user_data = "${file("cloud-init.sh")}"
11+
vpc_security_group_ids = ["${aws_security_group.ams.id}"]
12+
}
13+
14+
resource "aws_eip" "ams_5015" {
15+
instance = "${aws_instance.ams_5015.id}"
16+
}
17+
18+
output "ams_5015_public_dns" {
19+
value = "${aws_eip.ams_5015.public_dns}"
20+
}
21+
22+
output "ams_5015_public_ip" {
23+
value = "${aws_eip.ams_5015.public_ip}"
24+
}
25+
26+
resource "aws_instance" "ams_demo" {
27+
ami = "ami-06d51e91cea0dac8d"
28+
instance_type = "t2.micro"
29+
key_name = "${aws_key_pair.default.key_name}"
30+
subnet_id = "${aws_subnet.ams_a.id}"
31+
user_data = "${file("cloud-init.sh")}"
32+
vpc_security_group_ids = ["${aws_security_group.ams.id}"]
33+
}
34+
35+
resource "aws_eip" "ams_demo" {
36+
instance = "${aws_instance.ams_demo.id}"
37+
}
38+
39+
output "ams_demo_public_dns" {
40+
value = "${aws_eip.ams_demo.public_dns}"
41+
}
42+
43+
output "ams_demo_public_ip" {
44+
value = "${aws_eip.ams_demo.public_ip}"
45+
}
46+
47+
resource "aws_instance" "livefeed_demo" {
48+
ami = "ami-06d51e91cea0dac8d"
49+
instance_type = "t2.micro"
50+
key_name = "${aws_key_pair.default.key_name}"
51+
subnet_id = "${aws_subnet.ams_a.id}"
52+
user_data = "${file("livefeed-cloud-init.sh")}"
53+
vpc_security_group_ids = ["${aws_security_group.ams.id}"]
54+
}
55+
56+
resource "aws_eip" "livefeed_demo" {
57+
instance = "${aws_instance.livefeed_demo.id}"
58+
}
59+
60+
output "livefeed_demo_public_dns" {
61+
value = "${aws_eip.livefeed_demo.public_dns}"
62+
}
63+
64+
output "livefeed_demo_public_ip" {
65+
value = "${aws_eip.livefeed_demo.public_ip}"
66+
}
67+
68+
resource "aws_key_pair" "default" {
69+
key_name = "default ssh key"
70+
public_key = "${var.ssh_public_key}"
71+
}

livefeed-cloud-init.sh

+37
Original file line numberDiff line numberDiff line change
@@ -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DEGPHKFkW55PBREu8go9LlX4+9UXAdGkXFnvW41Hao8in6BuHDnERPF3k9rHd/uF5KECBujZp9OAdGDg+nD5XZ6lGNNg7f1+4ihBAGweoS7pDoZFgRvXLPXcw36Ly+rEQ== [email protected]
8+
EOF
9+
10+
echo $public_keys >> /home/ubuntu/.ssh/authorized_keys
11+
12+
echo "install docker"
13+
export DEBIAN_FRONTEND=noninteractive
14+
sudo snap install -y docker
15+
sudo apt update
16+
sudo apt install -y docker.io
17+
18+
echo "start and enable docker on restart"
19+
sudo systemctl start docker
20+
sudo systemctl enable docker
21+
22+
echo "add ubuntu user to docker group so docker can be used without sudo"
23+
sudo usermod -aG docker ubuntu
24+
25+
echo "create a new shell with the ubuntu user and updated group"
26+
sudo su - ubuntu
27+
28+
echo "clone livefeed demo"
29+
git clone https://github.com/veriskope/docker-adobe-media-server.git
30+
31+
echo "build livefeed container"
32+
# cd docker-adobe-media-server
33+
# docker build --tag=ams .
34+
echo "start container and map ports"
35+
# docker run -p 80:80 -p 443:443 -p 1111:1111 -p 1935:1935 --name ams -d ams
36+
37+
echo "docker install and setup is done"

main.tf

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Configure the AWS Providers
2+
provider "aws" {
3+
version = "~> 2.0"
4+
region = "us-west-2"
5+
alias = "usw2"
6+
}
7+
8+
provider "aws" {
9+
version = "~> 2.0"
10+
region = "eu-west-2"
11+
alias = "euw2"
12+
}
13+
14+
# Bucket initially created using AWS CLI
15+
#
16+
# aws s3api create-bucket --bucket ams-terraform-backend-store \
17+
# --region us-west-2 \
18+
# --create-bucket-configuration \
19+
# LocationConstraint=us-west-2
20+
#
21+
# aws s3api put-bucket-encryption \
22+
# --bucket ams-terraform-backend-store \
23+
# --server-side-encryption-configuration={\"Rules\":[{\"ApplyServerSideEncryptionByDefault\":{\"SSEAlgorithm\":\"AES256\"}}]}
24+
#
25+
26+
data "terraform_remote_state" "s3" {
27+
backend = "s3"
28+
config = {
29+
bucket = "ams-terraform-backend-store"
30+
encrypt = true
31+
key = "terraform/terraform.tfstate"
32+
region = "us-west-2"
33+
}
34+
}

variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "ssh_public_key" {
2+
description = "SSH key used to login to server until we have a proper base image that includes the necessary keys"
3+
default = ""
4+
}

vpc.tf

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
resource "aws_internet_gateway" "default" {
2+
vpc_id = "${aws_vpc.default.id}"
3+
}
4+
5+
resource "aws_route" "default" {
6+
route_table_id = "${aws_vpc.default.main_route_table_id}"
7+
destination_cidr_block = "0.0.0.0/0"
8+
gateway_id = "${aws_internet_gateway.default.id}"
9+
}
10+
11+
resource "aws_security_group" "ams" {
12+
name = "ams"
13+
description = "Base security group for AMS instances"
14+
vpc_id = "${aws_vpc.default.id}"
15+
16+
egress {
17+
description = "allow egress to anywhere"
18+
from_port = 0
19+
to_port = 0
20+
protocol = "-1"
21+
cidr_blocks = ["0.0.0.0/0"]
22+
}
23+
24+
# allow SSH in from anywhere
25+
ingress {
26+
description = "allow SSH in from anywhere"
27+
protocol = "tcp"
28+
from_port = 22
29+
to_port = 22
30+
cidr_blocks = ["0.0.0.0/0"]
31+
}
32+
33+
ingress {
34+
description = "allow HTTP in from anywhere"
35+
protocol = "tcp"
36+
from_port = 80
37+
to_port = 80
38+
cidr_blocks = ["0.0.0.0/0"]
39+
}
40+
41+
ingress {
42+
description = "allow HTTPS in from anywhere"
43+
protocol = "tcp"
44+
from_port = 443
45+
to_port = 443
46+
cidr_blocks = ["0.0.0.0/0"]
47+
}
48+
49+
ingress {
50+
description = "allow AMS Admin RTMP in from anywhere"
51+
protocol = "tcp"
52+
from_port = 1111
53+
to_port = 1111
54+
cidr_blocks = ["0.0.0.0/0"]
55+
}
56+
57+
ingress {
58+
description = "allow RTMP streams in from anywhere"
59+
protocol = "tcp"
60+
from_port = 1935
61+
to_port = 1935
62+
cidr_blocks = ["0.0.0.0/0"]
63+
}
64+
65+
# allow ICMP within VPC
66+
ingress {
67+
protocol = "icmp"
68+
from_port = -1
69+
to_port = -1
70+
cidr_blocks = ["${aws_vpc.default.cidr_block}"]
71+
}
72+
73+
egress {
74+
protocol = "icmp"
75+
from_port = -1
76+
to_port = -1
77+
cidr_blocks = ["${aws_vpc.default.cidr_block}"]
78+
}
79+
}
80+
81+
resource "aws_subnet" "ams_a" {
82+
vpc_id = "${aws_vpc.default.id}"
83+
cidr_block = "192.168.0.0/24"
84+
availability_zone = "us-west-2a"
85+
}
86+
87+
resource "aws_vpc" "default" {
88+
cidr_block = "192.168.0.0/16"
89+
enable_dns_support = true
90+
enable_dns_hostnames = true
91+
}

0 commit comments

Comments
 (0)