mirror of https://github.com/pulumi/pulumi.git
6b4805672c
When using `--target` to target specific resources during an update, we use the list of targets to decide which steps to generate given a set of resource registrations. Specifically: * If the registration event names a resource that is targeted, we process it as usual. * If the registration event names a resource that _is not_ targeted, we emit a `SameStep` for it. In the latter case, the emission of a `SameStep` means that the old state for the resource will be copied across to the new state. This is the desired behaviour -- the resource was not targeted and so the new state should contain the resource exactly as it was prior to the update. However, this presents a problem if the old state has references to resources that either will not appear in the new state, or will appear in the wrong place. Consider the following program in TypeScript-esque pseudocode: ```typescript const a = new Resource("a") const b = new Resource("b", { dependency: a }) const c = new Resource("c") ``` Here, `b` depends on `a`, while `a` and `c` have no dependencies. We run this program without specifying targets and obtain a state containing `a`, `b` and `c`, with `a` appearing before `b` due to `b`'s dependency on `a`. We now modify the program as follows: ```typescript const b = new Resource("b") const c = new Resource("c") ``` `a` has been removed from the program and consequently `b` no longer depends on it. We once more run the program, this time with a `--target` of `c`. That is to say, neither `a` nor `b` is targeted. The execution proceeds as follows: * `a` is not in the program, so no `RegisterResourceEvent` will be emitted and processed for it. * `b` is in the program, but it is not targeted. Its `RegisterResourceEvent` will be turned into a `SameStep` and `b`'s _old state will be copied as-is to the new state_. * `c` is in the program and is targeted. It will be processed as normal. At the end of execution when we come to write the snapshot, we take the following actions: * We first write the processed resources: `b`'s old state and `c`'s new state. * We then copy over any unprocessed resources from the base (previous) snapshot. This includes `a` (which is again desirable since its deletion should not be processed due to it not being targeted). Our snapshot is now not topologically sorted and thus invalid: `b` has a dependency on `a`, but `a` appears after it. Presently this bug will manifest irrespective of the nature of the dependency: `.Dependencies`, `.PropertyDependencies` and `.DeletedWith` are all affected. This commit fixes this issue by traversing all untargeted resource dependency relationships and ensuring that `SameStep`s (or better if they have been targeted) are emitted before emitting the depending resource's `SameStep`. * Fixes #16052 * Fixes #15959 |
||
---|---|---|
.. | ||
0 | ||
1 |