You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 05-iac/00-terraform/04-incorporando-recursos/09-demo.md
+228-1Lines changed: 228 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,4 +10,231 @@ terraform plan -out d1.tfplan
10
10
terraform apply "d2.tfplan"
11
11
```
12
12
13
-
## Pasos
13
+
## Pasos
14
+
15
+
Ahora que hemos añadido la fuente de datos de las `avaibility zones`, vamos a actualizar los `security groups` relacionados con las `subnets` y las instancias EC2.
Antes que creemos la segunda `availability zone`, recordemos que hemos definido el `cidr block` en un variable, sería mejor si tuvieramos un sólo lugar donde definir los `cidr blocks` de ambas.
33
+
34
+
Actualizamos `variables.tf`
35
+
36
+
```diff
37
+
# ....
38
+
-variable "subnet_cidr_block" {
39
+
- type = string
40
+
- description = "Subnet cidr block"
41
+
- default = "10.0.0.0/24"
42
+
-}
43
+
+
44
+
+variable "subnets_cidr_block" {
45
+
+ type = string
46
+
+ description = "Subnet cidr block"
47
+
+ default = ["10.0.0.0/24", "10.0.1.0/24"]
48
+
+}
49
+
# ....
50
+
```
51
+
52
+
Ahora podemos actualizar la subnet de la siguienete manera:
Ahora que hemos generado una nueva subnet, debemos crear una nueva asociación con la `route table` a fin de poder redirigir el tráfico desde la nueva EC2 hacia el exterior.
echo '<html><head><title>Lemon Land Server</title></head><body style=\"background-color:#1F778D\"><p style=\"text-align: center;\"><span style=\"color:#FFFFFF;\"><span style=\"font-size:28px;\">Welcome to 🍋 land</span></span></p></body></html>' | sudo tee /usr/share/nginx/html/index.html
149
+
EOF
150
+
151
+
tags = local.common_tags
152
+
153
+
}
154
+
#-----------diff-------------#
155
+
```
156
+
157
+
### Paso 5. Añadir un security group
158
+
159
+
Necesitamos crear un `security group` adicional para el balanceador de carga, de manera que permita el tráfico al puerto 80 desde cualquier dirección. Simplemente vamos a duplicar el que ya tenemos:
160
+
161
+
Actualizamos `network.tf`
162
+
163
+
```tf
164
+
# SECURITY GROUPS #
165
+
resource "aws_security_group" "nginx-sg" {
166
+
name = "nginx_sg"
167
+
vpc_id = aws_vpc.vpc.id
168
+
169
+
# HTTP access from anywhere
170
+
ingress {
171
+
from_port = var.sg_ingress_port
172
+
to_port = var.sg_ingress_port
173
+
protocol = "tcp"
174
+
cidr_blocks = var.sg_ingress_cidr_blocks
175
+
}
176
+
177
+
# outbound internet access
178
+
egress {
179
+
from_port = var.sg_egress_port
180
+
to_port = var.sg_egress_port
181
+
protocol = "-1"
182
+
cidr_blocks = var.sg_egress_cidr_blocks
183
+
}
184
+
185
+
tags = local.common_tags
186
+
}
187
+
#-----------diff-------------#
188
+
resource "aws_security_group" "alb_sg" {
189
+
name = "nginx_alb_sg"
190
+
vpc_id = aws_vpc.vpc.id
191
+
192
+
# HTTP access from anywhere
193
+
ingress {
194
+
from_port = var.sg_ingress_port
195
+
to_port = var.sg_ingress_port
196
+
protocol = "tcp"
197
+
cidr_blocks = var.sg_ingress_cidr_blocks
198
+
}
199
+
200
+
# outbound internet access
201
+
egress {
202
+
from_port = var.sg_egress_port
203
+
to_port = var.sg_egress_port
204
+
protocol = "-1"
205
+
cidr_blocks = var.sg_egress_cidr_blocks
206
+
}
207
+
208
+
tags = local.common_tags
209
+
}
210
+
#-----------diff-------------#
211
+
```
212
+
213
+
Ahora que vamos a tener un load balancer por delante de nuestras instancias, sólo queremos aceptar táfico que venga desde dentro de la `VPC`
0 commit comments