Skip to content

Commit 9708723

Browse files
authored
Merge pull request #615 from DefangLabs/lio-fix-cd-ls
show pending operations in cd ls
2 parents 084b8d4 + 6cf70e6 commit 9708723

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/pkg/cli/client/byoc/aws/byoc.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/base64"
7+
"encoding/json"
78
"errors"
89
"fmt"
910
"io"
@@ -714,6 +715,43 @@ func (b *ByocAws) BootstrapList(ctx context.Context) ([]string, error) {
714715
}
715716
// Cut off the prefix and the .json suffix
716717
stack := (*obj.Key)[len(prefix) : len(*obj.Key)-5]
718+
// Check the contents of the JSON file, because the size is not a reliable indicator of a valid stack
719+
objOutput, err := s3client.GetObject(ctx, &s3.GetObjectInput{
720+
Bucket: &bucketName,
721+
Key: obj.Key,
722+
})
723+
if err != nil {
724+
term.Debugf("Failed to get Pulumi state object %q: %v", *obj.Key, err)
725+
} else {
726+
defer objOutput.Body.Close()
727+
var state struct {
728+
Version int `json:"version"`
729+
Checkpoint struct {
730+
// Stack string `json:"stack"` TODO: could use this instead of deriving the stack name from the key
731+
Latest struct {
732+
Resources []struct{} `json:"resources,omitempty"`
733+
PendingOperations []struct {
734+
Resource struct {
735+
Urn string `json:"urn"`
736+
}
737+
} `json:"pending_operations,omitempty"`
738+
}
739+
}
740+
}
741+
if err := json.NewDecoder(objOutput.Body).Decode(&state); err != nil {
742+
term.Debugf("Failed to decode Pulumi state %q: %v", *obj.Key, err)
743+
} else if state.Version != 3 {
744+
term.Debug("Skipping Pulumi state with version", state.Version)
745+
} else if len(state.Checkpoint.Latest.PendingOperations) > 0 {
746+
for _, op := range state.Checkpoint.Latest.PendingOperations {
747+
parts := strings.Split(op.Resource.Urn, "::") // prefix::project::type::resource => urn:provider:stack::project::plugin:file:class::name
748+
stack += fmt.Sprintf(" (pending %q)", parts[3])
749+
}
750+
} else if len(state.Checkpoint.Latest.Resources) == 0 {
751+
continue // skip: no resources and no pending operations
752+
}
753+
}
754+
717755
stacks = append(stacks, stack)
718756
}
719757
return stacks, nil

0 commit comments

Comments
 (0)