Skip to content

Commit

Permalink
Set Load Balancer internal/external per process instead of per applic…
Browse files Browse the repository at this point in the history
…ation

Introduces EMPIRE_X_EXPOSURE which needs to be either `internal` or `internet-facing` (kept AWS terminology here).

If that environment variable is not set, we fallback to the default selection via application (where you use `domain-add`).

Fixes remind101#1076
  • Loading branch information
iserko committed May 5, 2017
1 parent a0d4352 commit 5978efd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build
*.dump
*.key
*.cert
\#*\#
.\#*
49 changes: 32 additions & 17 deletions scheduler/cloudformation/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"log"
"reflect"
"regexp"
"sort"
Expand Down Expand Up @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5978efd

Please sign in to comment.