Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
javaguirre committed Jan 31, 2020
0 parents commit 11a1234
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tfvars
*.tfstate
.terraform/
7 changes: 7 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "Prestashop URL STAGING" {
value = "ssh ${aws_instance.prestashop_staging.public_ip}:22"
}

output "Prestashop URL PRODUCTION" {
value = "ssh ${aws_instance.prestashop_production.public_ip}:22"
}
6 changes: 6 additions & 0 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "aws" {
version = "~> 2.42"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
region = var.region
}
89 changes: 89 additions & 0 deletions terraform/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
resource "aws_instance" "prestashop_staging" {
ami = var.ami
instance_type = var.ec2_size
key_name = var.key_name

vpc_security_group_ids = [
aws_security_group.web.id,
aws_security_group.ssh.id,
aws_security_group.egress-tls.id,
aws_security_group.ping-ICMP.id
]

tags = {
Name = "prestashop-staging"
}
}

resource "aws_instance" "prestashop_production" {
ami = var.ami
instance_type = var.ec2_size
key_name = var.key_name

vpc_security_group_ids = [
aws_security_group.web.id,
aws_security_group.ssh.id,
aws_security_group.egress-tls.id,
aws_security_group.ping-ICMP.id
]

tags = {
Name = "prestashop-production"
}
}

resource "aws_security_group" "web" {
name = "default-web-prestashop"
description = "Security group for web that allows web traffic from internet"

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_security_group" "ssh" {
name = "default-ssh-prestashop"
description = "Security group for nat instances that allows SSH and VPN traffic from internet"

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_security_group" "egress-tls" {
name = "default-egress-tls-prestashop"
description = "Default security group that allows inbound and outbound traffic from all instances in the VPC"

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_security_group" "ping-ICMP" {
name = "default-ping-prestashop"
description = "Default security group that allows to ping the instance"

ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
40 changes: 40 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "profile" {
default = "terraform_iam_user"
}

variable "region" {
default = "eu-west-1"
}

variable "key_name" {
default = "javaguirre-tnp"
}

variable "aws_access_key" {
default = ""
}

variable "aws_secret_key" {
default = ""
}

variable "instance" {
default = "t2.micro"
}

variable "instance_count" {
default = "1"
}


variable "ansible_user" {
default = "ubuntu"
}

variable "ami" {
default = "ami-04c58523038d79132" # Ubuntu 18.04
}

variable "ec2_size" {
default = "t2.medium"
}

0 comments on commit 11a1234

Please sign in to comment.