https://pulumi.com logo
#golang
Title
# golang
r

rich-exabyte-94739

10/02/2020, 5:55 PM
Hi all, I'm trying to setup an ALB with target groups and having trouble finding out where I specify my targets for a target group. I can define my TargetGroup just fine:
Copy code
frontEndTargetGroup, err := lb.NewTargetGroup(ctx, "foo-tg", &lb.TargetGroupArgs{
			Name:       pulumi.String("foo-tg"),
			Port:       <http://pulumi.Int|pulumi.Int>(80),
			Protocol:   pulumi.String("HTTP"),
			VpcId:      vpc.ID(),
			TargetType: pulumi.String("ip"),
			HealthCheck: &lb.TargetGroupHealthCheckArgs{
				Enabled:            pulumi.Bool(true),
				Path:               pulumi.String("/health"),
				Protocol:           pulumi.String("HTTP"),
				HealthyThreshold:   <http://pulumi.Int|pulumi.Int>(5),
				UnhealthyThreshold: <http://pulumi.Int|pulumi.Int>(5),
				Timeout:            <http://pulumi.Int|pulumi.Int>(5),
			},
		})
		if err != nil {
			return err
		}
I'm just not sure where to go after this. How do I add an IP address to this target group?
w

witty-candle-66007

10/02/2020, 6:06 PM
I think you want the TargetGroupAttachment resource https://www.pulumi.com/docs/reference/pkg/aws/alb/targetgroupattachment/ Specifically, https://www.pulumi.com/docs/reference/pkg/aws/alb/targetgroupattachment/#create And if you look at the TargetGroupAttachmentArgs you'll see a targetId property which is where you can specify IP addresses.
r

rich-exabyte-94739

10/05/2020, 2:42 PM
Thanks @witty-candle-66007! Is a way I can get my ECS task IP address via Pulumi to pass as the targetId? Not seeing it in https://www.pulumi.com/docs/reference/pkg/aws/ecs/gettaskdefinition/#taskdefinition_go.
w

witty-candle-66007

10/05/2020, 3:20 PM
If using ECS, you should be able to let AWS do the routing by referencing the load balancer in the ECS definition. This example may help: https://github.com/pulumi/examples/blob/master/aws-go-fargate/main.go In it, you see the various resources being defined and then in the ecs.NewService() call the LB is referenced. At this point AWS knows to route the traffic to the tasks appropriately. This page discusses this as well: https://docs.aws.amazon.com/AmazonECS/latest/userguide/create-application-load-balancer.html (See the Register targets and last sections specifically.)
r

rich-exabyte-94739

10/05/2020, 5:43 PM
Thanks Mitch, that was exactly what I needed!
👍 1
3 Views