Fix resource naming

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-06-04 16:20:21 +02:00
parent 37177e6d7a
commit fbb5bdac6e
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
2 changed files with 15 additions and 14 deletions

View File

@ -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 { func (c client) createLoadBalancer(project *compose.Project, template *cloudformation.Template) string {
loadBalancerType := "network" loadBalancerName := fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name))
loadBalancerName := fmt.Sprintf( template.Resources[loadBalancerName] = &elasticloadbalancingv2.LoadBalancer{
"%s%sLB",
strings.Title(project.Name),
strings.ToUpper(loadBalancerType[0:1]),
)
loadBalancer := &elasticloadbalancingv2.LoadBalancer{
Name: loadBalancerName, Name: loadBalancerName,
Scheme: "internet-facing", Scheme: elbv2.LoadBalancerSchemeEnumInternetFacing,
Subnets: []string{ Subnets: []string{
cloudformation.Ref(ParameterSubnet1Id), cloudformation.Ref(ParameterSubnet1Id),
cloudformation.Ref(ParameterSubnet2Id), cloudformation.Ref(ParameterSubnet2Id),
@ -191,18 +186,17 @@ func (c client) createLoadBalancer(project *compose.Project, template *cloudform
Value: project.Name, Value: project.Name,
}, },
}, },
Type: loadBalancerType, Type: elbv2.LoadBalancerTypeEnumNetwork,
} }
template.Resources[loadBalancerName] = loadBalancer
return loadBalancerName return loadBalancerName
} }
func (c client) createListener(service types.ServiceConfig, port types.ServicePortConfig, template *cloudformation.Template, targetGroupName string, loadBalancerName string, protocol string) string { func (c client) createListener(service types.ServiceConfig, port types.ServicePortConfig, template *cloudformation.Template, targetGroupName string, loadBalancerName string, protocol string) string {
listenerName := fmt.Sprintf( listenerName := fmt.Sprintf(
"%s%s%sListener", "%s%s%dListener",
normalizeResourceName(service.Name), normalizeResourceName(service.Name),
strings.ToUpper(port.Protocol), strings.ToUpper(port.Protocol),
string(port.Published), port.Published,
) )
//add listener to dependsOn //add listener to dependsOn
//https://stackoverflow.com/questions/53971873/the-target-group-does-not-have-an-associated-load-balancer //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 { func (c client) createTargetGroup(project *compose.Project, service types.ServiceConfig, port types.ServicePortConfig, template *cloudformation.Template, protocol string) string {
targetGroupName := fmt.Sprintf( targetGroupName := fmt.Sprintf(
"%s%s%sTargetGroup", "%s%s%dTargetGroup",
normalizeResourceName(service.Name), normalizeResourceName(service.Name),
strings.ToUpper(port.Protocol), strings.ToUpper(port.Protocol),
string(port.Published), port.Published,
) )
template.Resources[targetGroupName] = &elasticloadbalancingv2.TargetGroup{ template.Resources[targetGroupName] = &elasticloadbalancingv2.TargetGroup{
Name: targetGroupName, Name: targetGroupName,

View File

@ -23,6 +23,13 @@ func Normalize(model *types.Config) error {
s.Networks = map[string]*types.ServiceNetworkConfig{"default": nil} 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 != "" { if s.LogDriver != "" {
logrus.Warn("`log_driver` is deprecated. Use the `logging` attribute") logrus.Warn("`log_driver` is deprecated. Use the `logging` attribute")
if s.Logging == nil { if s.Logging == nil {