Skip to content

Commit

Permalink
Support numbers, boolean when doing a Sub parameter value (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Nov 12, 2020
1 parent 34f34e4 commit a735424
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cfnlint/rules/functions/Sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def _test_parameters(self, parameters, cfn, tree):
message = 'Sub parameter should be an object of 1 for {0}'
matches.append(RuleMatch(
param_tree, message.format('/'.join(map(str, tree)))))
elif not isinstance(parameter_value_obj, six.string_types):
message = 'Sub parameter should be an object of 1 or string for {0}'
elif isinstance(parameter_value_obj, list):
message = 'Sub parameter value should be a string for {0}'
matches.append(RuleMatch(
param_tree, message.format('/'.join(map(str, tree)))))

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/templates/bad/functions/sub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ Resources:
Properties:
CidrBlock:
Fn::Sub:
- "${myCidr}"
- "${myCidr}${number}"
- myCidr: !Ref CidrBlock
number:
- bad
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/templates/good/functions/sub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Parameters:
Description: App Package
mySubnets:
Type: List<AWS::EC2::Subnet::Id>
CidrBlock:
Type: String
Resources:
myInstance:
Type: AWS::EC2::Instance
Expand Down Expand Up @@ -64,6 +66,14 @@ Resources:
Properties:
ProductName: example
ProvisioningArtifactName: v1
myVPc2:
Type: AWS::EC2::VPC
Properties:
CidrBlock:
Fn::Sub:
- "${myCidr}${number}"
- myCidr: !Ref CidrBlock
number: 1
Outputs:
OutputSub:
Value: !Sub '${ProvisionedProduct.Outputs.Example}-example'
2 changes: 1 addition & 1 deletion test/unit/rules/functions/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def test_file_positive(self):

def test_file_negative(self):
"""Test failure"""
self.helper_file_negative('test/fixtures/templates/bad/functions/sub.yaml', 15)
self.helper_file_negative('test/fixtures/templates/bad/functions/sub.yaml', 16)

0 comments on commit a735424

Please sign in to comment.