diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 00000000..973b7885 --- /dev/null +++ b/terraform/main.tf @@ -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=main/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=main/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 +} diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars new file mode 100644 index 00000000..4c6a5b3e --- /dev/null +++ b/terraform/terraform.tfvars @@ -0,0 +1,38 @@ + +#If you don't specify the values from some variables, this takes the default values described in the variable.tf file. +#The variables region,key_name and amiid are required. + +# Generics +region = + +tags = + +# Networking + +vpc = + +subnet_prefix = + +security_group = + +route_table = + +network_interface = + +# EC2 + +ec2name = + +key_name = + +#We recomend use g4dn.xlarge size. +size = + +#We recomend use [{ volume_size = "100",volume_type = "gp2"}] values. +root_disk = + +#We recomend use "ami-012e9f6aa634f84f8", this ami have ndrivia drivers and gpu. +amiid = + +# To be run after creation +user_data_path = \ No newline at end of file diff --git a/terraform/user_data.tmpl b/terraform/user_data.tmpl new file mode 100644 index 00000000..bd309677 --- /dev/null +++ b/terraform/user_data.tmpl @@ -0,0 +1,31 @@ +#!/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 + diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 00000000..681760d4 --- /dev/null +++ b/terraform/variables.tf @@ -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" +} +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" + default = "user_data.tmpl" +} \ No newline at end of file