Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

921 fix public subnet retrieval #1297

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions ecs/awsResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
return nil
}

func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Project, template *cloudformation.Template) {
func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Project, template *cloudformation.Template) error {
if r.loadBalancer != nil {
return
return nil
}
if allServices(project.Services, func(it types.ServiceConfig) bool {
return len(it.Ports) == 0
}) {
logrus.Debug("Application does not expose any public port, so no need for a LoadBalancer")
return
return nil
}

balancerType := getRequiredLoadBalancerType(project)
Expand All @@ -450,10 +450,21 @@ func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Proje
})
}

var publicSubNetIDs []string
for _, subNetID := range r.subnetsIDs() {
isPublic, err := b.aws.IsPublicSubnet(context.Background(), subNetID)
if err != nil {
return err
}
if isPublic {
publicSubNetIDs = append(publicSubNetIDs, subNetID)
}
}

template.Resources["LoadBalancer"] = &elasticloadbalancingv2.LoadBalancer{
Scheme: elbv2.LoadBalancerSchemeEnumInternetFacing,
SecurityGroups: securityGroups,
Subnets: r.subnetsIDs(),
Subnets: publicSubNetIDs,
Tags: projectTags(project),
Type: balancerType,
LoadBalancerAttributes: loadBalancerAttributes,
Expand All @@ -463,6 +474,7 @@ func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Proje
nameProperty: "LoadBalancerName",
}
r.loadBalancerType = balancerType
return nil
}

func (r *awsResources) getLoadBalancerSecurityGroups(project *types.Project) []string {
Expand Down