diff --git a/.gitignore b/.gitignore index 2a8d72219..ebcf9a945 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ build *.dump *.key *.cert +\#*\# +.\#* diff --git a/scheduler/cloudformation/template.go b/scheduler/cloudformation/template.go index 484d1f078..a6bd5a5db 100644 --- a/scheduler/cloudformation/template.go +++ b/scheduler/cloudformation/template.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "log" "reflect" "regexp" "sort" @@ -36,6 +37,20 @@ const ( applicationLoadBalancer = "alb" ) +const ( + schemeInternal = "internal" + schemeExternal = "internet-facing" + + defaultConnectionDrainingTimeout int64 = 30 + defaultCNAMETTL = 60 + + runTaskFunction = "RunTaskFunction" + + appEnvironment = "AppEnvironment" + + restartLabel = "cloudformation.restart-key" +) + // Returns the type of load balancer that should be used (ELB/ALB). func loadBalancerType(app *twelvefactor.Manifest, process *twelvefactor.Process) string { check := []string{ @@ -54,6 +69,20 @@ func loadBalancerType(app *twelvefactor.Manifest, process *twelvefactor.Process) return classicLoadBalancer } +func schemeExposure(app *twelvefactor.Manifest, process *twelvefactor.Process) string { + env := twelvefactor.Env(app, process) + if v, ok := env["EMPIRE_X_EXPOSURE"]; ok { + if v == schemeExternal { + return v + } + } + // For backwards compatibility we check the application setting via process + if process.Exposure.External { + return schemeExternal + } + return schemeInternal +} + // Returns the name of the CloudFormation resource that should be used to create // custom task definitions. func taskDefinitionResourceType(app *twelvefactor.Manifest) string { @@ -89,20 +118,6 @@ func taskRoleArn(app *twelvefactor.Manifest) *string { return nil } -const ( - schemeInternal = "internal" - schemeExternal = "internet-facing" - - defaultConnectionDrainingTimeout int64 = 30 - defaultCNAMETTL = 60 - - runTaskFunction = "RunTaskFunction" - - appEnvironment = "AppEnvironment" - - restartLabel = "cloudformation.restart-key" -) - // This implements the Template interface to create a suitable CloudFormation // template for an Empire app. type EmpireTemplate struct { @@ -400,12 +415,12 @@ func (t *EmpireTemplate) addService(tmpl *troposphere.Template, app *twelvefacto var serviceDependencies []string loadBalancers := []map[string]interface{}{} if p.Exposure != nil { - scheme := schemeInternal sg := t.InternalSecurityGroupID subnets := t.InternalSubnetIDs - if p.Exposure.External { - scheme = schemeExternal + scheme := schemeExposure(app, p) + + if scheme == schemeExternal { sg = t.ExternalSecurityGroupID subnets = t.ExternalSubnetIDs }