awslabs/aws-cfn-template-flip

Conversion of Fn::GetAtt from YML to JSON for short form syntax

davinod opened this issue · 1 comments

Fn::GetAtt requires two arguments as input, Resource and Attribute.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

The following entry is a valid YML reference, provided in AWS Documentation:

S3SubBucket:
    Type: "AWS::S3::Bucket"
    Properties:
      Tags:
        -
          Key: "MainBucket"
          Value: !GetAtt S3Stack.Outputs.BucketName

When this YML block is converted to json via $ cfn-flip -y , although it converts to a valid JSON syntax, it adds a third argument which makes the Fn::GetAtt be invalid:

"S3SubBucket": {
            "Type": "AWS::S3::Bucket", 
            "Properties": {
                "Tags": [
                    {
                        "Key": "MainBucket", 
                        "Value": {
                            "Fn::GetAtt": [
                                "S3Stack", 
                                "Outputs", 
                                "BucketName"
                            ]
                        }
                    }
                ]
            }
        }

The correct conversion should be:

"Fn::GetAtt": [
     "S3Stack", 
      "Outputs.BucketName"
]

In order to prevent this bug from happening, the template needs to be implemented using full syntax instead of short form:
Fn::GetAtt: [ S3Stack, Outputs.BucketName ]
It is very likely that when the cfn-flip finds !GetAtt S3Stack.Outputs.BucketName, it is simply using '.' as delimiter and breaking in multiple items.

Fixed in 881d7c9