|
| 1 | +# Añadiendo nuevos recursos a la configuración |
| 2 | + |
| 3 | +## Pre requisitos |
| 4 | + |
| 5 | +> Si has destruidfo el entorno recrealo |
| 6 | +
|
| 7 | +```bash |
| 8 | +cd lab/lc_web_app/ |
| 9 | +terraform plan -out d1.tfplan |
| 10 | +terraform apply "d2.tfplan" |
| 11 | +``` |
| 12 | + |
| 13 | +## Pasos |
| 14 | + |
| 15 | +### Paso 1. Crear nuevos recursos y renombrar |
| 16 | + |
| 17 | +* Crear `./lab/lc_web_app/loadbalancer.tf` |
| 18 | +* Crear `./lab/lc_web_app/instances.tf` |
| 19 | +* Renombrar `./lab/lc_web_app/main.tf` --> `./lab/lc_web_app/network.tf` |
| 20 | + |
| 21 | +### Paso 2. Movemos la instancia a su propio fichero. |
| 22 | + |
| 23 | +Cortamos el contenido en `network.tf` |
| 24 | + |
| 25 | +```diff |
| 26 | +- # INSTANCES # |
| 27 | +- resource "aws_instance" "nginx1" { |
| 28 | +- ami = nonsensitive(data.aws_ssm_parameter.ami.value) |
| 29 | +- instance_type = var.aws_instance_type |
| 30 | +- subnet_id = aws_subnet.subnet1.id |
| 31 | +- vpc_security_group_ids = [aws_security_group.nginx-sg.id] |
| 32 | +- |
| 33 | +- user_data = <<EOF |
| 34 | +- #! /bin/bash |
| 35 | +- sudo amazon-linux-extras install -y nginx1 |
| 36 | +- sudo service nginx start |
| 37 | +- sudo rm /usr/share/nginx/html/index.html |
| 38 | +- 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 |
| 39 | +- EOF |
| 40 | +- |
| 41 | +- tags = local.common_tags |
| 42 | +- |
| 43 | +- } |
| 44 | +``` |
| 45 | + |
| 46 | +Y lo añadimos a `instances.tf` |
| 47 | + |
| 48 | +```tf |
| 49 | +# INSTANCES # |
| 50 | +resource "aws_instance" "nginx1" { |
| 51 | + ami = nonsensitive(data.aws_ssm_parameter.ami.value) |
| 52 | + instance_type = var.aws_instance_type |
| 53 | + subnet_id = aws_subnet.subnet1.id |
| 54 | + vpc_security_group_ids = [aws_security_group.nginx-sg.id] |
| 55 | +
|
| 56 | + user_data = <<EOF |
| 57 | +#! /bin/bash |
| 58 | +sudo amazon-linux-extras install -y nginx1 |
| 59 | +sudo service nginx start |
| 60 | +sudo rm /usr/share/nginx/html/index.html |
| 61 | +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 |
| 62 | +EOF |
| 63 | +
|
| 64 | + tags = local.common_tags |
| 65 | +
|
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +### Paso 3. Nos preparamos para añadir los recursos del balanceo de carga |
| 70 | + |
| 71 | +Actualizamos `loadbalancer.tf` |
| 72 | + |
| 73 | +```tf |
| 74 | +## aws_lb |
| 75 | +
|
| 76 | +## aws_lb_target_group |
| 77 | +
|
| 78 | +## aws_lb_listener |
| 79 | +
|
| 80 | +## aws_lb_target_group_attachment |
| 81 | +``` |
| 82 | + |
| 83 | +## Clean Up |
| 84 | + |
| 85 | +```bash |
| 86 | +terraform destroy |
| 87 | +``` |
0 commit comments