Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@
ehthumbs.db
Thumbs.db
/.project
ssh
./ssh
**/ssh/
**/*.tfstate
**/*.tfstate.backup
**/.terraform/
**/.terraform.lock.hcl
**/*.tfvars
**/*.tfvars.json
**/terraform.*
**/.terraform.*

89 changes: 89 additions & 0 deletions terraform/GCP/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
resource "google_compute_instance" "ams-marketplace" {

name = "ams-marketplace-${var.ams_version}"
machine_type = var.machine_type
zone = var.zone
tags = ["allow-all"]
boot_disk {
initialize_params {
image = var.image
}
}
network_interface {
network = "default"
access_config {

}
}

metadata = {
ssh-keys = "${var.user}:${file(var.publickeypath)}"
}
}

resource "google_compute_firewall" "ams-allow_port_5080" {
name = "ams-allow-port-5080"
network = "default"

allow {
protocol = "tcp"
ports = ["5080"]
}

source_ranges = ["0.0.0.0/0"]
}

resource "null_resource" "ams-marketplace-setup" {
provisioner "remote-exec" {
connection {
type = "ssh"
user = var.user
host = google_compute_instance.ams-marketplace.network_interface[0].access_config[0].nat_ip
private_key = file(var.privatekeypath)
}
inline = [
"sudo sed -i 's/#\\$nrconf{kernelhints} = -1;/\\$nrconf{kernelhints} = -1;/g' /etc/needrestart/needrestart.conf",
"echo 'NEEDRESTART_SUSPEND=1' >> /etc/environment",
"sudo source /etc/environment",
"sudo apt-get update",
"sudo apt-get dist-upgrade -y",
"wget https://raw.githubusercontent.com/ant-media/Scripts/master/install_ant-media-server.sh",
"curl -L 'https://drive.usercontent.google.com/download?id=${var.zip_file_id}&export=download&confirm=t' -o 'ams.zip'",
"sudo bash ./install_ant-media-server.sh -i ams.zip",
"sudo sed -i 's/server.marketplace=.*/server.marketplace=gcp/g' /usr/local/antmedia/conf/red5.properties",
"sudo systemctl stop antmedia",
"sudo rm -rf /usr/local/antmedia/conf/instanceId",
"sudo rm -rf /usr/local/antmedia/*.db.* && sudo rm -rf /usr/local/antmedia/*.db",
"sudo rm -rf /root/*.zip && sudo rm -rf /root/install*",
"sudo rm -rf /root/.ssh",
]
}
}

resource "null_resource" "stop_instance" {
provisioner "local-exec" {
command = "gcloud compute instances stop ams-marketplace-${var.ams_version} --project=${var.project} --zone=${var.zone}"
}
depends_on = [null_resource.ams-marketplace-setup]
}


resource "google_compute_image" "ams_marketplace_image" {
name = "ams-marketplace-${var.ams_version}"
source_disk = "projects/antmedia-dev/zones/${var.zone}/disks/ams-marketplace-${var.ams_version}"
licenses = ["projects/${var.public_project}/global/licenses/cloud-marketplace-211adc9aa41170ec-df1ebeb69c0ba664"]
description = "AMS-ams-marketplace-${var.ams_version}"
project = "${var.public_project}"
depends_on = [null_resource.stop_instance]
}


resource "google_compute_image_iam_binding" "iam" {
image = "projects/${var.public_project}/global/images/ams-marketplace-${var.ams_version}"
role = "roles/compute.imageUser"

members = [
"allAuthenticatedUsers"
]
depends_on = [google_compute_image.ams_marketplace_image]
}
6 changes: 6 additions & 0 deletions terraform/GCP/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "google" {
# credentials = file("antmedia-dev.json")
project = var.project
region = var.region
zone = var.zone
}
63 changes: 63 additions & 0 deletions terraform/GCP/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
variable "project" {
type = string
description = "The project ID to deploy to"
default = "antmedia-dev"
}

variable "public_project" {
type = string
description = "The project ID to deploy to"
default = "antmedia-public-385620"
}


variable "region" {
type = string
description = "The region to deploy to"
default = "us-central1"

}

variable "zone" {
type = string
description = "The zone to deploy to"
default = "us-central1-a"
}

variable "machine_type" {
type = string
description = "The machine type to deploy to"
default = "e2-medium"
}

variable "image" {
type = string
description = "The image to deploy to"
default = "ubuntu-os-cloud/ubuntu-2404-lts-amd64"
}

variable "ams_version" {
type = string
description = "Version number of AMS"
}

variable "publickeypath" {
type = string
default = "./ssh/id_rsa.pub"
}

variable "privatekeypath" {
type = string
default = "./ssh/id_rsa"
}

variable "user" {
type = string
default = "root"

}

variable "zip_file_id" {
description = "Google drive ID"
type = string
}
62 changes: 62 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# GCP

1. Log in first
```
gcloud auth application-default login
```
2. Create a file called terraform.tfvars and add the following variables
```
zip_file_id = ""
ams_version = ""

```
3. Generate a new SSH key
```
mkdir ./ssh
ssh-keygen -t rsa -f ./ssh/id_rsa
```

# Azure

1. Log in first
```
az login
```
2. Set subscription id in provider.tf

3. Create a file called terraform.tfvars and add the following variables
```
zip_file_id = ""
ams_version = ""
```
4. Generate a new SSH key
```
mkdir ./ssh
ssh-keygen -t rsa -f ./ssh/id_rsa
```

# DO

1. First create a DO token

2. Create a file called terraform.tfvars and add the following variables

```
zip_file_id = ""
do_token = ""
ams_version = ""
```
3. Generate a new SSH key
```
mkdir ./ssh
ssh-keygen -t rsa -f ./ssh/id_rsa
```

## Make sure everything works properly
```
terraform plan
```
## Install the deployments
```
terraform apply -auto-approve
```
18 changes: 18 additions & 0 deletions terraform/aws/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}

# Create a VPC
resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
Loading
Loading