Skip to content

Commit

Permalink
Merge #11387
Browse files Browse the repository at this point in the history
11387: `pulumi about` outputs the fully qualified stack reference r=iwahbe a=AaronFriel

Resolves #11386

```shell
$ pulumi about 
# current output would go here until after this line:
Current Stack: dev

Fully qualified stack name: Fully qualified stack name: friel/tmp.knCczy5IiO/dev

Found no resources associated with dev

Found no pending operations associated with dev
# and regular output
```

```shell
$ pulumi about --json | jq '.currentStack.fullyQualifiedName'
"friel/tmp.knCczy5IiO/dev"
```

When there is no valid stack, the `currentStack` value is `null`. 

Due to an existing bug, when the backend is filestate the `currentStack` value is `null`. It appears on filestate backends we do not render the current stack.

Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
Co-authored-by: Ian Wahbe <ian@wahbe.com>
  • Loading branch information
3 people committed Nov 30, 2022
2 parents 7afac76 + 23608c2 commit beaf07d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: cli/about
description: Add fully qualified stack name to current stack.
3 changes: 3 additions & 0 deletions pkg/backend/backend.go
Expand Up @@ -75,6 +75,9 @@ type StackReference interface {
// name may not uniquely identify the stack (e.g. the cloud backend embeds owner information in the StackReference
// but that information is not part of the StackName() we pass to the engine.
Name() tokens.Name

// Fully qualified name of the stack.
FullyQualifiedName() tokens.QName
}

// PolicyPackReference is an opaque type that refers to a PolicyPack managed by a backend. The CLI
Expand Down
4 changes: 4 additions & 0 deletions pkg/backend/filestate/backend.go
Expand Up @@ -99,6 +99,10 @@ func (r localBackendReference) Name() tokens.Name {
return r.name
}

func (r localBackendReference) FullyQualifiedName() tokens.QName {
return r.Name().Q()
}

func IsFileStateBackendURL(urlstr string) bool {
u, err := url.Parse(urlstr)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/backend/httpstate/stack.go
Expand Up @@ -74,6 +74,10 @@ func (c cloudBackendReference) Name() tokens.Name {
return c.name
}

func (c cloudBackendReference) FullyQualifiedName() tokens.QName {
return tokens.IntoQName(fmt.Sprintf("%v/%v/%v", c.owner, c.project, c.name.String()))
}

// cloudStack is a cloud stack descriptor.
type cloudStack struct {
// ref is the stack's unique name.
Expand Down
20 changes: 13 additions & 7 deletions pkg/cmd/pulumi/about.go
Expand Up @@ -330,9 +330,10 @@ func (b backendAbout) String() string {
}

type currentStackAbout struct {
Name string `json:"name"`
Resources []aboutState `json:"resources"`
PendingOps []aboutState `json:"pendingOps"`
Name string `json:"name"`
FullyQualifiedName string `json:"fullyQualifiedName"`
Resources []aboutState `json:"resources"`
PendingOps []aboutState `json:"pendingOps"`
}

type aboutState struct {
Expand Down Expand Up @@ -386,9 +387,10 @@ func getCurrentStackAbout(ctx context.Context, b backend.Backend, selectedStack
}
}
return currentStackAbout{
Name: name,
Resources: aboutResources,
PendingOps: aboutPending,
Name: name,
FullyQualifiedName: stack.Ref().FullyQualifiedName().String(),
Resources: aboutResources,
PendingOps: aboutPending,
}, nil
}

Expand Down Expand Up @@ -423,7 +425,11 @@ func (current currentStackAbout) String() string {
Rows: rows,
}.String() + "\n"
}
return fmt.Sprintf("Current Stack: %s\n\n%s\n%s", current.Name, resources, pending)
stackName := current.Name
if current.FullyQualifiedName != "" {
stackName = current.FullyQualifiedName
}
return fmt.Sprintf("Current Stack: %s\n\n%s\n%s", stackName, resources, pending)
}

func simpleTableRows(arr [][]string) []cmdutil.TableRow {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pulumi/stack_ls_test.go
Expand Up @@ -82,6 +82,10 @@ func (msr *mockStackReference) Name() tokens.Name {
return tokens.Name(msr.name)
}

func (msr *mockStackReference) FullyQualifiedName() tokens.QName {
return msr.Name().Q()
}

func (msr *mockStackReference) String() string {
return msr.name
}
Expand Down

0 comments on commit beaf07d

Please sign in to comment.