Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misconf): check if property is not nil before conversion #7578

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/iac/adapters/cloudformation/aws/ec2/adapt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ Resources:
},
},
},
{
name: "empty",
source: `---
AWSTemplateFormatVersion: 2010-09-09
Description: Godd example of excessive ports
Resources:
NetworkACL:
Type: AWS::EC2::NetworkAcl
Rule:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId:
Ref: NetworkACL`,
expected: ec2.EC2{
NetworkACLs: []ec2.NetworkACL{
{
Rules: []ec2.NetworkACLRule{
{
Action: types.StringTest("allow"),
Type: types.StringTest("ingress"),
FromPort: types.IntTest(-1),
ToPort: types.IntTest(-1),
},
},
},
},
},
},
}

for _, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
)

func (p *Property) IsConvertableTo(conversionType cftypes.CfType) bool {
if p.IsNil() {
return false
}

switch conversionType {
case cftypes.Int:
return p.isConvertableToInt()
Expand Down Expand Up @@ -62,6 +66,9 @@ func (p *Property) isConvertableToInt() bool {
}

func (p *Property) ConvertTo(conversionType cftypes.CfType) *Property {
if p.IsNil() {
return nil
}

if p.Type() == conversionType {
return p
Expand Down