diff --git a/src/cfnlint/rules/resources/ectwo/Ebs.py b/src/cfnlint/rules/resources/ectwo/Ebs.py index 875086d4b2..f949e491e3 100644 --- a/src/cfnlint/rules/resources/ectwo/Ebs.py +++ b/src/cfnlint/rules/resources/ectwo/Ebs.py @@ -59,7 +59,7 @@ def match(self, cfn): ebs = properties.get('Ebs') if virtual_name: # switch to regex - if not re.match(r'^ephemeral[0-9]$', virtual_name): + if not re.match(r'^ephemeral([0-9]|[1][0-9]|[2][0-3])$', virtual_name): pathmessage = path[:] + [index, 'VirtualName'] message = 'Property VirtualName should be of type ephemeral(n) for {0}' matches.append( diff --git a/test/fixtures/templates/bad/resources/ec2/ebs.yaml b/test/fixtures/templates/bad/resources/ec2/ebs.yaml new file mode 100644 index 0000000000..4923cb9e1c --- /dev/null +++ b/test/fixtures/templates/bad/resources/ec2/ebs.yaml @@ -0,0 +1,57 @@ +--- +AWSTemplateFormatVersion: "2010-09-09" +Description: A sample template +Resources: + ## Missing Properties + MyEC2Instance: + Type: "AWS::EC2::Instance" + Properties: + ImageId: "ami-2f726546" + InstanceType: t1.micro + KeyName: 1 + BlockDeviceMappings: + - DeviceName: /dev/sdm + Ebs: + VolumeType: io1 + Iops: 0 + DeleteOnTermination: false + VolumeSize: 20 + - DeviceName: /dev/sdn + Ebs: + VolumeType: magnetic + Iops: 100 + DeleteOnTermination: false + VolumeSize: 20 + NetworkInterfaces: + - DeviceIndex: "1" + MyEC2Instance3: + Type: "AWS::EC2::Instance" + Properties: + ImageId: "ami-2f726546" + BlockDeviceMappings: + - DeviceName: /dev/sdm + VirtualName: ephemeralA + - DeviceName: /dev/sdn + VirtualName: ephemeral0 + - DeviceName: /dev/sdo + VirtualName: ephemeral24 + - DeviceName: /dev/sdo + VirtualName: ephemeral100 + MyLaunchConfig: + Type: AWS::AutoScaling::LaunchConfiguration + Properties: + ImageId: "ami-2f726546" + InstanceType: t2.micro + BlockDeviceMappings: + - DeviceName: /dev/sdm + Ebs: + VolumeType: io1 + Iops: 10 + DeleteOnTermination: false + VolumeSize: 20 + - DeviceName: /dev/sdn + Ebs: + VolumeType: standard + Iops: 100 + DeleteOnTermination: false + VolumeSize: 20 diff --git a/test/fixtures/templates/good/properties_ebs.yaml b/test/fixtures/templates/good/resources/ec2/ebs.yaml similarity index 78% rename from test/fixtures/templates/good/properties_ebs.yaml rename to test/fixtures/templates/good/resources/ec2/ebs.yaml index 1405963797..4a34ddde80 100644 --- a/test/fixtures/templates/good/properties_ebs.yaml +++ b/test/fixtures/templates/good/resources/ec2/ebs.yaml @@ -14,8 +14,7 @@ Resources: InstanceType: t1.micro KeyName: 1 BlockDeviceMappings: - - - DeviceName: /dev/sdm + - DeviceName: /dev/sdm Ebs: VolumeType: io1 Iops: 1000 @@ -28,24 +27,25 @@ Resources: Properties: ImageId: "ami-2f726546" BlockDeviceMappings: - - - DeviceName: /dev/sdm - VirtualName: ephemeral0 + - DeviceName: /dev/sdm + VirtualName: ephemeral0 + - DeviceName: /dev/sdn + VirtualName: ephemeral23 + - DeviceName: /dev/sdo + VirtualName: ephemeral19 MyLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Properties: ImageId: "ami-2f726546" InstanceType: t2.micro BlockDeviceMappings: - - - DeviceName: /dev/sdm + - DeviceName: /dev/sdm Ebs: VolumeType: io1 Iops: !Ref myIops DeleteOnTermination: false VolumeSize: 20 - - - DeviceName: /dev/sdn + - DeviceName: /dev/sdn Ebs: VolumeType: standard DeleteOnTermination: false diff --git a/test/unit/rules/resources/ec2/test_ec2_ebs.py b/test/unit/rules/resources/ec2/test_ec2_ebs.py index 8f15ed75cf..0f093b0fe7 100644 --- a/test/unit/rules/resources/ec2/test_ec2_ebs.py +++ b/test/unit/rules/resources/ec2/test_ec2_ebs.py @@ -13,6 +13,9 @@ def setUp(self): """Setup""" super(TestPropertyEc2Ebs, self).setUp() self.collection.register(Ebs()) + self.success_templates = [ + 'test/fixtures/templates/good/resources/ec2/ebs.yaml', + ] def test_file_positive(self): """Test Positive""" @@ -20,4 +23,4 @@ def test_file_positive(self): def test_file_negative(self): """Test failure""" - self.helper_file_negative('test/fixtures/templates/bad/properties_ebs.yaml', 3) + self.helper_file_negative('test/fixtures/templates/bad/resources/ec2/ebs.yaml', 5)