Does anyone know if the order of resources matter ...
# general
w
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
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
Thank you @little-cartoon-10569!
Oh, hm, it does appear it matters to some piece of code out there:
Copy code
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
Yeh as that error said, the order does matter in the state file. Resources need to be in dependency order.
w
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
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
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