|
| 1 | +# Actualizando el Balancedor de carga y las instancias |
| 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 d3.tfplan |
| 10 | +terraform apply "d3.tfplan" |
| 11 | +``` |
| 12 | + |
| 13 | +## Pasos |
| 14 | + |
| 15 | +### Paso 1. Actualizamos el Balanceador de Carga |
| 16 | + |
| 17 | +Actualizamos `loadbalancer.tf` |
| 18 | + |
| 19 | +```diff |
| 20 | + |
| 21 | +## aws_lb |
| 22 | +resource "aws_lb" "nginx" { |
| 23 | + name = "lc-web-alb" |
| 24 | + internal = false |
| 25 | + load_balancer_type = "application" |
| 26 | + security_groups = [aws_security_group.alb_sg.id] |
| 27 | + subnets = [aws_subnet.subnet1.id, aws_subnet.subnet2.id] |
| 28 | + |
| 29 | + enable_deletion_protection = false |
| 30 | ++ |
| 31 | ++ access_logs { |
| 32 | ++ bucket = aws_s3_bucket.web_bucket.bucket |
| 33 | ++ prefix = "alb-logs" |
| 34 | ++ enabled = true |
| 35 | ++ } |
| 36 | ++ |
| 37 | + tags = local.common_tags |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Paso 2. Actualizamos las instancias |
| 42 | + |
| 43 | +```diff |
| 44 | +# INSTANCES # |
| 45 | +resource "aws_instance" "nginx1" { |
| 46 | + ami = nonsensitive(data.aws_ssm_parameter.ami.value) |
| 47 | + instance_type = var.aws_instance_type |
| 48 | + subnet_id = aws_subnet.subnet1.id |
| 49 | + vpc_security_group_ids = [aws_security_group.nginx-sg.id] |
| 50 | ++ iam_instance_profile = aws_iam_instance_profile.nginx_profile.name |
| 51 | ++ dependsdepends_on = [ |
| 52 | ++ aws_iam_role_policy.allow_s3_all |
| 53 | ++ ] |
| 54 | ++ |
| 55 | + user_data = <<EOF |
| 56 | +#! /bin/bash |
| 57 | +sudo amazon-linux-extras install -y nginx1 |
| 58 | +sudo service nginx start |
| 59 | +sudo rm /usr/share/nginx/html/index.html |
| 60 | +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 |
| 61 | +EOF |
| 62 | + |
| 63 | + tags = local.common_tags |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | +resource "aws_instance" "nginx2" { |
| 68 | + ami = nonsensitive(data.aws_ssm_parameter.ami.value) |
| 69 | + instance_type = var.aws_instance_type |
| 70 | + subnet_id = aws_subnet.subnet2.id |
| 71 | + vpc_security_group_ids = [aws_security_group.nginx-sg.id] |
| 72 | ++ iam_instance_profile = aws_iam_instance_profile.nginx_profile.name |
| 73 | ++ dependsdepends_on = [ |
| 74 | ++ aws_iam_role_policy.allow_s3_all |
| 75 | ++ ] |
| 76 | ++ |
| 77 | + user_data = <<EOF |
| 78 | +#! /bin/bash |
| 79 | +sudo amazon-linux-extras install -y nginx1 |
| 80 | +sudo service nginx start |
| 81 | +sudo rm /usr/share/nginx/html/index.html |
| 82 | +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 |
| 83 | +EOF |
| 84 | + |
| 85 | + tags = local.common_tags |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | +``` |
| 90 | + |
| 91 | +## Clean Up |
| 92 | + |
| 93 | +```bash |
| 94 | +terraform destroy |
| 95 | +``` |
0 commit comments