-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Don't bail at preview when a protected resource needs replacement #15969
Don't bail at preview when a protected resource needs replacement #15969
Conversation
Changelog[uncommitted] (2024-04-18)Bug Fixes
|
expectedMessage = "<{%reset%}>unable to replace resource \"urn:pulumi:test::test::pkgA:m:typA::resA\"\n" + | ||
"as it is currently marked for protection. To unprotect the resource, remove the `protect` flag from " + | ||
"the resource in your Pulumi program and run `pulumi up`<{%reset%}>\n" | ||
ins = resource.NewPropertyMapFromMap(map[string]interface{}{ | ||
"foo": "baz", | ||
}) | ||
_, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, true, p.BackendClient, validate) | ||
assert.Error(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use assert.Error, use ErrorContains or similar to check its actually the error expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that already happens with expectedMessage
. I'll double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expectedMessage is checking the diagnostic gets output, but we also want to check that the error is the bail error we expect matching up to that, not some other random error that might get hit in the system. We've had tests before that we thought we're testing for one error case just using asset.Error
and when the system slightly changed to a different error the tests didn't catch it but users noticed.
@@ -1034,7 +1034,9 @@ func (sg *stepGenerator) generateStepsFromDiff( | |||
"program and run `pulumi up`", urn) | |||
sg.deployment.ctx.Diag.Errorf(diag.StreamMessage(urn, message, 0)) | |||
sg.sawError = true | |||
return nil, result.BailErrorf(message) | |||
if !sg.deployment.preview { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth a comment why we have to error here if not preview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment. I'm not exactly sure we need to bail during update. Honestly, I'm making the smallest possible change to solve the preview issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't bail and we're doing a create before delete replacement we'll execute the create before getting to the delete error. State will still be tracking both resources but it's an awkward state to cleanup from.
Description
Don't bail at preview when a protected resource needs replacement, just error. This makes sure that users can see the actual diff that causes the replacement.
Fixes #5027
Before:
After:
Checklist
make tidy
to update any new dependenciesmake lint
to verify my code passes the lint checkgofumpt
make changelog
and committed thechangelog/pending/<file>
documenting my change