awslabs/aws-cfn-template-flip

cfn-flip mangles the attribute specified in my Fn::GetAtt calls

sdejean opened this issue · 2 comments

Hello, I've been testing cfn-flip this week with our JSON templates and we've hit a snag with a template containing Fn::GetAtt. cfn-flip seems to place a . in-between each character of the attribute name. I have created a test template that demonstrates the issue.

{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "Test cfn-flip template",
  "Metadata" : {
    "HostedZones" : {
      "123456789012" : {
        "ZoneId" : "ABCDEFGHIG1234",
        "ZoneName" : "testsub.testdomain.com."
      }
    }
  },
  "Parameters" : {
  },
  "Conditions" : {
  },
  "Resources" : {
    "TestRoute53Record" : {
      "Type" : "AWS::Route53::RecordSet",
      "Properties" : {
        "HostedZoneId": { "Fn::FindInMap" : [ "HostedZones", { "Ref" : "AWS::AccountId" }, "ZoneId" ] },
        "Comment" : "Test DNS entry",
        "Name" : {
          "Fn::Join" : [
            "",
            [
              { "Ref" : "ParentStackName" },
              ".",
              { "Ref" : "AWS::Region" },
              ".",
              { "Fn::FindInMap" : [ "HostedZones", { "Ref" : "AWS::AccountId" }, "ZoneName" ]
              }
            ]
          ]
        },
        "Type" : "CNAME",
        "TTL" : "300",
        "ResourceRecords" : [
          { "Fn::GetAtt" : "FakeResource.FakeAttribute" }
        ]
      }
    }
  },
  "Outputs" : {
  }
}

Generates the following output:

AWSTemplateFormatVersion: '2010-09-09'
Description: Test cfn-flip template
Metadata:
  HostedZones:
    '123456789012':
      ZoneId: ABCDEFGHIG1234
      ZoneName: testsub.testdomain.com.
Parameters: {}
Conditions: {}
Resources:
  TestRoute53Record:
    Type: AWS::Route53::RecordSet
    Properties:
      HostedZoneId: !FindInMap [HostedZones, !Ref 'AWS::AccountId', ZoneId]
      Comment: Test DNS entry
      Name: !Join ['', [!Ref 'ParentStackName', ., !Ref 'AWS::Region', ., !FindInMap [
            HostedZones, !Ref 'AWS::AccountId', ZoneName]]]
      Type: CNAME
      TTL: '300'
      ResourceRecords:
        - !GetAtt 'F.a.k.e.R.e.s.o.u.r.c.e...F.a.k.e.A.t.t.r.i.b.u.t.e'
Outputs: {}

Python and cfn-flip versions:

$ python --version
Python 2.7.14

$ pip show cfn-flip
Name: cfn-flip
Version: 0.2.4.post2
Summary: Convert AWS CloudFormation templates between JSON and YAML formats
Home-page: https://github.com/awslabs/aws-cfn-template-flip
Author: Steve Engledow
Author-email: sengledo@amazon.co.uk
License: Apache2
Location: /Users/sdejean/.virtualenvs/cfnflip-wujEZljp/lib/python2.7/site-packages
Requires: six, PyYAML

So, according to the GetAtt documentation this is invalid syntax for GetAtt in JSON. However, cloudformation seems to be happy with it so I'll fix it shortly :)

Fixed in 2e3c3ef. New pip version coming soon.