Skip to content

Commit

Permalink
Fallback to user-provided cluster from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
austindrenski committed Nov 8, 2023
1 parent 3da16ae commit 91b0504
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
dist/
/.idea/
/.vscode/
1 change: 1 addition & 0 deletions ecs/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions ecs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions ecs/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
Expand Down

0 comments on commit 91b0504

Please sign in to comment.