From 8b2912f7a242f8055a5badf43ded2dcf6cc24e11 Mon Sep 17 00:00:00 2001 From: Austin Drenski Date: Wed, 8 Nov 2023 17:26:43 -0500 Subject: [PATCH] Fallback to user-provided cluster from metadata (#2) Fixes: #19, docker/compose-cli#1084, docker/compose-cli#2086 --- ecs/aws.go | 1 + ecs/list.go | 6 ++++++ ecs/sdk.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/ecs/aws.go b/ecs/aws.go index 5c08c8fd..f6bd1983 100644 --- a/ecs/aws.go +++ b/ecs/aws.go @@ -51,6 +51,7 @@ type API interface { GetStackID(ctx context.Context, name string) (string, error) ListStacks(ctx context.Context) ([]api.Stack, error) GetStackClusterID(ctx context.Context, stack string) (string, error) + GetStackMetadataClusterID(ctx context.Context, stack string) (string, error) GetServiceTaskDefinition(ctx context.Context, cluster string, serviceArns []string) (map[string]string, error) ListStackServices(ctx context.Context, stack string) ([]string, error) GetServiceTasks(ctx context.Context, cluster string, service string, stopped bool) ([]*ecs.Task, error) diff --git a/ecs/list.go b/ecs/list.go index 9c3a4fc1..349e7e82 100644 --- a/ecs/list.go +++ b/ecs/list.go @@ -71,6 +71,12 @@ func (b *ComposeECS) checkStackState(ctx context.Context, name string) error { svcNames[r.ARN] = r.LogicalID } } + if len(cluster) == 0 { + cluster, err = b.aws.GetStackMetadataClusterID(ctx, name) + if err != nil { + return err + } + } if len(svcArns) == 0 { return nil } diff --git a/ecs/sdk.go b/ecs/sdk.go index 24388ef2..953596c6 100644 --- a/ecs/sdk.go +++ b/ecs/sdk.go @@ -505,6 +505,10 @@ func (s sdk) GetStackClusterID(ctx context.Context, stack string) (string, error token = response.NextToken } // stack is using user-provided cluster + return s.GetStackMetadataClusterID(ctx, stack) +} + +func (s sdk) GetStackMetadataClusterID(ctx context.Context, stack string) (string, error) { res, err := s.CF.GetTemplateSummaryWithContext(ctx, &cloudformation.GetTemplateSummaryInput{ StackName: aws.String(stack), })