@@ -222,6 +222,27 @@ func (s sdk) DescribeStackEvents(ctx context.Context, stackID string) ([]*cloudf
222222 }
223223}
224224
225+ func (s sdk ) ListStackResources (ctx context.Context , name string ) ([]compose.StackResource , error ) {
226+ // FIXME handle pagination
227+ res , err := s .CF .ListStackResourcesWithContext (ctx , & cloudformation.ListStackResourcesInput {
228+ StackName : aws .String (name ),
229+ })
230+ if err != nil {
231+ return nil , err
232+ }
233+
234+ resources := []compose.StackResource {}
235+ for _ , r := range res .StackResourceSummaries {
236+ resources = append (resources , compose.StackResource {
237+ LogicalID : * r .LogicalResourceId ,
238+ Type : * r .ResourceType ,
239+ ARN : * r .PhysicalResourceId ,
240+ Status : * r .ResourceStatus ,
241+ })
242+ }
243+ return resources , nil
244+ }
245+
225246func (s sdk ) DeleteStack (ctx context.Context , name string ) error {
226247 logrus .Debug ("Delete CloudFormation stack" )
227248 _ , err := s .CF .DeleteStackWithContext (ctx , & cloudformation.DeleteStackInput {
@@ -270,7 +291,6 @@ func (s sdk) InspectSecret(ctx context.Context, id string) (compose.Secret, erro
270291}
271292
272293func (s sdk ) ListSecrets (ctx context.Context ) ([]compose.Secret , error ) {
273-
274294 logrus .Debug ("List secrets ..." )
275295 response , err := s .SM .ListSecrets (& secretsmanager.ListSecretsInput {})
276296 if err != nil {
@@ -336,18 +356,10 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer compose.LogConsu
336356 }
337357}
338358
339- func (s sdk ) DescribeServices (ctx context.Context , cluster string , project string ) ([]compose.ServiceStatus , error ) {
340- // TODO handle pagination
341- list , err := s .ECS .ListServicesWithContext (ctx , & ecs.ListServicesInput {
342- Cluster : aws .String (cluster ),
343- })
344- if err != nil {
345- return nil , err
346- }
347-
359+ func (s sdk ) DescribeServices (ctx context.Context , cluster string , arns []string ) ([]compose.ServiceStatus , error ) {
348360 services , err := s .ECS .DescribeServicesWithContext (ctx , & ecs.DescribeServicesInput {
349361 Cluster : aws .String (cluster ),
350- Services : list . ServiceArns ,
362+ Services : aws . StringSlice ( arns ) ,
351363 Include : aws .StringSlice ([]string {"TAGS" }),
352364 })
353365 if err != nil {
@@ -356,17 +368,13 @@ func (s sdk) DescribeServices(ctx context.Context, cluster string, project strin
356368 status := []compose.ServiceStatus {}
357369 for _ , service := range services .Services {
358370 var name string
359- var stack string
360371 for _ , t := range service .Tags {
361- switch * t .Key {
362- case compose .ProjectTag :
363- stack = * t .Value
364- case compose .ServiceTag :
372+ if * t .Key == compose .ServiceTag {
365373 name = * t .Value
366374 }
367375 }
368- if stack != project {
369- continue
376+ if name == "" {
377+ return nil , fmt . Errorf ( "service %s doesn't have a %s tag" , * service . ServiceArn , compose . ServiceTag )
370378 }
371379 status = append (status , compose.ServiceStatus {
372380 ID : * service .ServiceName ,
@@ -410,24 +418,24 @@ func (s sdk) GetPublicIPs(ctx context.Context, interfaces ...string) (map[string
410418 return publicIPs , nil
411419}
412420
413- func (s sdk ) LoadBalancerExists (ctx context.Context , name string ) (bool , error ) {
414- logrus .Debug ("Check if cluster was already created : " , name )
421+ func (s sdk ) LoadBalancerExists (ctx context.Context , arn string ) (bool , error ) {
422+ logrus .Debug ("Check if LoadBalancer exists : " , arn )
415423 lbs , err := s .ELB .DescribeLoadBalancersWithContext (ctx , & elbv2.DescribeLoadBalancersInput {
416- Names : []* string {aws .String (name )},
424+ LoadBalancerArns : []* string {aws .String (arn )},
417425 })
418426 if err != nil {
419427 return false , err
420428 }
421429 return len (lbs .LoadBalancers ) > 0 , nil
422430}
423431
424- func (s sdk ) GetLoadBalancerARN (ctx context.Context , name string ) (string , error ) {
425- logrus .Debug ("Check if cluster was already created : " , name )
432+ func (s sdk ) GetLoadBalancerURL (ctx context.Context , arn string ) (string , error ) {
433+ logrus .Debug ("Retrieve load balancer URL : " , arn )
426434 lbs , err := s .ELB .DescribeLoadBalancersWithContext (ctx , & elbv2.DescribeLoadBalancersInput {
427- Names : []* string {aws .String (name )},
435+ LoadBalancerArns : []* string {aws .String (arn )},
428436 })
429437 if err != nil {
430438 return "" , err
431439 }
432- return * lbs .LoadBalancers [0 ].LoadBalancerArn , nil
440+ return * lbs .LoadBalancers [0 ].DNSName , nil
433441}
0 commit comments