Skip to content

Commit

Permalink
Use service role from flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Apr 30, 2016
1 parent 295174d commit bbbb564
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/empire/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func newCloudFormationScheduler(db *empire.DB, c *cli.Context) (scheduler.Schedu
InternalSubnetIDs: c.StringSlice(FlagEC2SubnetsPrivate),
ExternalSubnetIDs: c.StringSlice(FlagEC2SubnetsPublic),
HostedZone: zone,
ServiceRole: c.String(FlagECSServiceRole),
LogConfiguration: logConfiguration,
}

Expand Down
7 changes: 7 additions & 0 deletions scheduler/cloudformation/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ import (
"golang.org/x/net/context"
)

// The identifier of the ECS Service resource in CloudFormation.
const ecsServiceType = "AWS::ECS::Service"

// errNoStack can be returned when there's no CloudFormation stack for a given
// app.
var errNoStack = errors.New("no stack for app found")

// cloudformationClient duck types the cloudformation.CloudFormation interface
// that we use.
type cloudformationClient interface {
CreateStack(*cloudformation.CreateStackInput) (*cloudformation.CreateStackOutput, error)
UpdateStack(*cloudformation.UpdateStackInput) (*cloudformation.UpdateStackOutput, error)
Expand All @@ -40,6 +45,7 @@ type cloudformationClient interface {
WaitUntilStackUpdateComplete(*cloudformation.DescribeStacksInput) error
}

// ecsClient duck types the ecs.ECS interface that we use.
type ecsClient interface {
ListTasksPages(input *ecs.ListTasksInput, fn func(p *ecs.ListTasksOutput, lastPage bool) (shouldContinue bool)) error
DescribeTaskDefinition(*ecs.DescribeTaskDefinitionInput) (*ecs.DescribeTaskDefinitionOutput, error)
Expand All @@ -50,6 +56,7 @@ type ecsClient interface {
UpdateService(*ecs.UpdateServiceInput) (*ecs.UpdateServiceOutput, error)
}

// s3Client duck types the s3.S3 interface that we use.
type s3Client interface {
PutObject(*s3.PutObjectInput) (*s3.PutObjectOutput, error)
}
Expand Down
14 changes: 4 additions & 10 deletions scheduler/cloudformation/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

const (

// For HTTP/HTTPS/TCP services, we allocate an ELB and map it's instance port to
// the container port. This is the port that processes within the container
// should bind to. Tihs value is also exposed to the container through the PORT
Expand Down Expand Up @@ -52,6 +51,9 @@ type EmpireTemplate struct {
// The Subnet IDs to assign when creating external load balancers.
ExternalSubnetIDs []string

// The name of the ECS Service IAM role.
ServiceRole string

LogConfiguration *ecs.LogConfiguration
}

Expand All @@ -77,12 +79,6 @@ func (t *EmpireTemplate) Build(app *scheduler.App) (interface{}, error) {
resources := map[string]interface{}{}
outputs := map[string]interface{}{}

serviceRole := "ServiceRole" // TODO: Build a service role.
parameters["ServiceRole"] = map[string]string{
"Type": "String",
"Default": "ecsServiceRole",
}

for _, p := range app.Processes {
cd := t.ContainerDefinition(p)

Expand Down Expand Up @@ -217,9 +213,7 @@ func (t *EmpireTemplate) Build(app *scheduler.App) (interface{}, error) {
},
}
if len(loadBalancers) > 0 {
serviceProperties["Role"] = map[string]string{
"Ref": serviceRole,
}
serviceProperties["Role"] = t.ServiceRole
}
resources[service] = map[string]interface{}{
"Type": "AWS::ECS::Service",
Expand Down

0 comments on commit bbbb564

Please sign in to comment.