diff --git a/ecs/pkg/amazon/roles.go b/ecs/pkg/amazon/roles.go index 3e8c5303a..bfa5026a2 100644 --- a/ecs/pkg/amazon/roles.go +++ b/ecs/pkg/amazon/roles.go @@ -13,7 +13,7 @@ const ECSTaskExecutionPolicy = "arn:aws:iam::aws:policy/service-role/AmazonECSTa var defaultTaskExecutionRole *string // GetEcsTaskExecutionRole retrieve the role ARN to apply for task execution -func (c client) GetEcsTaskExecutionRole(spec types.ServiceConfig) (*string, error) { +func (c client) GetEcsTaskExecutionRole(spec *types.ServiceConfig) (*string, error) { if arn, ok := spec.Extras["x-ecs-TaskExecutionRole"]; ok { s := arn.(string) return &s, nil diff --git a/ecs/pkg/amazon/up.go b/ecs/pkg/amazon/up.go index c8b4352b9..e54aae14f 100644 --- a/ecs/pkg/amazon/up.go +++ b/ecs/pkg/amazon/up.go @@ -10,6 +10,22 @@ import ( ) func (c *client) ComposeUp(project *compose.Project) error { + type mapping struct { + service *types.ServiceConfig + task *ecs.RegisterTaskDefinitionInput + } + mappings := []mapping{} + for _, service := range project.Services { + task, err := convert.Convert(project, service) + if err != nil { + return err + } + mappings = append(mappings, mapping{ + service: &service, + task: task, + }) + } + vpc, err := c.GetDefaultVPC() if err != nil { return err @@ -29,8 +45,8 @@ func (c *client) ComposeUp(project *compose.Project) error { return err } - for _, service := range project.Services { - _, err = c.CreateService(project, service, securityGroup, subnets, logGroup) + for _, mapping := range mappings { + _, err = c.CreateService(project, mapping.service, mapping.task, securityGroup, subnets, logGroup) if err != nil { return err } @@ -38,12 +54,7 @@ func (c *client) ComposeUp(project *compose.Project) error { return nil } -func (c *client) CreateService(project *compose.Project, service types.ServiceConfig, securityGroup *string, subnets []*string, logGroup *string) (*string, error) { - task, err := convert.Convert(project, service) - if err != nil { - return nil, err - } - +func (c *client) CreateService(project *compose.Project, service *types.ServiceConfig, task *ecs.RegisterTaskDefinitionInput, securityGroup *string, subnets []*string, logGroup *string) (*string, error) { role, err := c.GetEcsTaskExecutionRole(service) if err != nil { return nil, err