Closed ericzbeard closed 7 months ago
The handleScalar function in cft/format/json.go
looks at each node independently, without knowledge of the rest of the template.
We could fix the code to handle anchors better for JSON conversion, but we will not be able to round-trip it, since JSON doesn't have an equivalent to anchors. I assume that would be ok for any use case where someone wants to use a YAML feature not supported by CloudFormation.
I wonder if the fmt
command should resolve the anchors and get rid of them for YAML formatting as well.
Our company is moving to rain
as a replacement for cfn-flip
since it is no longer actively maintained. cfn-flip
supported anchors, so it would be great if rain
could maintain that support. I hope this enhancement will be considered.
I wonder if the
fmt
command should resolve the anchors and get rid of them for YAML formatting as well.
I don't know about this one. It makes sense for the anchors to be resolved when transforming to JSON, but resolving them when all you wanted to do was format your template may catch users unaware. I think it would be fine if the rain fmt
command is executed without the -w
flag, but should probably be avoided otherwise. In addition, if the anchors are going to be resolved, rain should explicitly notify the user of that fact, both in the help messages but also in the output of the rain fmt
command
I could add a new flag to the command, like rain fmt --anchor
to explicitly resolve them.
Resolving anchors should probably be done by rain pkg
instead of rain fmt
.
Apparently the AWS CLI does understand anchors, using the package
command.
aws cloudformation package --template-file test/templates/anchors.yaml --s3-bucket my-bucket
I'll add this to rain pkg
so you can pipe the output to rain fmt
Great idea. That should provide a better UE.
YAML anchors are supported by Go, but when trying to convert to JSON with
rain fmt -j
, we get an error:yaml: unknown anchor 'fooval' referenced