Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last status to pulumi stack ls output #10059

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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