Skip to content

Commit

Permalink
Se agrega primer ejemplo_cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarsan01 committed Dec 9, 2019
1 parent a0a1202 commit 66a3393
Show file tree
Hide file tree
Showing 16 changed files with 460 additions and 72 deletions.
41 changes: 41 additions & 0 deletions ejemplo1_cpu/asg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "aws_autoscaling_group" "web" {
name = "${aws_launch_configuration.web.name}-asg"

min_size = 1
desired_capacity = 2
max_size = 4

health_check_type = "ELB"
load_balancers= [
"${aws_elb.web_elb.id}"
]

launch_configuration = "${aws_launch_configuration.web.name}"
availability_zones = ["us-east-1a", "us-east-1b"]

enabled_metrics = [
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupTotalInstances"
]

metrics_granularity="1Minute"

vpc_zone_identifier = [
"${aws_subnet.public_us_east_1a.*.id}",
"${aws_subnet.public_us_east_1b.*.id}"
]

# Required to redeploy without an outage.
lifecycle {
create_before_destroy = true
}

tag {
key = "Name"
value = "web"
propagate_at_launch = true
}
}
48 changes: 48 additions & 0 deletions ejemplo1_cpu/elb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
resource "aws_security_group" "elb_http" {
name = "elb_http"
description = "Allow HTTP traffic to instances through Elastic Load Balancer"
vpc_id = "${aws_vpc.my_vpc.id}"

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

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

tags {
Name = "Allow HTTP through ELB Security Group"
}
}

resource "aws_elb" "web_elb" {
name = "web-elb"
security_groups = [
"${aws_security_group.elb_http.id}"
]
subnets = [
"${aws_subnet.public_us_east_1a.id}",
"${aws_subnet.public_us_east_1b.id}"
]
cross_zone_load_balancing = true
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
interval = 30
target = "HTTP:80/"
}
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "80"
instance_protocol = "http"
}
}
59 changes: 59 additions & 0 deletions ejemplo1_cpu/infrastructure.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
resource "aws_vpc" "my_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true

tags {
Name = "My VPC"
}
}

resource "aws_subnet" "public_us_east_1a" {
vpc_id = "${aws_vpc.my_vpc.id}"
cidr_block = "10.0.0.0/24"
availability_zone = "us-east-1a"

tags {
Name = "Public Subnet us-east-1a"
}
}

resource "aws_subnet" "public_us_east_1b" {
vpc_id = "${aws_vpc.my_vpc.id}"
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1b"

tags {
Name = "Public Subnet us-east-1b"
}
}

resource "aws_internet_gateway" "my_vpc_igw" {
vpc_id = "${aws_vpc.my_vpc.id}"

tags {
Name = "My VPC - Internet Gateway"
}
}

resource "aws_route_table" "my_vpc_public" {
vpc_id = "${aws_vpc.my_vpc.id}"

route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.my_vpc_igw.id}"
}

tags {
Name = "Public Subnets Route Table for My VPC"
}
}

resource "aws_route_table_association" "my_vpc_us_east_1a_public" {
subnet_id = "${aws_subnet.public_us_east_1a.id}"
route_table_id = "${aws_route_table.my_vpc_public.id}"
}

resource "aws_route_table_association" "my_vpc_us_east_1b_public" {
subnet_id = "${aws_subnet.public_us_east_1b.id}"
route_table_id = "${aws_route_table.my_vpc_public.id}"
}
23 changes: 23 additions & 0 deletions ejemplo1_cpu/lc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "aws_launch_configuration" "web" {
name_prefix = "web-"

image_id = "ami-09479453c5cde9639" # Amazon Linux AMI 2018.03.0 (HVM)
instance_type = "t2.micro"
key_name = "Lenovo T410"

security_groups = ["${aws_security_group.allow_http.id}"]
associate_public_ip_address = true

user_data = <<USER_DATA
#!/bin/bash
yum update
yum -y install nginx
echo "$(curl http://169.254.169.254/latest/meta-data/local-ipv4)" > /usr/share/nginx/html/index.html
chkconfig nginx on
service nginx start
USER_DATA

lifecycle {
create_before_destroy = true
}
}
3 changes: 3 additions & 0 deletions ejemplo1_cpu/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "ELB_IP" {
value = "${aws_elb.web_elb.dns_name}"
}
3 changes: 3 additions & 0 deletions ejemplo1_cpu/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "us-west-2"
}
23 changes: 23 additions & 0 deletions ejemplo1_cpu/sg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "aws_security_group" "allow_http" {
name = "allow_http"
description = "Allow HTTP inbound connections"
vpc_id = "${aws_vpc.my_vpc.id}"

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

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

tags {
Name = "Allow HTTP Security Group"
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
resource "aws_autoscaling_group" "web" {
name = "${var.project_name}-web"
max_size = 2
min_size = 0
desired_capacity = 2
name = "${var.project_name}-web"
max_size = 2
min_size = 0
desired_capacity = 2

#Auto scaling se apoya en los chequeos de salud del balanceador.
health_check_type = "ELB"
#Auto scaling se apoya en los chequeos de salud del balanceador.
health_check_type = "ELB"

#Establece el tiempo de espera en segundos para comenzar a realizar los chequedos.
health_check_grace_period = 20
#Establece el tiempo de espera en segundos para comenzar a realizar los chequedos.
health_check_grace_period = 20

#Se le atacha el Load balancer al Auto Scaling Group.
#Se le atacha el Load balancer al Auto Scaling Group.
load_balancers = [
"${aws_elb.web.name}"
"${aws_elb.web.name}"
]

#Se le atacha el Launch Configuration al AutoScalingGroup.
launch_configuration = "${aws_launch_configuration.web.name}"
#Se le atacha el Launch Configuration al AutoScalingGroup.
launch_configuration = "${aws_launch_configuration.web.name}"


#El Auto Scaling Group se generara en las siguientes subnet de la VPC por default.
vpc_zone_identifier = [
"subnet-27eee00f",
"subnet-96b995cf" ,
"subnet-a0cfded7" ,
"subnet-a7e814c3"
#El Auto Scaling Group se generara en las siguientes subnet de la VPC por default.
vpc_zone_identifier = [
"subnet-27eee00f",
"subnet-96b995cf",
"subnet-a0cfded7",
"subnet-a7e814c3"
]

tag {
Expand Down
Loading

0 comments on commit 66a3393

Please sign in to comment.