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

fix pulumi new creates new project when stack reference project name and project name don't match #13250

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

dixler
Copy link
Contributor

@dixler dixler commented Jun 22, 2023

Description

pulumi new --stack and --name check that the project name matches before creating a new project.

Fixes #13248

Checklist

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Jun 22, 2023

Changelog

[uncommitted] (2023-06-29)

Bug Fixes

  • [cli/new] When providing a --stack and --name to pulumi new, the project names must match before creating Pulumi.yaml.
    #13250

@dixler dixler changed the title Dixler/13248/pulumi new project contradiction fix pulumi new creates new project when stack reference project name and project name don't match Jun 22, 2023
@dixler dixler marked this pull request as ready for review June 22, 2023 18:22
@dixler dixler requested a review from a team June 22, 2023 18:23
@@ -82,6 +82,11 @@ func runNew(ctx context.Context, args newArgs) error {
IsInteractive: args.interactive,
}

// Check project name and stack reference project name are the same.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should just make --stack have to be a plain name. I.e. validate it's a tokens.Name not a QName. I realize the scuppers the idea of using a fully qualified ref here to set the org, but I think I'm coming around to preferring your idea of adding an "--org" flag to override that. Hell maybe we could even add a prompt as part of the new workflow to give users the choice for org if they haven't set that flag (The backend can suggest which orgs the user has access to, and if they only have one we can just default select it and not prompt so most users wouldn't see any difference here).

This might also interact with your other PR (#13234) so if we like this approach I'd put that PR on a short hold to make this change first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is sensible.

Copy link
Member

Choose a reason for hiding this comment

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

This generally sounds reasonable to me, but we should discuss a concrete proposal in ideation.

Though, I don't think we can get away with forcing --stack to be only a plain name, because it can be a fully qualified name already today. As such, this change to do this validation looks reasonable to me.

Copy link
Member

Choose a reason for hiding this comment

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

Though, I don't think we can get away with forcing --stack to be only a plain name, because it can be a fully qualified name already today.

I think we've only run into problems trying to pass a ref here internally, I haven't seen any users doing this? I suspect it would be OK to do this.

As such, this change to do this validation looks reasonable to me.

If we are going to allow a ref here then yes we should validate the project matches but we should do that by calling the backends ParseStackReference method and checking the refs Project() property. Not by doing the string split currently proposed in this change.
That Parse will also cover a lot of other validation of the ref like checking its actually a valid name.

@dixler dixler force-pushed the dixler/13248/pulumi-new-project-contradiction branch from e1fa860 to 8135649 Compare June 26, 2023 17:45
@dixler dixler requested a review from Frassle June 26, 2023 17:46
Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable change.
Minus the minor comments, would appreciate comments on some of the key behavioral bits.
And we should maybe tweak the error message a bit, WDYT?

pkg/backend/mock.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/new.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/new.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/new.go Outdated Show resolved Hide resolved
pkg/cmd/pulumi/new.go Outdated Show resolved Hide resolved
Comment on lines +837 to +878
valid: false,
},
{
projectName: "",
stackRef: "org/foo/dev",
valid: true,
},
{
projectName: "foo",
stackRef: "",
valid: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: can omit zero-value fields.

Suggested change
valid: false,
},
{
projectName: "",
stackRef: "org/foo/dev",
valid: true,
},
{
projectName: "foo",
stackRef: "",
valid: true,
},
},
{
stackRef: "org/foo/dev",
valid: true,
},
{
projectName: "foo",
valid: true,
},

Copy link
Contributor Author

@dixler dixler Jun 27, 2023

Choose a reason for hiding this comment

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

We could, but I feel that it would be nicer to show this implicit detail since it's a list and I imagine it's easier to chunk if they all have the same structure.

pkg/cmd/pulumi/new_test.go Outdated Show resolved Hide resolved
@dixler dixler force-pushed the dixler/13248/pulumi-new-project-contradiction branch 2 times, most recently from d96d39d to d03d607 Compare June 27, 2023 18:55
@dixler dixler requested a review from justinvp June 28, 2023 16:52
}

// Catch the case where the user has specified a fully qualified stack reference.
if strings.Count(stackName, "/") == 2 {
Copy link
Member

Choose a reason for hiding this comment

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

No need to check for if there's two "/" here, just let the backend do the parse.

valid: true,
},
}
b, err := currentBackend(context.Background(), nil, display.Options{})
Copy link
Member

Choose a reason for hiding this comment

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

This should not be testing against the real backend.

@dixler dixler requested a review from Frassle June 29, 2023 19:33
@dixler dixler force-pushed the dixler/13248/pulumi-new-project-contradiction branch 2 times, most recently from c69227f to d6651d6 Compare June 29, 2023 22:34
@Frassle Frassle dismissed their stale review June 30, 2023 07:43

Assuming Justin's checked my comments and I'm off today

@dixler
Copy link
Contributor Author

dixler commented Jun 30, 2023

bors merge

bors bot added a commit that referenced this pull request Jun 30, 2023
13250: fix `pulumi new` creates new project when stack reference project name and project name don't match r=dixler a=dixler

<!--- 
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 new` `--stack` and `--name` check that the project name matches before creating a new project.

Fixes #13248 

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] 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 Cloud,
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 Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Kyle Dixler <kyle@pulumi.com>
bors bot added a commit that referenced this pull request Jun 30, 2023
13250: fix `pulumi new` creates new project when stack reference project name and project name don't match r=dixler a=dixler

<!--- 
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 new` `--stack` and `--name` check that the project name matches before creating a new project.

Fixes #13248 

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] 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 Cloud,
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 Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Kyle Dixler <kyle@pulumi.com>
@dixler
Copy link
Contributor Author

dixler commented Jun 30, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 30, 2023

Already running a review

@bors
Copy link
Contributor

bors bot commented Jun 30, 2023

Build failed:

@dixler
Copy link
Contributor Author

dixler commented Jun 30, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 30, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 97bc12a into master Jun 30, 2023
48 checks passed
@bors bors bot deleted the dixler/13248/pulumi-new-project-contradiction branch June 30, 2023 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pulumi new --stack and --name may clash.
5 participants