Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gomplate not preserving AWS-specific custom YAML tags on merge #1997

Open
greg-caffeine opened this issue Feb 14, 2024 · 3 comments
Open

Gomplate not preserving AWS-specific custom YAML tags on merge #1997

greg-caffeine opened this issue Feb 14, 2024 · 3 comments
Labels

Comments

@greg-caffeine
Copy link

greg-caffeine commented Feb 14, 2024

I would like to use gomplate to allow overriding and merging of sections of CloudFormation YAML templates with other YAML sections defined in other files by using the gomplate merge datasource. Unfortunately, gomplate drops the AWS-specific YAML tags in the merged output, breaking the template.

Example:

cloudfront_template.yaml:

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: A gomplate test

Parameters:
  MyParameter:
    Type: String

Globals:
  Function:
    Environment:
      Variables:
        MY_PARAMETER: !Ref MyParameter

cloudfront_overrides.yaml:

Globals:
  Function:
    Environment:
      Variables:
        MY_OTHER_PARAMETER: my_other_value

Gomplate Command
% gomplate -d 'merger=merge:cloudfront_template.yaml|cloudfront_overrides.yaml' -i '{{ include "merger" }}'

OUTPUT

AWSTemplateFormatVersion: 2010-09-09T00:00:00Z
Description: A gomplate test
Globals:
  Function:
    Environment:
      Variables:
        MY_OTHER_PARAMETER: my_other_value
        MY_PARAMETER: MyParameter
Parameters:
  MyParameter:
    Type: String
Transform: AWS::Serverless-2016-10-31

Note in the output that MY_PARAMETER: !Ref MyParameter has not been preserved and instead has been transformed into MY_PARAMETER: MyParameter, losing the !Ref tag.

Is there any way to get gomplate to preserve all HTML tags in the output, or to provide a list of tags to preserve?

A list of AWS custom tags can be found here.

@greg-caffeine greg-caffeine changed the title Gomplete not preserving AWS-specific custom YAML tags on merge Gomplate not preserving AWS-specific custom YAML tags on merge Feb 14, 2024
@hairyhenderson
Copy link
Owner

Hi @greg-caffeine, sorry for the delay.

Custom YAML tags are something that are going to be pretty difficult to support with gomplate. The main problem is that internally the data is parsed into an intermediate form which is a map with nested maps, and so something like the above would be parsed into (in JSON terms) {"MY_PARAMETER": "MyParameter"}, with no ability to retain custom tags.

You may be able to accomplish this if you instead reframe the approach and build a template out of cloudfront_template.yaml rather than using it as part of a datasource.

@hairyhenderson
Copy link
Owner

Hmm... There may actually be a possibility to use a different intermediate format, as hinted at by go-yaml/yaml#191 (comment), but it's unclear exactly how. I'd need to find some time to dig into this deeper.

Copy link

This issue is stale because it has been open for 60 days with no
activity. If it is no longer relevant or necessary, please close it.
Given no action, it will be closed in 14 days.

If it's still relevant, one of the following will remove the stale
marking:

  • A maintainer can add this issue to a milestone to indicate that
    it's been accepted and will be worked on
  • A maintainer can remove the stale label
  • Anyone can post an update or other comment

@github-actions github-actions bot added the Stale label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants