emrichen
emrichen copied to clipboard
Co-operate with formats that use tags of their own such as CloudFormation
CloudFormation has its own functions such as !Subst
and !Join
etc. In order to be able to input and output CloudFormation templates, Emrichen needs a way to co-operate with foreign tags.
(Bad) options:
- Keep disallowing foreign tags and require CloudFormation users to use the
{ "Fn::Join": […] }
form of CFN functions instead of the tag-based!Join
form - Prefix our own tags with some prefix, reducing the risk of collision, and pass foreign tags to the output as-is.
- Require foreign tags to be prefixed and strip the prefix upon processing
- have a per-template pragma sort of thing to determine which tags are handled within emrichen and which not (e.g.
!Pragma cloudformation
)
@zbyte64 in #53 suggested another use case for this: creating Emrichen templates with Emrichen.
If we were to go by approach 2, it might look like something like this:
Template:
foo: !Tag,FooTagWillBeCopiedVerbatimToOutput 5
Output:
foo: !FooTagWillBeCopiedVerbatimToOutput 5
Here I'm shamelessly reusing the ,
separator we currently are using for tag composition. tag_name.startswith("Tag,")
would have to be special-cased in emrichen.input.yaml:construct_tagged_object
.
Implementation could use a Tag
internal tag similarly to Compose
, but how would it communicate the custom tag to PyYAML? Ad-hoc class that extends YAMLObject
and sets tag = "FooTagWillBeCopiedVerbatimToOutput"
as class variable?
For my use I actually want to spit back Tags I would otherwise process with emrichen, but as a second stage. Would option 2 look something like this (adapted from my use case)?
chart:
profile: "foobar"
chartConfigUrl:
!Tag,AsDocument
filename: ./data_overview.json
content: !Tag,With
template: !Tag,Include ./atemplate.template.yaml
vars:
path: s3://...../
columns:
- application_gap_ratio
- application_gap
This tweaked my brain at first, but now it seems very satisfying.