Skip to content

Commit

Permalink
Add last status to pulumi stack ls output (#10059)
Browse files Browse the repository at this point in the history
  • Loading branch information
aq17 committed Jul 12, 2022
1 parent 4e19e95 commit 764a61c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- [cli] Display outputs during the very first preview.
[#10031](https://github.com/pulumi/pulumi/pull/10031)

- [cli] Add Last Status to `pulumi stack ls` output.
[#6148](https://github.com/pulumi/pulumi/pull/6148)
- [cli] Allow pulumi `destroy -s <stack>` if not in a Pulumi project dir
[#9918](https://github.com/pulumi/pulumi/pull/9918)

Expand Down
21 changes: 19 additions & 2 deletions pkg/cmd/pulumi/stack_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type stackSummaryJSON struct {
Current bool `json:"current"`
LastUpdate string `json:"lastUpdate,omitempty"`
UpdateInProgress bool `json:"updateInProgress"`
LastStatus string `json:"lastStatus,omitempty"`
ResourceCount *int `json:"resourceCount,omitempty"`
URL string `json:"url,omitempty"`
}
Expand All @@ -216,6 +217,11 @@ func formatStackSummariesJSON(b backend.Backend, currentStack string, stackSumma
}

if httpBackend, ok := b.(httpstate.Backend); ok {
if stackHistory, err := httpBackend.GetHistory(commandContext(), summary.Name(), 1, 1); err == nil {
if len(stackHistory) > 0 {
summaryJSON.LastStatus = string(stackHistory[0].Result)
}
}
if consoleURL, err := httpBackend.StackConsoleURL(summary.Name()); err == nil {
summaryJSON.URL = consoleURL
}
Expand All @@ -231,7 +237,7 @@ func formatStackSummariesConsole(b backend.Backend, currentStack string, stackSu
_, showURLColumn := b.(httpstate.Backend)

// Header string and formatting options to align columns.
headers := []string{"NAME", "LAST UPDATE", "RESOURCE COUNT"}
headers := []string{"NAME", "LAST UPDATE", "LAST STATUS", "RESOURCE COUNT"}
if showURLColumn {
headers = append(headers, "URL")
}
Expand All @@ -257,14 +263,25 @@ func formatStackSummariesConsole(b backend.Backend, currentStack string, stackSu
}
}

// Last status column
lastStatus := none
if httpBackend, ok := b.(httpstate.Backend); ok {
if stackHistory, err := httpBackend.GetHistory(commandContext(), summary.Name(),
len(stackSummaries), 1); err == nil {
if len(stackHistory) > 0 {
lastStatus = string(stackHistory[0].Result)
}
}
}

// ResourceCount column
resourceCount := none
if stackResourceCount := summary.ResourceCount(); stackResourceCount != nil {
resourceCount = strconv.Itoa(*stackResourceCount)
}

// Render the columns.
columns := []string{name, lastUpdate, resourceCount}
columns := []string{name, lastUpdate, lastStatus, resourceCount}
if showURLColumn {
url := none
if httpBackend, ok := b.(httpstate.Backend); ok {
Expand Down

0 comments on commit 764a61c

Please sign in to comment.