unbounce / iidy

iidy (Is it done yet?) -- CloudFormation with Confidence
MIT License
52 stars 7 forks source link

!GetAtt in common template called multiple times creates YAML aliases in rendered output #239

Closed dannosaur closed 4 years ago

dannosaur commented 4 years ago

I suspect as part of #228, this particular use case got broken. Example templates that replicate the issue;

stack.yml

$imports:
  common: ./common.yml

Resources:
  Role:
    Type: AWS::IAM::Role

  App1:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Environment: !$ common.Environment
  App2:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Environment: !$ common.Environment

common.yml

Environment:
  - Name: ROLE
    Value: !GetAtt [Role, Arn]

Expected output:

Resources:
  Role:
    Type: 'AWS::IAM::Role'
  App1:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: ROLE
              Value: !GetAtt 
                - Role
                - Arn
  App2:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: ROLE
              Value: !GetAtt 
                - Role
                - Arn

Actual output:

Resources:
  Role:
    Type: 'AWS::IAM::Role'
  App1:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: ROLE
              Value: !GetAtt &ref_0
                - Role
                - Arn
  App2:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: ROLE
              Value: *ref_0

The caveat here seems to be when a common element is referenced twice in the same template. If App2 is removed from the source, the output ends up as expected. If the element is included more than once, it generates YAML aliases which then create invalid CFN templates (CFN doesn't support YAML aliases).

dannosaur commented 4 years ago

Actual output is now expected output with this fix.