Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
9154: chore: add new test case for esm-loading with a srcdir r=AaronFriel a=rawkode

# Description

Trying to use `ts-node` with the loader for top level async-await seems to fail if the Pulumi code is inside a `src` directory, a rather common pattern for Pulumi users.

I don't know why, but adding this test-case to hopefully help get some fixes

Fixes #9153

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11383: Feature - Short Node Label for Stack Graph r=AaronFriel a=krupaJari

# Description
This feature allows the user to opt for short node labels, i.e, only the resource name part of the URN instead of the full URN that is returned as the node label in the stack graph while using ```pulumi stack graph``` command. A flag named ```short-node-name``` is added to the ```pulumi stack graph``` command that enables this feature.

## Command Usage
Existing command : ```pulumi stack graph [file-name]```
Example : ```pulumi stack graph dev```
Output for dev :
strict digraph {
    Resource0 [label="urn:pulumi:dev::Test-Simple-Stack::pulumi:pulumi:Stack::Test-Simple-Stack-dev"];
    Resource1 [label="urn:pulumi:dev::Test-Simple-Stack::pulumi:providers:aws-native::default_0_40_2"];
    Resource2 [label="urn:pulumi:dev::Test-Simple-Stack::aws-native:s3:Bucket::my-bucket2"];
    Resource2 -> Resource0 [color = "#AA6639"];
    Resource3 [label="urn:pulumi:dev::Test-Simple-Stack::aws-native:s3:Bucket::my-bucket1"];
    Resource3 -> Resource0 [color = "#AA6639"];
}

Command for using the feature : ```pulumi stack graph [file-name] --short-node-name```

Fixes #10663

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11394: Pulumi destroy --remove command deletes stack config file r=AaronFriel a=heagma

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

`pulumi destroy --remove` command now will delete also the stack config file. This will be consistent with `pulumi stack rm`

Fixes #11198

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: David Flanagan <david@rawkode.com>
Co-authored-by: Krupa Jariwala <h20210067@goa.bits-pilani.ac.in>
Co-authored-by: hernandoagudelo <heagma@live.com>
  • Loading branch information
4 people committed Dec 13, 2022
4 parents 94ef784 + a8c3c51 + 829cae4 + 4910bce commit 53c4457
Show file tree
Hide file tree
Showing 10 changed files with 2,342 additions and 8 deletions.
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: cli
description: Adds a flag that allows user to set the node label as the resource name instead of full URN in the stack graph
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: cli
description: pulumi destroy --remove will now delete the stack config file
23 changes: 15 additions & 8 deletions pkg/cmd/pulumi/destroy.go
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"fmt"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -81,7 +82,7 @@ func newDestroyCmd() *cobra.Command {
"all of this stack's resources and associated state are deleted.\n" +
"\n" +
"The stack itself is not deleted. Use `pulumi stack rm` or the \n" +
"`--remove` flag to delete the stack.\n" +
"`--remove` flag to delete the stack and its config file.\n" +
"\n" +
"Warning: this command is generally irreversible and should be used with great care.",
Args: cmdArgs,
Expand Down Expand Up @@ -271,9 +272,15 @@ func newDestroyCmd() *cobra.Command {
_, err = s.Remove(ctx, false)
if err != nil {
return result.FromError(err)
} else if !jsonDisplay {
fmt.Printf("The resources in the stack have been deleted, and the history and " +
"configuration removed.\n")
}
// Remove also the stack config file.
if _, path, err := workspace.DetectProjectStackPath(s.Ref().Name().Q()); err == nil {
if err = os.Remove(path); err != nil && !os.IsNotExist(err) {
return result.FromError(err)
} else if !jsonDisplay {
fmt.Printf("The resources in the stack have been deleted, and the history and " +
"configuration removed.\n")
}
}
}
} else if res != nil && res.Error() == context.Canceled {
Expand All @@ -288,7 +295,7 @@ func newDestroyCmd() *cobra.Command {
"Print detailed debugging output during resource operations")
cmd.PersistentFlags().BoolVar(
&remove, "remove", false,
"Remove the stack after all resources in the stack have been deleted")
"Remove the stack and its config file after all resources in the stack have been deleted")
cmd.PersistentFlags().StringVarP(
&stack, "stack", "s", "",
"The name of the stack to operate on. Defaults to the current stack")
Expand Down Expand Up @@ -368,7 +375,7 @@ func newDestroyCmd() *cobra.Command {
return cmd
}

// seperateProtected returns a list or unprotected and protected resources respectively. This allows
// separateProtected returns a list or unprotected and protected resources respectively. This allows
// us to safely destroy all resources in the unprotected list without invalidating any resource in
// the protected list. Protection is contravarient: A < B where A: Protected => B: Protected, A < B
// where B: Protected !=> A: Protected.
Expand All @@ -385,7 +392,7 @@ func newDestroyCmd() *cobra.Command {
//
// We rely on the fact that `resources` is topologically sorted with respect to its dependencies.
// This function understands that providers live outside this topological sort.
func seperateProtected(resources []*resource.State) (
func separateProtected(resources []*resource.State) (
/*unprotected*/ []*resource.State /*protected*/, []*resource.State) {
dg := graph.NewDependencyGraph(resources)
transitiveProtected := graph.ResourceSet{}
Expand All @@ -409,7 +416,7 @@ func handleExcludeProtected(ctx context.Context, s backend.Stack) ([]string, int
} else if snapshot == nil {
return nil, 0, errors.New("Failed to find the stack snapshot. Are you in a stack?")
}
unprotected, protected := seperateProtected(snapshot.Resources)
unprotected, protected := separateProtected(snapshot.Resources)
targetUrns := make([]string, len(unprotected))
for i, r := range unprotected {
targetUrns[i] = string(r.URN)
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/pulumi/stack_graph.go
Expand Up @@ -40,6 +40,9 @@ var dependencyEdgeColor string
// The color of parent edges in the graph. Defaults to #AA6639, an orange.
var parentEdgeColor string

// Whether or not to return resource name as the node label for each node of the graph.
var shortNodeName bool

func newStackGraphCmd() *cobra.Command {
var stackName string

Expand Down Expand Up @@ -98,6 +101,8 @@ func newStackGraphCmd() *cobra.Command {
"Sets the color of dependency edges in the graph")
cmd.PersistentFlags().StringVar(&parentEdgeColor, "parent-edge-color", "#AA6639",
"Sets the color of parent edges in the graph")
cmd.PersistentFlags().BoolVar(&shortNodeName, "short-node-name", false,
"Sets the resource name as the node label for each node of the graph")
return cmd
}

Expand Down Expand Up @@ -178,6 +183,9 @@ func (vertex *dependencyVertex) Data() interface{} {
}

func (vertex *dependencyVertex) Label() string {
if shortNodeName {
return string(vertex.resource.URN.Name())
}
return string(vertex.resource.URN)
}

Expand Down
8 changes: 8 additions & 0 deletions tests/integration/nodejs/esm-srcdir-ts/Pulumi.yaml
@@ -0,0 +1,8 @@
name: esm-ts
runtime:
name: nodejs
options:
# See https://github.com/TypeStrong/ts-node/issues/1007
nodeargs: "--loader ts-node/esm --no-warnings"
description: Use ECMAScript modules for a TS program.
main: src/index.ts

0 comments on commit 53c4457

Please sign in to comment.