Complete the code to create a highly available web server using AWS Elastic Load Balancer.
resource "aws_elb" "web_elb" { name = "web-elb" availability_zones = ["us-east-1a", "us-east-1b"] listener { instance_port = 80 instance_protocol = "HTTP" lb_port = 80 lb_protocol = [1] } }
The load balancer protocol should match the instance protocol for HTTP traffic, so "HTTP" is correct.
Complete the code to define an Auto Scaling group with a minimum of 2 instances for high availability.
resource "aws_autoscaling_group" "web_asg" { name = "web-asg" max_size = 5 min_size = [1] desired_capacity = 3 launch_configuration = aws_launch_configuration.web_lc.name availability_zones = ["us-east-1a", "us-east-1b"] }
Setting min_size to 2 ensures at least two instances run for high availability.
Fix the error in the Route 53 health check configuration to improve availability.
resource "aws_route53_health_check" "web_health_check" { fqdn = "example.com" port = 80 type = [1] failure_threshold = 3 }
The health check type should be HTTP for port 80 to correctly monitor web server health.
Fill both blanks to configure a multi-AZ RDS instance for high availability.
resource "aws_db_instance" "mydb" { allocated_storage = 20 engine = "mysql" instance_class = [1] multi_az = [2] identifier = "mydb" username = "admin" password = "password" skip_final_snapshot = true }
Use a suitable instance class like db.m5.large and set multi_az to true for high availability.
Fill all three blanks to create a CloudWatch alarm that triggers when CPU usage is high.
resource "aws_cloudwatch_metric_alarm" "high_cpu" { alarm_name = "high_cpu_alarm" comparison_operator = [1] evaluation_periods = 2 metric_name = "CPUUtilization" namespace = "AWS/EC2" period = 300 statistic = [2] threshold = 80 alarm_actions = [aws_sns_topic.alerts.arn] dimensions = { InstanceId = [3] } }
The alarm triggers when CPU usage is greater than the threshold using average metric and the instance ID dimension.