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

When outputting to JSON, !Contains ("Fn::Contains") is removed erroneously. #612

Open
JoseRolles opened this issue Dec 13, 2024 · 2 comments

Comments

@JoseRolles
Copy link

JoseRolles commented Dec 13, 2024

To reproduce, create the following file.

template.yaml

Rules:
  CheckBootstrapVersion:
    Assertions:
      - Assert: !Not
          - !Contains
            - - '1'
              - '2'
              - '3'
              - '4'
              - '5'
            - !Ref BootstrapVersion

Then I ran the following command and got the following output.

$ rain fmt --unsorted --json template.yaml
{
    "Rules": {
        "CheckBootstrapVersion": {
            "Assertions": [
                {
                    "Assert": {
                        "Fn::Not": [
                            [
                                [
                                    "1",
                                    "2",
                                    "3",
                                    "4",
                                    "5"
                                ],
                                {
                                    "Ref": "BootstrapVersion"
                                }
                            ]
                        ]
                    }
                }
            ]
        }
    }
}

The output should be the following instead.

{
    "Rules": {
        "CheckBootstrapVersion": {
            "Assertions": [
                {
                    "Assert": {
                        "Fn::Not": [
                            {
                                "Fn::Contains": [
                                    [
                                        "1",
                                        "2",
                                        "3",
                                        "4",
                                        "5"
                                    ],
                                    {
                                        "Ref": "BootstrapVersion"
                                    }
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    }
}
@JoseRolles JoseRolles changed the title When outputting to JSON, !Contains (`"Fn::Contains") is removed erroneously. When outputting to JSON, !Contains ("Fn::Contains") is removed erroneously. Dec 13, 2024
@JoseRolles
Copy link
Author

Hmmm, apparently the short form doesn't work, but the full function name works.

Rules:
  CheckBootstrapVersion:
    Assertions:
      - Assert: !Not
          - "Fn::Contains":
            - - '1'
              - '2'
              - '3'
              - '4'
              - '5'
            - !Ref BootstrapVersion

@ericzbeard
Copy link
Contributor

For some reason the go yaml parser is converting !Contains to a tag, not a mapping. Not sure there's much I can do about this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants