-
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.
- Loading branch information
Showing
5 changed files
with
195 additions
and
0 deletions.
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,10 @@ | ||
## Criar uma infraestrutura na Amazon AWS utilizando o Terraform | ||
* Subir 1 instância EC2 t2.micro com EBS attached de 20GB na rede pública | ||
|
||
`vpc.tf`: Responsável por criar a VPC e também subnets Pública e Privada | ||
|
||
`variables.tf`: Declaração das variáveis | ||
|
||
`public.tf`: Criar as 1 instância com disco de 20GB atachado e atrelado à subnet pública | ||
|
||
`provider`: Faz a conexão com a AWS |
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,5 @@ | ||
provider "aws" { | ||
access_key = "${var.aws_access_key}" | ||
secret_key = "${var.aws_secret_key}" | ||
region = "${var.aws_region}" | ||
} |
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,67 @@ | ||
/* | ||
Web Servers | ||
*/ | ||
resource "aws_security_group" "webserver" { | ||
name = "vpc_web" | ||
description = "HTTP connections." | ||
|
||
ingress { | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = -1 | ||
to_port = -1 | ||
protocol = "icmp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
egress { # All Traffic | ||
from_port = 0 | ||
to_port = 65535 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
vpc_id = "${aws_vpc.default.id}" | ||
|
||
tags { | ||
Name = "WebServerSG" | ||
} | ||
} | ||
|
||
resource "aws_instance" "webserver" { | ||
ami = "${lookup(var.amis, var.aws_region)}" | ||
instance_type = "t2.micro" | ||
key_name = "${var.aws_key_name}" | ||
vpc_security_group_ids = ["${aws_security_group.webserver.id}"] | ||
subnet_id = "${aws_subnet.us-east-1-public.id}" | ||
associate_public_ip_address = true | ||
source_dest_check = false | ||
ebs_block_device { | ||
device_name = "/dev/sda1" | ||
volume_size = "20" | ||
volume_type = "gp2" | ||
delete_on_termination = "true" | ||
} | ||
|
||
tags { | ||
Name = "Web Server 1" | ||
} | ||
} | ||
|
||
|
||
resource "aws_eip" "webserver" { | ||
instance = "${aws_instance.webserver.id}" | ||
vpc = 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,35 @@ | ||
# Variaveis AWS | ||
|
||
variable "aws_access_key" {} | ||
variable "aws_secret_key" {} | ||
variable "aws_key_path" {} | ||
variable "aws_key_name" {} | ||
|
||
variable "aws_region" { | ||
description = "REGIAO PARA CRIACAO EC2 e VPC" | ||
default = "us-east-1" | ||
} | ||
|
||
variable "amis" { | ||
description = "IMI Ubuntu da Regiao US EAST 1 " | ||
default = { | ||
us-east-1 = "ami-43a15f3e" | ||
} | ||
} | ||
|
||
variable "vpc_cidr" { | ||
description = "CIDR for the whole VPC" | ||
default = "10.0.0.0/16" | ||
} | ||
|
||
variable "public_subnet_cidr" { | ||
description = "CIDR for the Public Subnet" | ||
default = "10.0.0.0/24" | ||
} | ||
|
||
variable "private_subnet_cidr" { | ||
description = "CIDR for the Private Subnet" | ||
default = "10.0.1.0/24" | ||
} | ||
|
||
|
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,78 @@ | ||
# Criacao da VPC e Subnets Publica e Privada | ||
|
||
resource "aws_vpc" "default" { | ||
cidr_block = "${var.vpc_cidr}" | ||
enable_dns_hostnames = true | ||
tags { | ||
Name = "terraform-aws-vpc" | ||
} | ||
} | ||
|
||
resource "aws_internet_gateway" "default" { | ||
vpc_id = "${aws_vpc.default.id}" | ||
} | ||
|
||
|
||
/* | ||
Public Subnet | ||
*/ | ||
resource "aws_subnet" "us-east-1-public" { | ||
vpc_id = "${aws_vpc.default.id}" | ||
|
||
cidr_block = "${var.public_subnet_cidr}" | ||
availability_zone = "us-east-1a" | ||
|
||
tags { | ||
Name = "Public Subnet" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "us-east-1-public" { | ||
vpc_id = "${aws_vpc.default.id}" | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = "${aws_internet_gateway.default.id}" | ||
} | ||
|
||
tags { | ||
Name = "Public Subnet" | ||
} | ||
} | ||
|
||
resource "aws_route_table_association" "us-east-1-public" { | ||
subnet_id = "${aws_subnet.us-east-1-public.id}" | ||
route_table_id = "${aws_route_table.us-east-1-public.id}" | ||
} | ||
|
||
/* | ||
Private Subnet | ||
*/ | ||
resource "aws_subnet" "us-east-1-private" { | ||
vpc_id = "${aws_vpc.default.id}" | ||
|
||
cidr_block = "${var.private_subnet_cidr}" | ||
availability_zone = "us-east-1b" | ||
|
||
tags { | ||
Name = "Private Subnet" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "us-east-1-private" { | ||
vpc_id = "${aws_vpc.default.id}" | ||
|
||
route { | ||
cidr_block = "0.0.0.0/0" | ||
} | ||
|
||
tags { | ||
Name = "Private Subnet" | ||
} | ||
} | ||
|
||
resource "aws_route_table_association" "us-east-1-private" { | ||
subnet_id = "${aws_subnet.us-east-1-private.id}" | ||
route_table_id = "${aws_route_table.us-east-1-private.id}" | ||
} | ||
|