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

Add pulumi stack rename to allow you to rename a stack #2402

Closed
ellismg opened this issue Jan 29, 2019 · 7 comments
Closed

Add pulumi stack rename to allow you to rename a stack #2402

ellismg opened this issue Jan 29, 2019 · 7 comments
Assignees
Labels
p1 A bug severe enough to be the next item assigned to an engineer
Milestone

Comments

@ellismg
Copy link
Contributor

ellismg commented Jan 29, 2019

Now that we no longer require stack names to be unique across an organization it's natural to want to rename and existing stack you've created, since we previously recommended to use <project-name>-<unique-identifier> as a stack name, e.g (my-great-project-dev).

Today, renaming a stack is not a straightforward process. In addition to backend specific changes, the stack's name is also part of the URN of every resource we've created for a stack, so simply changing the name would cause the engine to believe that it needs to replace every resource.

We should add a pulumi stack rename command which should handle both backend specific logic to do the rename (e.g. in the service, updating some metadata about a stack name) and handle the updates needed to the existing checkpoint file such that URNs now have the new stack name.

@ellismg ellismg added the p1 A bug severe enough to be the next item assigned to an engineer label Jan 29, 2019
@ellismg ellismg added this to the 0.21 milestone Jan 29, 2019
@ellismg ellismg self-assigned this Jan 29, 2019
@chrsmith
Copy link
Contributor

Just as an FYI, I do not think we can 100% guarantee the operation is safe. So we want to add a warning by default, such as when trying to delete a stack that still has resources. (And --yes or --force to bypass automatically.)

Doing a find/replace across resource URNs will cover the majority of cases. But because you can get the stack's name at runtime via pulumi.getStack, it's possible to have the stack's name bleed into resource properties too. (And applying the same find/replace could lead to false-positives for a generic stack name.)

In practice I don't think this is going to be a problem, but I can imagine situations where renaming a stack could lead to trouble.

Alternatively, we may want to have the rename as a special kind of update. Where the command first previews the changes that would take place if the rename were to be made. That would allow you to see if there were any unexpected or problematic infrastructure changes, before proceeding.

@lukehoban
Copy link
Member

But because you can get the stack's name at runtime via pulumi.getStack, it's possible to have the stack's name bleed into resource properties too.

Actually the common case is even worse - pulumi.getStack() is frequently used as part of how the "name" of resources is generated, which means every resource would change identity and get recreated on the next update.

Alternatively, we may want to have the rename as a special kind of update.

This is an interesting idea...

@ellismg
Copy link
Contributor Author

ellismg commented Jan 31, 2019

Just as an FYI, I do not think we can 100% guarantee the operation is safe. So we want to add a warning by default, such as when trying to delete a stack that still has resources. (And --yes or --force to bypass automatically.)

I understand what you are saying here, but I wanted to point out that a rename operation by itself can be 100% safe, assuming that we just operate on the checkpoint file.

Now, it's true that if you the output of pulumi.getStack() as part of naming your resources, it's possible that the /next/ update after doing a rename would show "unexpected" changes as resources who's names depended on the output of pulumi.getStack() to name their resources now have new names, but if this was something you really didn't want to have happen, you could always rename the stack back to the old name.

Note we already have a version of this problem for any external observable state from update to update. For example, if you happened to use the value of a configuration variable to name a resource, then using pulumi config set could be considered a "dangerous" operation.

Alternatively, we may want to have the rename as a special kind of update.

@lukehoban and I were talking about this in person. I am not sure if it is a special kind of operation, but I could imagine value in pulumi stack rename showing you the output of a pulumi preview (with the engine configured to use the new stack name and the checkpoint it uses as the input state to have rewritten URNs) so you could see how such an change could impact a future update.

@lukehoban
Copy link
Member

Fixed with #2561.

@4c74356b41
Copy link

wait-wait, so I can create stacks with the same name. how does that work? how would i differentiate between those?

@lukehoban
Copy link
Member

wait-wait, so I can create stacks with the same name. how does that work? how would i differentiate between those?

You cannot create two stacks with the same fully qualified name. You can have two stacks named, e.g. dev, in different projects and/or organizations.

What specific comment here led you to think there was a potential concern here?

@4c74356b41
Copy link

i was just wondering how it works, thats it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1 A bug severe enough to be the next item assigned to an engineer
Projects
None yet
Development

No branches or pull requests

4 participants