diff --git a/ecs/pkg/amazon/cloudformation.go b/ecs/pkg/amazon/cloudformation.go index 0e6966bb..35d2e123 100644 --- a/ecs/pkg/amazon/cloudformation.go +++ b/ecs/pkg/amazon/cloudformation.go @@ -172,15 +172,10 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err } func (c client) createLoadBalancer(project *compose.Project, template *cloudformation.Template) string { - loadBalancerType := "network" - loadBalancerName := fmt.Sprintf( - "%s%sLB", - strings.Title(project.Name), - strings.ToUpper(loadBalancerType[0:1]), - ) - loadBalancer := &elasticloadbalancingv2.LoadBalancer{ + loadBalancerName := fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name)) + template.Resources[loadBalancerName] = &elasticloadbalancingv2.LoadBalancer{ Name: loadBalancerName, - Scheme: "internet-facing", + Scheme: elbv2.LoadBalancerSchemeEnumInternetFacing, Subnets: []string{ cloudformation.Ref(ParameterSubnet1Id), cloudformation.Ref(ParameterSubnet2Id), @@ -191,18 +186,17 @@ func (c client) createLoadBalancer(project *compose.Project, template *cloudform Value: project.Name, }, }, - Type: loadBalancerType, + Type: elbv2.LoadBalancerTypeEnumNetwork, } - template.Resources[loadBalancerName] = loadBalancer return loadBalancerName } func (c client) createListener(service types.ServiceConfig, port types.ServicePortConfig, template *cloudformation.Template, targetGroupName string, loadBalancerName string, protocol string) string { listenerName := fmt.Sprintf( - "%s%s%sListener", + "%s%s%dListener", normalizeResourceName(service.Name), strings.ToUpper(port.Protocol), - string(port.Published), + port.Published, ) //add listener to dependsOn //https://stackoverflow.com/questions/53971873/the-target-group-does-not-have-an-associated-load-balancer @@ -228,10 +222,10 @@ func (c client) createListener(service types.ServiceConfig, port types.ServicePo func (c client) createTargetGroup(project *compose.Project, service types.ServiceConfig, port types.ServicePortConfig, template *cloudformation.Template, protocol string) string { targetGroupName := fmt.Sprintf( - "%s%s%sTargetGroup", + "%s%s%dTargetGroup", normalizeResourceName(service.Name), strings.ToUpper(port.Protocol), - string(port.Published), + port.Published, ) template.Resources[targetGroupName] = &elasticloadbalancingv2.TargetGroup{ Name: targetGroupName, diff --git a/ecs/pkg/compose/normalize.go b/ecs/pkg/compose/normalize.go index 861d146f..3e4809d1 100644 --- a/ecs/pkg/compose/normalize.go +++ b/ecs/pkg/compose/normalize.go @@ -23,6 +23,13 @@ func Normalize(model *types.Config) error { s.Networks = map[string]*types.ServiceNetworkConfig{"default": nil} } + for i, p := range s.Ports { + if p.Published == 0 { + p.Published = p.Target + s.Ports[i] = p + } + } + if s.LogDriver != "" { logrus.Warn("`log_driver` is deprecated. Use the `logging` attribute") if s.Logging == nil {