-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this is a module for being used when we are using AWS accounts that a…
…re under EC2-classic way and don't use a VPC by default added a readme explanation of why this module exist and its purpose
- Loading branch information
Showing
15 changed files
with
317 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
data "aws_ami" "ubuntu" { | ||
most_recent = true | ||
filter { | ||
name = "name" | ||
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170721"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
resource "aws_instance" "nginx_node" { | ||
ami = "${data.aws_ami.ubuntu.id}" | ||
instance_type = "${var.instance_type}" | ||
associate_public_ip_address = true | ||
subnet_id = "${aws_subnet.us-east-1a-public.id}" | ||
|
||
key_name = "${aws_key_pair.deployer-key.key_name}" | ||
security_groups = ["${aws_security_group.node_nginx.id}"] // node-nginx | ||
|
||
tags { | ||
Name = "${var.project_name} [demo]" | ||
Description = "Created with aws-provisioner for ${var.project_name}" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"mkdir -p ~/provision" | ||
] | ||
} | ||
|
||
provisioner "file" { | ||
source = "${path.module}/provision/" | ||
destination = "/home/ubuntu/provision/" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"chmod +x /home/ubuntu/provision/*", | ||
"/home/ubuntu/provision/install_ubuntu_build_essential.sh", | ||
"/home/ubuntu/provision/install_nvm.sh", | ||
"/home/ubuntu/provision/install_dummy_app.sh", | ||
"/home/ubuntu/provision/install_nginx.sh", | ||
] | ||
} | ||
|
||
connection { | ||
user = "ubuntu" | ||
type = "ssh" | ||
private_key = "${file("${var.private_key_path}")}" | ||
} | ||
} | ||
|
||
resource "aws_vpc" "selected" { | ||
cidr_block = "10.0.0.0/16" | ||
enable_dns_hostnames = true | ||
enable_dns_support = true | ||
tags { | ||
Name = "${var.project_name}" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "us-east-1a-public" { | ||
vpc_id = "${aws_vpc.selected.id}" | ||
cidr_block = "10.0.1.0/25" | ||
availability_zone = "us-east-1a" | ||
} | ||
|
||
resource "aws_internet_gateway" "main" { | ||
vpc_id = "${aws_vpc.selected.id}" | ||
tags { | ||
Name = "${var.project_name}" | ||
} | ||
} | ||
|
||
resource "aws_default_route_table" "r" { | ||
default_route_table_id = "${aws_vpc.selected.default_route_table_id}" | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = "${aws_internet_gateway.main.id}" | ||
} | ||
|
||
tags { | ||
Name = "${var.project_name}" | ||
} | ||
|
||
} | ||
|
||
output "nginx_node.public_dns" { | ||
value = "${aws_instance.nginx_node.public_dns}" | ||
} | ||
|
||
output "nginx_node.public_ip" { | ||
value = "${aws_instance.nginx_node.public_ip}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
resource "aws_key_pair" "deployer-key" { | ||
key_name = "${var.project_id}-key" | ||
public_key = "${var.public_key}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
provider "aws" { | ||
region = "${var.region}" | ||
profile = "${var.profile}" | ||
} | ||
|
||
variable "region" {} | ||
variable "profile" {} | ||
|
||
variable "project_name" { | ||
default = "Hello World" | ||
} | ||
|
||
variable "project_id" { | ||
default = "hello-world" | ||
} | ||
|
||
variable "instance_type" { | ||
default = "t2.micro" | ||
} | ||
|
||
variable "private_key_path" {} | ||
variable "public_key" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const express = require('express'); | ||
|
||
const app = express(); | ||
|
||
app.get('/', (req, res) => { | ||
res.send(`<h1>Dummy app</h1><p>Response from PID: ${process.pid}. Hit F5 many times!</p>`); | ||
}); | ||
app.listen(3000, () => console.log('Listening on port 3000!')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "sample-app", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"author": { | ||
"name": "Julian Reyes", | ||
"email": "jreyes@bixlabs.com", | ||
"url": "https://twitter.com/rokemaster" | ||
}, | ||
"dependencies": { | ||
"express": "^4.15.4" | ||
}, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This loads nvm | ||
export NVM_DIR="$HOME/.nvm" | ||
\. "$NVM_DIR/nvm.sh" | ||
|
||
cp -r $HOME/provision/app $HOME/ | ||
cp -r $HOME/provision/pm2.json $HOME/app-pm2.json | ||
npm i -g pm2 | ||
|
||
cd $HOME/app | ||
npm i | ||
|
||
pm2 start $HOME/app-pm2.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
sudo apt-get install -y nginx | ||
sudo rm /etc/nginx/sites-enabled/default | ||
sudo ln -s $HOME/provision/nginx_app.conf /etc/nginx/sites-enabled/default | ||
sudo systemctl restart nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
function latest_version() { | ||
curl -s https://api.github.com/repos/creationix/nvm/releases/latest \ | ||
| grep 'tag_name' \ | ||
| cut -d '"' -f 4 | ||
} | ||
|
||
function install_version() { | ||
curl "https://raw.githubusercontent.com/creationix/nvm/${1}/install.sh" \ | ||
| bash | ||
} | ||
|
||
install_version `latest_version` | ||
|
||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | ||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | ||
|
||
nvm install 8.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
DB_NAME=${1} | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
## Install postgres | ||
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" | ||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | ||
sudo apt-get update | ||
sudo apt-get install -y postgresql-9.6 | ||
|
||
## Setup postgres | ||
sudo sed -i.bak -e 's/peer/trust/' /etc/postgresql/9.6/main/pg_hba.conf | ||
sudo systemctl restart postgresql | ||
echo "ALTER USER postgres WITH PASSWORD 'postgres';" | psql -U postgres | ||
|
||
## Setup database | ||
echo "CREATE DATABASE hey_mozo ${DB_NAME};" | psql -U postgres |
7 changes: 7 additions & 0 deletions
7
modules/ec2-classic/provision/install_ubuntu_build_essential.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
sudo apt-get update | ||
sudo apt-get install -y build-essential libssl-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
upstream app { | ||
server 127.0.0.1:3000; | ||
} | ||
|
||
server { | ||
listen 80 default_server; | ||
listen [::]:80 default_server; | ||
|
||
server_name _; | ||
|
||
location / { | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
|
||
proxy_pass http://app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "dummy-app", | ||
"cwd": "/home/ubuntu/app", | ||
"script": "index.js", | ||
"env": { | ||
"NODE_ENV": "production" | ||
}, | ||
"instances": 2, | ||
"exec_mode": "cluster" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
resource "aws_security_group" "node_nginx" { | ||
name = "${var.project_id}-node-nginx" | ||
description = "Machine with Nginx and Node" | ||
vpc_id = "${aws_vpc.selected.id}" | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
} | ||
|
||
resource "aws_security_group_rule" "node_nginx_http" { | ||
from_port = 80 | ||
protocol = "tcp" | ||
security_group_id = "${aws_security_group.node_nginx.id}" | ||
to_port = 80 | ||
type = "ingress" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
resource "aws_security_group_rule" "node_nginx_ssh" { | ||
from_port = 22 | ||
protocol = "tcp" | ||
security_group_id = "${aws_security_group.node_nginx.id}" | ||
to_port = 22 | ||
type = "ingress" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
resource "aws_security_group_rule" "node_nginx_https" { | ||
from_port = 443 | ||
protocol = "tcp" | ||
security_group_id = "${aws_security_group.node_nginx.id}" | ||
to_port = 443 | ||
type = "ingress" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters