pulumi/pkg/cmd
Will Jones 02f6b99735
Introduce the `state repair` command (#17445)
Before performing any operation, Pulumi will by default check that the
state it is operating on is well-formed -- that all resources referenced
in the state (e.g. as dependencies) actually exist in that state, and
that resources are correctly ordered so that states that depend on
others appear after those that they require. If these well-formedness
checks fail, Pulumi will refuse to continue and report a "snapshot
integrity error".

Such errors are both frustrating and scary. Frustrating because it's
Pulumi's fault and now something has to be done before we can proceed.
Scary because the only options for proceeding are:

* Run another operation with `--disable-integrity-checking`, hoping that
the broken state a. won't affect the operation being run negatively and
b. that when the operation completes, it will have coincidentally
written a well-formed state.
* "State surgery" -- using tools such as `state delete` (likely with
`--disable-integrity-checking`) or `state export`/`state import` to
manually fix issues in the snapshot.

While `--disable-integrity-checking` offers a slightly better UX,
requiring less understanding of the underlying issue in order to fix it,
it is riskier, since it combines the act of repairing the state with
another operation. State surgery, on the other hand, is safer, but
requires a low-level understanding of how Pulumi operates. Moreover, it
can be tedious and error-prone, especially when the state is large.

This commit introduces the `state repair` command, which attempts to
combine the best bits of these two options. `state repair` automates
state surgery that in general we know to be safe -- sorting out-of-order
resources (#17403), and pruning dangling references (#17408). While
automatic repair may not always be possible, `state repair` should be
strictly an improvement: the command will leave valid snapshots
untouched and refuse to write snapshots that can't be repaired with
these operations.

Fixes #17446
2024-10-04 13:56:46 +00:00
..
pulumi Introduce the `state repair` command (#17445) 2024-10-04 13:56:46 +00:00