https://pulumi.com logo
Title
w

wet-soccer-72485

04/20/2022, 1:35 AM
Does anyone know if the order of resources matter in the state file? I’m comparing state JSONs over time, and I’m finding that the resource order seems to change at random, not just when there are meaningful differences. It makes it harder to tell exactly what has changed between what I’m looking at. (I may implement my own sorting, if just to diagnose my issue, even if I don’t import the JSONs back.)
l

little-cartoon-10569

04/20/2022, 4:02 AM
No it doesn't matter, all that matters is the top-level element that they're in. You can use jq to re-order items, so long as they maintain the same nesting.
1
w

wet-soccer-72485

04/20/2022, 4:04 AM
Thank you @little-cartoon-10569!
Oh, hm, it does appear it matters to some piece of code out there:
CommandError: code: 255
   stdout: 
   stderr: I0420 05:17:09.057488   11447 sink.go:155] defaultSink::Error(error: 2 errors occurred:
      1) state file contains errors: child resource urn:yzx's parent urn:yabc comes after it
      2) importing this file could be dangerous; rerun with --force to proceed anyway)
  error: 2 errors occurred:
      1) state file contains errors: child resource x's parent y comes after it
      2) importing this file could be dangerous; rerun with --force to proceed anyway
I’m running through the automation API (#automation-api) so I’m just going to edit
node_modules/@pulumi/pulumi/automation/cmd.js
to add the
--force
flag manually
e

echoing-dinner-19531

04/20/2022, 12:02 PM
Yeh as that error said, the order does matter in the state file. Resources need to be in dependency order.
w

wet-soccer-72485

04/21/2022, 7:56 PM
Yes, thank you @echoing-dinner-19531. You could see my confusion based on what @little-cartoon-10569 had said.
I may open a ticket to sort states as much as possible by their URNs to allow for easier visual inspection & (importantly) diffing
l

little-cartoon-10569

04/21/2022, 10:56 PM
Sorry about that. I'd done it a few times and had no problems, but obviously that was because there were no dependencies between the things that had been re-ordered. Mea culpa!
w

wet-soccer-72485

04/22/2022, 8:41 PM
Thats okay!
I added some text to the docs page to hopefully help comer-behinds find the answer to this question going forward: https://github.com/pulumi/docs/pull/7393