Closed null93 closed 2 months ago
It might be in pkg.go
where we Decode and Encode the template to resolve anchors. If we're sorting unexpectedly I'd think that's where it's happening. But I would expect a random order for mappings.
I can confirm that it happens after this line: https://github.com/aws-cloudformation/rain/blob/9038611cb314e7ce8d2f8464611d54f91319d893/cft/pkg/pkg.go#L137
Looks like if you change this line, then the order is preserved: https://github.com/aws-cloudformation/rain/blob/9038611cb314e7ce8d2f8464611d54f91319d893/cft/pkg/pkg.go#L126
Here is the very complex diff lol
--- var decoded interface{}
+++ var decoded yaml.Node
Ha ha nice. Honestly I would not have thought of that.
Will you PR this or do you want me to?
I can do it np
It seems like the
pkg
command is missing the--unsorted
flag. Here is an example of what I mean. Considertest.yaml
to have this content:When running
rain pkg test.yaml
it transforms it to this:Ideally there would be an option to not sort object keys (similar to the
fmt
command).My particular use case is that I store metadata in templates where the position of the keys really matter.
I took a quick look at the source code and couldn't pin point exactly where this would be specified. I can try to submit a PR for this with a little guidance.