Appliscale / perun

A command-line validation tool for AWS Cloud Formation that allows to conquer the cloud faster!
https://perun-for-aws.appliscale.io
Apache License 2.0
92 stars 8 forks source link

Bug while parsing intristic function !Sub #144

Closed mwpolcik closed 6 years ago

mwpolcik commented 6 years ago
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  SomeParam:
    Type: String
    AllowedValues:
      - some.default.value

Resources:

  SomeRole:
    Type: "AWS::IAM::Role"
    Properties:
      RoleName: !Sub ${SomeParam}.nebula
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          -
            Effect: "Allow"
            Principal:
              Service:
                - "ec2.amazonaws.com"
            Action:
              - "sts:AssumeRole"

Perun should report template as valid, but is throwing an error:

ERROR: invalid YAML template: yaml: line 13: did not find expected ',' or '}'
ERROR: Template templates/iam-roles.yml is invalid!
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x161f76d]

goroutine 1 [running]:
github.com/Appliscale/perun/helpers.ParseYAML(0xc4200ac000, 0x1f0, 0x3f0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/mpolcik/Projects/GO/src/github.com/Appliscale/perun/helpers/formathelpers.go:79 +0x42d
maxiwoj commented 6 years ago
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  VPCStackName:
    Type: String

Resources:

  ICMPPublicSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow ICMP from outside world
      VpcId:
        Fn::ImportValue: !Sub '${VPCStackName}-vpcId'
      SecurityGroupIngress:
      - IpProtocol: icmp
        FromPort: '-1'
        ToPort: '-1'
        CidrIp: 0.0.0.0/0
      Tags:
      - Key: Name
        Value: !Join ["-",[PUBLIC, ICMP, SG]]

This template also throws an error with the !Sub function, but it is valid