Terraform how to register known private ip address in target group of type "ip"

5.4k views Asked by At

In Terraform

How can register known private ip addresses in target group of type "ip". Below is my current code.

resource "aws_alb_target_group" "default" {
  name        = "target group name"
  port        = var.container_port
  protocol    = "HTTP"
  target_type = "ip"
  vpc_id      = data.terraform_remote_state.network.outputs.vpc_id

  health_check {
    path     = var.health_check_path
    protocol = "HTTP"
    port     = var.target_group_port
    interval = 60
  }

  tags = var.tags
 
}
2

There are 2 answers

0
Marcin On

You use aws_lb_target_group_attachment for that.

For example:

resource "aws_lb_target_group_attachment" "test" {
  target_group_arn = aws_alb_target_group.default.arn
  target_id        = instance-ip-address
  port             = 80
}
0
Dan Edeen On

Not: target_group_arn = aws_alb_target_group.default.arn, but instead:

target_group_arn = aws_lb_target_group.default.arn