diff --git a/pkg/app/piped/platformprovider/ecs/client.go b/pkg/app/piped/platformprovider/ecs/client.go index f7853e2b97..37b4c88192 100644 --- a/pkg/app/piped/platformprovider/ecs/client.go +++ b/pkg/app/piped/platformprovider/ecs/client.go @@ -355,6 +355,44 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou return nil } +func (c *client) ModifyListenerRules(ctx context.Context, listenerRuleArns []string, routingTrafficCfg RoutingTrafficConfig) error { + if len(routingTrafficCfg) != 2 { + return fmt.Errorf("invalid listener configuration: requires 2 target groups") + } + + modifyListenerRule := func(ctx context.Context, listenerRuleArn string) error { + input := &elasticloadbalancingv2.ModifyRuleInput{ + RuleArn: aws.String(listenerRuleArn), + Actions: []elbtypes.Action{ + { + Type: elbtypes.ActionTypeEnumForward, + ForwardConfig: &elbtypes.ForwardActionConfig{ + TargetGroups: []elbtypes.TargetGroupTuple{ + { + TargetGroupArn: aws.String(routingTrafficCfg[0].TargetGroupArn), + Weight: aws.Int32(int32(routingTrafficCfg[0].Weight)), + }, + { + TargetGroupArn: aws.String(routingTrafficCfg[1].TargetGroupArn), + Weight: aws.Int32(int32(routingTrafficCfg[1].Weight)), + }, + }, + }, + }, + }, + } + _, err := c.elbClient.ModifyRule(ctx, input) + return err + } + + for _, listener := range listenerRuleArns { + if err := modifyListenerRule(ctx, listener); err != nil { + return err + } + } + return nil +} + func (c *client) TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error { input := &ecs.TagResourceInput{ ResourceArn: aws.String(resourceArn),