Skip to content

Commit 66a3393

Browse files
committed
Se agrega primer ejemplo_cpu
1 parent a0a1202 commit 66a3393

File tree

16 files changed

+460
-72
lines changed

16 files changed

+460
-72
lines changed

ejemplo1_cpu/asg.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "aws_autoscaling_group" "web" {
2+
name = "${aws_launch_configuration.web.name}-asg"
3+
4+
min_size = 1
5+
desired_capacity = 2
6+
max_size = 4
7+
8+
health_check_type = "ELB"
9+
load_balancers= [
10+
"${aws_elb.web_elb.id}"
11+
]
12+
13+
launch_configuration = "${aws_launch_configuration.web.name}"
14+
availability_zones = ["us-east-1a", "us-east-1b"]
15+
16+
enabled_metrics = [
17+
"GroupMinSize",
18+
"GroupMaxSize",
19+
"GroupDesiredCapacity",
20+
"GroupInServiceInstances",
21+
"GroupTotalInstances"
22+
]
23+
24+
metrics_granularity="1Minute"
25+
26+
vpc_zone_identifier = [
27+
"${aws_subnet.public_us_east_1a.*.id}",
28+
"${aws_subnet.public_us_east_1b.*.id}"
29+
]
30+
31+
# Required to redeploy without an outage.
32+
lifecycle {
33+
create_before_destroy = true
34+
}
35+
36+
tag {
37+
key = "Name"
38+
value = "web"
39+
propagate_at_launch = true
40+
}
41+
}

ejemplo1_cpu/elb.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
resource "aws_security_group" "elb_http" {
2+
name = "elb_http"
3+
description = "Allow HTTP traffic to instances through Elastic Load Balancer"
4+
vpc_id = "${aws_vpc.my_vpc.id}"
5+
6+
ingress {
7+
from_port = 80
8+
to_port = 80
9+
protocol = "tcp"
10+
cidr_blocks = ["0.0.0.0/0"]
11+
}
12+
13+
egress {
14+
from_port = 0
15+
to_port = 0
16+
protocol = "-1"
17+
cidr_blocks = ["0.0.0.0/0"]
18+
}
19+
20+
tags {
21+
Name = "Allow HTTP through ELB Security Group"
22+
}
23+
}
24+
25+
resource "aws_elb" "web_elb" {
26+
name = "web-elb"
27+
security_groups = [
28+
"${aws_security_group.elb_http.id}"
29+
]
30+
subnets = [
31+
"${aws_subnet.public_us_east_1a.id}",
32+
"${aws_subnet.public_us_east_1b.id}"
33+
]
34+
cross_zone_load_balancing = true
35+
health_check {
36+
healthy_threshold = 2
37+
unhealthy_threshold = 2
38+
timeout = 3
39+
interval = 30
40+
target = "HTTP:80/"
41+
}
42+
listener {
43+
lb_port = 80
44+
lb_protocol = "http"
45+
instance_port = "80"
46+
instance_protocol = "http"
47+
}
48+
}

ejemplo1_cpu/infrastructure.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
resource "aws_vpc" "my_vpc" {
2+
cidr_block = "10.0.0.0/16"
3+
enable_dns_hostnames = true
4+
5+
tags {
6+
Name = "My VPC"
7+
}
8+
}
9+
10+
resource "aws_subnet" "public_us_east_1a" {
11+
vpc_id = "${aws_vpc.my_vpc.id}"
12+
cidr_block = "10.0.0.0/24"
13+
availability_zone = "us-east-1a"
14+
15+
tags {
16+
Name = "Public Subnet us-east-1a"
17+
}
18+
}
19+
20+
resource "aws_subnet" "public_us_east_1b" {
21+
vpc_id = "${aws_vpc.my_vpc.id}"
22+
cidr_block = "10.0.1.0/24"
23+
availability_zone = "us-east-1b"
24+
25+
tags {
26+
Name = "Public Subnet us-east-1b"
27+
}
28+
}
29+
30+
resource "aws_internet_gateway" "my_vpc_igw" {
31+
vpc_id = "${aws_vpc.my_vpc.id}"
32+
33+
tags {
34+
Name = "My VPC - Internet Gateway"
35+
}
36+
}
37+
38+
resource "aws_route_table" "my_vpc_public" {
39+
vpc_id = "${aws_vpc.my_vpc.id}"
40+
41+
route {
42+
cidr_block = "0.0.0.0/0"
43+
gateway_id = "${aws_internet_gateway.my_vpc_igw.id}"
44+
}
45+
46+
tags {
47+
Name = "Public Subnets Route Table for My VPC"
48+
}
49+
}
50+
51+
resource "aws_route_table_association" "my_vpc_us_east_1a_public" {
52+
subnet_id = "${aws_subnet.public_us_east_1a.id}"
53+
route_table_id = "${aws_route_table.my_vpc_public.id}"
54+
}
55+
56+
resource "aws_route_table_association" "my_vpc_us_east_1b_public" {
57+
subnet_id = "${aws_subnet.public_us_east_1b.id}"
58+
route_table_id = "${aws_route_table.my_vpc_public.id}"
59+
}

ejemplo1_cpu/lc.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "aws_launch_configuration" "web" {
2+
name_prefix = "web-"
3+
4+
image_id = "ami-09479453c5cde9639" # Amazon Linux AMI 2018.03.0 (HVM)
5+
instance_type = "t2.micro"
6+
key_name = "Lenovo T410"
7+
8+
security_groups = ["${aws_security_group.allow_http.id}"]
9+
associate_public_ip_address = true
10+
11+
user_data = <<USER_DATA
12+
#!/bin/bash
13+
yum update
14+
yum -y install nginx
15+
echo "$(curl http://169.254.169.254/latest/meta-data/local-ipv4)" > /usr/share/nginx/html/index.html
16+
chkconfig nginx on
17+
service nginx start
18+
USER_DATA
19+
20+
lifecycle {
21+
create_before_destroy = true
22+
}
23+
}

ejemplo1_cpu/output.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "ELB_IP" {
2+
value = "${aws_elb.web_elb.dns_name}"
3+
}

ejemplo1_cpu/provider.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}

ejemplo1_cpu/sg.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "aws_security_group" "allow_http" {
2+
name = "allow_http"
3+
description = "Allow HTTP inbound connections"
4+
vpc_id = "${aws_vpc.my_vpc.id}"
5+
6+
ingress {
7+
from_port = 80
8+
to_port = 80
9+
protocol = "tcp"
10+
cidr_blocks = ["0.0.0.0/0"]
11+
}
12+
13+
egress {
14+
from_port = 0
15+
to_port = 0
16+
protocol = "-1"
17+
cidr_blocks = ["0.0.0.0/0"]
18+
}
19+
20+
tags {
21+
Name = "Allow HTTP Security Group"
22+
}
23+
}

instanciasweb-terraform-aws-asg-and-lc-with-elb_cpu/Auto_Scaling_Group.tf

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
resource "aws_autoscaling_group" "web" {
2-
name = "${var.project_name}-web"
3-
max_size = 2
4-
min_size = 0
5-
desired_capacity = 2
2+
name = "${var.project_name}-web"
3+
max_size = 2
4+
min_size = 0
5+
desired_capacity = 2
66

7-
#Auto scaling se apoya en los chequeos de salud del balanceador.
8-
health_check_type = "ELB"
7+
#Auto scaling se apoya en los chequeos de salud del balanceador.
8+
health_check_type = "ELB"
99

10-
#Establece el tiempo de espera en segundos para comenzar a realizar los chequedos.
11-
health_check_grace_period = 20
10+
#Establece el tiempo de espera en segundos para comenzar a realizar los chequedos.
11+
health_check_grace_period = 20
1212

13-
#Se le atacha el Load balancer al Auto Scaling Group.
13+
#Se le atacha el Load balancer al Auto Scaling Group.
1414
load_balancers = [
15-
"${aws_elb.web.name}"
15+
"${aws_elb.web.name}"
1616
]
1717

18-
#Se le atacha el Launch Configuration al AutoScalingGroup.
19-
launch_configuration = "${aws_launch_configuration.web.name}"
18+
#Se le atacha el Launch Configuration al AutoScalingGroup.
19+
launch_configuration = "${aws_launch_configuration.web.name}"
2020

2121

22-
#El Auto Scaling Group se generara en las siguientes subnet de la VPC por default.
23-
vpc_zone_identifier = [
24-
"subnet-27eee00f",
25-
"subnet-96b995cf" ,
26-
"subnet-a0cfded7" ,
27-
"subnet-a7e814c3"
22+
#El Auto Scaling Group se generara en las siguientes subnet de la VPC por default.
23+
vpc_zone_identifier = [
24+
"subnet-27eee00f",
25+
"subnet-96b995cf",
26+
"subnet-a0cfded7",
27+
"subnet-a7e814c3"
2828
]
2929

3030
tag {

0 commit comments

Comments
 (0)