diff --git a/ecs/pkg/amazon/backend/cloudformation.go b/ecs/pkg/amazon/backend/cloudformation.go index bf8ecb3f8..3cd72360f 100644 --- a/ecs/pkg/amazon/backend/cloudformation.go +++ b/ecs/pkg/amazon/backend/cloudformation.go @@ -218,7 +218,9 @@ func getLoadBalancerSecurityGroups(project *types.Project, template *cloudformat } func createLoadBalancer(project *types.Project, template *cloudformation.Template) string { - loadBalancerName := fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name)) + + // load balancer names are limited to 32 characters total + loadBalancerName := fmt.Sprintf("%.32s", fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name))) // Create LoadBalancer if `ParameterLoadBalancerName` is not set template.Conditions["CreateLoadBalancer"] = cloudformation.Equals("", cloudformation.Ref(ParameterLoadBalancerARN)) diff --git a/ecs/pkg/amazon/backend/cloudformation_test.go b/ecs/pkg/amazon/backend/cloudformation_test.go index 8a03e0f58..d362a93fc 100644 --- a/ecs/pkg/amazon/backend/cloudformation_test.go +++ b/ecs/pkg/amazon/backend/cloudformation_test.go @@ -34,7 +34,7 @@ func TestSimpleWithOverrides(t *testing.T) { } func TestRolePolicy(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: foo: @@ -54,14 +54,14 @@ services: } func TestMapNetworksToSecurityGroups(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: test: image: hello_world networks: - - front-tier - - back-tier + - front-tier + - back-tier networks: front-tier: @@ -79,7 +79,7 @@ networks: } func TestLoadBalancerTypeApplication(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test123456789009876543211234567890", ` version: "3" services: test: @@ -89,12 +89,13 @@ services: `) lb := template.Resources["TestLoadBalancer"].(*elasticloadbalancingv2.LoadBalancer) assert.Check(t, lb != nil) + assert.Check(t, len(lb.Name) <= 32) assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumApplication) assert.Check(t, len(lb.SecurityGroups) > 0) } func TestServiceReplicas(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: test: @@ -108,7 +109,7 @@ services: } func TestLoadBalancerTypeNetwork(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: test: @@ -123,7 +124,7 @@ services: } func TestServiceMapping(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: test: @@ -163,7 +164,7 @@ func get(l []ecs.TaskDefinition_KeyValuePair, name string) string { } func TestResourcesHaveProjectTagSet(t *testing.T) { - template := convertYaml(t, ` + template := convertYaml(t, "test", ` version: "3" services: test: @@ -207,7 +208,7 @@ func load(t *testing.T, paths ...string) *types.Project { return project } -func convertYaml(t *testing.T, yaml string) *cloudformation.Template { +func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Template { dict, err := loader.ParseYAML([]byte(yaml)) assert.NilError(t, err) model, err := loader.Load(types.ConfigDetails{ diff --git a/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-with-overrides-conversion.golden b/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-with-overrides-conversion.golden index b2d1ffad8..0bc56cf99 100644 --- a/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-with-overrides-conversion.golden +++ b/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-with-overrides-conversion.golden @@ -260,10 +260,10 @@ }, "Type": "AWS::EC2::SecurityGroupIngress" }, - "TestSimpleWithOverridesLoadBalancer": { + "TestSimpleWithOverridesLoadBalan": { "Condition": "CreateLoadBalancer", "Properties": { - "Name": "TestSimpleWithOverridesLoadBalancer", + "Name": "TestSimpleWithOverridesLoadBalan", "Scheme": "internet-facing", "SecurityGroups": [ {