emrichen icon indicating copy to clipboard operation
emrichen copied to clipboard

Co-operate with formats that use tags of their own such as CloudFormation

Open japsu opened this issue 6 years ago • 3 comments

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:

  1. Keep disallowing foreign tags and require CloudFormation users to use the { "Fn::Join": […] } form of CFN functions instead of the tag-based !Join form
  2. Prefix our own tags with some prefix, reducing the risk of collision, and pass foreign tags to the output as-is.
  3. Require foreign tags to be prefixed and strip the prefix upon processing

japsu avatar Aug 13 '18 11:08 japsu

  1. have a per-template pragma sort of thing to determine which tags are handled within emrichen and which not (e.g. !Pragma cloudformation)

akx avatar Aug 13 '18 12:08 akx

@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?

japsu avatar Oct 13 '21 05:10 japsu

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.

zbyte64 avatar Oct 16 '21 00:10 zbyte64