@@ -222,6 +222,27 @@ func (s sdk) DescribeStackEvents(ctx context.Context, stackID string) ([]*cloudf
222
222
}
223
223
}
224
224
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
+
225
246
func (s sdk ) DeleteStack (ctx context.Context , name string ) error {
226
247
logrus .Debug ("Delete CloudFormation stack" )
227
248
_ , err := s .CF .DeleteStackWithContext (ctx , & cloudformation.DeleteStackInput {
@@ -270,7 +291,6 @@ func (s sdk) InspectSecret(ctx context.Context, id string) (compose.Secret, erro
270
291
}
271
292
272
293
func (s sdk ) ListSecrets (ctx context.Context ) ([]compose.Secret , error ) {
273
-
274
294
logrus .Debug ("List secrets ..." )
275
295
response , err := s .SM .ListSecrets (& secretsmanager.ListSecretsInput {})
276
296
if err != nil {
@@ -336,18 +356,10 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer compose.LogConsu
336
356
}
337
357
}
338
358
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 ) {
348
360
services , err := s .ECS .DescribeServicesWithContext (ctx , & ecs.DescribeServicesInput {
349
361
Cluster : aws .String (cluster ),
350
- Services : list . ServiceArns ,
362
+ Services : aws . StringSlice ( arns ) ,
351
363
Include : aws .StringSlice ([]string {"TAGS" }),
352
364
})
353
365
if err != nil {
@@ -356,17 +368,13 @@ func (s sdk) DescribeServices(ctx context.Context, cluster string, project strin
356
368
status := []compose.ServiceStatus {}
357
369
for _ , service := range services .Services {
358
370
var name string
359
- var stack string
360
371
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 {
365
373
name = * t .Value
366
374
}
367
375
}
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 )
370
378
}
371
379
status = append (status , compose.ServiceStatus {
372
380
ID : * service .ServiceName ,
@@ -410,24 +418,24 @@ func (s sdk) GetPublicIPs(ctx context.Context, interfaces ...string) (map[string
410
418
return publicIPs , nil
411
419
}
412
420
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 )
415
423
lbs , err := s .ELB .DescribeLoadBalancersWithContext (ctx , & elbv2.DescribeLoadBalancersInput {
416
- Names : []* string {aws .String (name )},
424
+ LoadBalancerArns : []* string {aws .String (arn )},
417
425
})
418
426
if err != nil {
419
427
return false , err
420
428
}
421
429
return len (lbs .LoadBalancers ) > 0 , nil
422
430
}
423
431
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 )
426
434
lbs , err := s .ELB .DescribeLoadBalancersWithContext (ctx , & elbv2.DescribeLoadBalancersInput {
427
- Names : []* string {aws .String (name )},
435
+ LoadBalancerArns : []* string {aws .String (arn )},
428
436
})
429
437
if err != nil {
430
438
return "" , err
431
439
}
432
- return * lbs .LoadBalancers [0 ].LoadBalancerArn , nil
440
+ return * lbs .LoadBalancers [0 ].DNSName , nil
433
441
}
0 commit comments