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

pulumi about outputs the fully qualified stack reference #11387

Merged
merged 5 commits into from Nov 30, 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
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this prints like:

Current Stack: stack (fully qualified to org/proj/stack)

I wonder if the "fully qualified to" text is needed. I wonder if the non-qualified name is even needed if we're doing a text print, like we clearly want to keep it as is for the json case but maybe this should just always print the fully qualified name now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll just print out the FQN if it exists.

}

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