Advertisement
PandaAcademy

alb.tf

Jul 27th, 2022
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. resource "aws_default_subnet" "default_az" {
  2. count = length(var.availability_zones)
  3. availability_zone = var.availability_zones[count.index]
  4. }
  5.  
  6. resource "aws_default_vpc" "default" {}
  7.  
  8. resource "aws_lb" "alb" {
  9. name = "alb"
  10. internal = false
  11. load_balancer_type = "application"
  12. security_groups = [aws_security_group.sg_pub.id]
  13. subnets = aws_default_subnet.default_az[*].id
  14. }
  15.  
  16. resource "aws_lb_listener" "alb_listener_frontend" {
  17. load_balancer_arn = aws_lb.alb.arn
  18. port = "5000"
  19. protocol = "HTTP"
  20.  
  21. default_action {
  22. type = "forward"
  23. target_group_arn = aws_lb_target_group.tg_frontend.arn
  24. }
  25. }
  26.  
  27. resource "aws_lb_target_group" "tg_frontend" {
  28. name = "tg-frontend"
  29. port = 5000
  30. protocol = "HTTP"
  31. target_type = "instance"
  32. vpc_id = aws_default_vpc.default.id
  33. }
  34.  
  35. resource "aws_lb_target_group_attachment" "tg_attch_frontend" {
  36. count = length(aws_instance.panda)
  37. target_group_arn = aws_lb_target_group.tg_frontend.arn
  38. target_id = aws_instance.panda[count.index].id
  39. port = 5000
  40. }
  41.  
  42. resource "aws_lb_listener" "alb_listener_backend" {
  43. load_balancer_arn = aws_lb.alb.arn
  44. port = "5001"
  45. protocol = "HTTP"
  46.  
  47. default_action {
  48. type = "forward"
  49. target_group_arn = aws_lb_target_group.tg_backend.arn
  50. }
  51. }
  52.  
  53. resource "aws_lb_target_group" "tg_backend" {
  54. name = "tg-backend"
  55. port = 5001
  56. protocol = "HTTP"
  57. target_type = "instance"
  58. vpc_id = aws_default_vpc.default.id
  59. }
  60.  
  61. resource "aws_lb_target_group_attachment" "tg_attch_backend" {
  62. count = length(aws_instance.panda)
  63. target_group_arn = aws_lb_target_group.tg_backend.arn
  64. target_id = aws_instance.panda[count.index].id
  65. port = 5001
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement