martysweet / cfn-lint

A CloudFormation JSON and YAML Validator
MIT License
162 stars 38 forks source link

Support the intrinsic function `Fn::And` #184

Open lorengordon opened 6 years ago

lorengordon commented 6 years ago

Just a placeholder for adding support for the Fn::And intrinsic function. Currently causing cfn-lint to claim our templates are invalid.

martysweet commented 6 years ago

This should be pretty easy to implement, probably best to copy the doInstrinicOr and change the conditional statement within.

martysweet commented 6 years ago

Having a look, Fn::And is implemented, is there a certain issue that's occurring?

lorengordon commented 6 years ago

Yeah...

Resource: Conditions > UseScheduledAction
Message: Condition did not resolve to a boolean value, got null
Documentation: http://docs.aws.amazon.com/search/doc-search.html?searchPath=documentation-guide&searchQuery=Conditions&x=0&y=0&this_doc_product=AWS+CloudFormation&this_doc_guide=User+Guide&doc_locale=en_us#facet_doc_product=AWS%20CloudFormation&facet_doc_guide=User%20Guide

where the condition looks like this (default value for both Refs is the empty string "")...

        "UseScheduledAction": {
            "Fn::And": [
                {
                    "Fn::Not": [
                        {
                            "Fn::Equals": [
                                {
                                    "Ref": "ScaleUpSchedule"
                                },
                                ""
                            ]
                        }
                    ]
                },
                {
                    "Fn::Not": [
                        {
                            "Fn::Equals": [
                                {
                                    "Ref": "ScaleDownSchedule"
                                },
                                ""
                            ]
                        }
                    ]
                }
            ]
        },

When I looked into the cfn-lint code and issues, it appeared the Fn::And was not implemented, hence the issue. Obviously being unfamiliar with the code I may have missed it or misunderstood.

martysweet commented 6 years ago

My mistake! The documentation is lying!

This should be a case of copying the doIntrinsicOr and changing the condition logic, then adding a couple of tests - hopefully will get a chance to look this weekend, but happy to review a pull request!

Dynamo6Dev commented 5 years ago

Any ETA on this yet? Looks like it's still an issue.

martysweet commented 5 years ago

This project is EOL in favour of https://github.com/aws-cloudformation/cfn-python-lint, however, if you wish to add doIntrinsicAnd with a couple of use cases I would be happy to push it in the next release.

martysweet commented 5 years ago

I made a start to it here a while ago https://github.com/martysweet/cfn-lint/pull/205/files, there is a lot of work around making conditions work correctly which is the major limiting factor to this - but happy for any contribution.