Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
36 changes: 36 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
}

provider "aws" {
region = var.region
}

module "module-network-linux-web" {
source = "github.com/xmartlabs/terraform.git?ref=module-network-linux-web/modules/module-network-linux-web"
region = var.region
tags = var.tags
vpc = var.vpc
subnet_prefix = var.subnet_prefix
security_group = var.security_group
route_table = var.route_table
network_interface = var.network_interface
}

module "module-ec2-linux-web"{
source = "github.com/xmartlabs/terraform.git?ref=module-network-linux-web/modules/module-ec2-linux-web"
region = var.region
amiid = var.amiid
tags= var.tags
id_network_interface= module.module-network-linux-web.network_interface_id
user_data_path= "user_data.tmpl"
key_name= var.key_name
ec2name = var.ec2name
size = var.size
root_disk = var.root_disk
}
31 changes: 31 additions & 0 deletions terraform/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generics
region = "us-east-1"

tags = [{ Project = "lanthorn",State = "Deploy EC2 with nvidia drivers and docker installed"}]


# Networking
vpc = [{ name = "lanthorn_vpc", cidr_block = "10.0.0.0/16" , instance_tenancy = "default", enable_dns_hostnames = true, enable_dns_support = true}]

subnet_prefix = [{ name = "langthron_module_subnet", cidr_block = "10.0.1.0/24", availability_zone = "us-east-1a", map_public_ip_on_launch = true }]

security_group = [{ name = "langthron_module_security_group" }]

route_table = [{ name = "langthron_module_route_table", cidr_block = "0.0.0.0/0", ipv6_cidr_block = "::/0" }]

network_interface = [{ name = "langthron_module_network_interface", private_ips = ["10.0.1.50"], device_index = 0 }]


# EC2
ec2name = "langthron-smart-social-distancing"

key_name = "lanthornkey"

size = "g4dn.xlarge"

root_disk = [{ volume_size = "100",volume_type = "gp2"}]

amiid = "ami-012e9f6aa634f84f8"

# To be run after creation
user_data_path = "user_data.tmpl"
34 changes: 34 additions & 0 deletions terraform/user_data.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start

#docker-ec2user

sudo groupadd docker
sudo gpasswd -a ec2-user docker
sudo usermod -aG docker ec2-user


sudo yum install nvidia* -y

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo

sudo yum clean expire-cache

sudo systemctl restart docker

sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

#Api
sudo yum install git -y
git clone https://github.com/neuralet/smart-social-distancing.git
cd smart-social-distancing
git fetch --tags
git checkout $(git tag | tail -1)
./download-x86-openpifpaf-model.sh

#docker run -d -it --gpus all --restart unless-stopped --name smart-social-distancing -p 443:8000 -v $PWD/data:/repo/data -v $PWD/certs:/repo/certs -v $PWD/config-x86-gpu-tensorrt.ini:/repo/config-x86-gpu-tensorrt.ini -e TZ=`./timezone.sh` neuralet/smart-social-distancing:latest-x86_64_gpu_tensorrt

#-v $PWD/certs:/repo/certs
61 changes: 61 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generics
variable "region" {
description = "required - region"
}

variable "tags" {
description = "required - default important tags for resources"
default = [{ Project = "not created", State = "not created" }]
}

# Networking
variable "vpc" {
description = "The definition of vpc"
default = [{ name = "terraform_module_vpc", cidr_block = "10.0.0.0/16", instance_tenancy = "default", enable_dns_hostnames = true, enable_dns_support = true }]
}

variable "subnet_prefix" {
description = "The subnet prefix"
default = [{ name = "terraform_module_subnet", cidr_block = "10.0.1.0/24", availability_zone = "us-east-1a", map_public_ip_on_launch = true }]
}

variable "security_group" {
description = "security group definition"
default = [{ name = "terraform_module_security_group" }]
}

variable "route_table" {
description = "route table definition"
default = [{ name = "terraform_module_route_table", cidr_block = "0.0.0.0/0", ipv6_cidr_block = "::/0" }]
}

variable "network_interface" {
description = "network interface definition"
default = [{ name = "terraform_module_network_interface", private_ips = ["10.0.1.50"], device_index = 0 }]
}

# EC2
variable "ec2name" {
description = "name for the EC2 instance"
default = "default-ec2name"
}
variable "key_name" {
description = "key to be used by the EC2"
default = "default-key_name"
}
variable "size" {
description = "instance type for the EC2"
default = "t2-micro"
}
variable "root_disk" {
description = "root disk definition"
default = [{ volume_size = "100", volume_type = "gp2" }]
}
variable "amiid" {
description = "amazon-linux"
}

# To be run after creation
variable "user_data_path" {
description = "User data file path"
}