Skip to content

Commit 182bafc

Browse files
authored
fix(cloudformation-diff): cdk diff throws toUpperCase is not a function when ipProtocol is a number (#28023)
Fix the describe protocol method when running a diff with a processed existing cloudformation template that has a security group rule with ipprotocol = -1 Closes #28021 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9ae9af2 commit 182bafc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/@aws-cdk/cloudformation-diff/lib/network/security-group-rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class SecurityGroupRule {
2828
public readonly peer?: RulePeer;
2929

3030
constructor(ruleObject: any, groupRef?: string) {
31-
this.ipProtocol = ruleObject.IpProtocol || '*unknown*';
31+
this.ipProtocol = ruleObject.IpProtocol?.toString() || '*unknown*';
3232
this.fromPort = ruleObject.FromPort;
3333
this.toPort = ruleObject.ToPort;
3434
this.groupId = ruleObject.GroupId || groupRef || '*unknown*'; // In case of an inline rule

packages/@aws-cdk/cloudformation-diff/test/network/rule.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ test('equality is symmetric', () => {
7474
},
7575
));
7676
});
77+
78+
test('can describe protocol', () => {
79+
expect(new SecurityGroupRule({ IpProtocol: -1 }).describeProtocol()).toEqual('Everything');
80+
expect(new SecurityGroupRule({ IpProtocol: '-1' }).describeProtocol()).toEqual('Everything');
81+
expect(new SecurityGroupRule({ FromPort: -1 }).describeProtocol()).toEqual('All *UNKNOWN*');
82+
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: -1, ToPort: -1 }).describeProtocol()).toEqual('All TCP');
83+
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: 10, ToPort: 20 }).describeProtocol()).toEqual('TCP 10-20');
84+
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: 10, ToPort: 10 }).describeProtocol()).toEqual('TCP 10');
85+
});

0 commit comments

Comments
 (0)