-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(ec2): addIngressRule and addEgressRule detect unresolved tokens as duplicates #17201
Description
What is the problem?
When passing in a token to the peer property of these functions, the renderPeer() function is called and will return a constant value '{IndirectPeer}'.
aws-cdk/packages/@aws-cdk/aws-ec2/lib/security-group.ts
Lines 174 to 193 in 5831456
| function determineRuleScope( | |
| group: SecurityGroupBase, | |
| peer: IPeer, | |
| connection: Port, | |
| fromTo: 'from' | 'to', | |
| remoteRule?: boolean): [SecurityGroupBase, string] { | |
| if (remoteRule && SecurityGroupBase.isSecurityGroup(peer) && differentStacks(group, peer)) { | |
| // Reversed | |
| const reversedFromTo = fromTo === 'from' ? 'to' : 'from'; | |
| return [peer, `${group.uniqueId}:${connection} ${reversedFromTo}`]; | |
| } else { | |
| // Regular (do old ID escaping to in order to not disturb existing deployments) | |
| return [group, `${fromTo} ${renderPeer(peer)}:${connection}`.replace('/', '_')]; | |
| } | |
| } | |
| function renderPeer(peer: IPeer) { | |
| return Token.isUnresolved(peer.uniqueId) ? '{IndirectPeer}' : peer.uniqueId; | |
| } |
If the other properties remain constant, calling this multiple times will cause only one rule to be added to the security group due to the duplicate checker seen here
aws-cdk/packages/@aws-cdk/aws-ec2/lib/security-group.ts
Lines 86 to 96 in 5831456
| const [scope, id] = determineRuleScope(this, peer, connection, 'from', remoteRule); | |
| // Skip duplicates | |
| if (scope.node.tryFindChild(id) === undefined) { | |
| new CfnSecurityGroupIngress(scope, id, { | |
| groupId: this.securityGroupId, | |
| ...peer.toIngressRuleConfig(), | |
| ...connection.toRuleJson(), | |
| description, | |
| }); | |
| } |
Reproduction Steps
Call addIngressRule() or addEgressRule() multiple times on a security group, while only changing the peer prop from one token to another token. Only one rule will be added
What did you expect to happen?
I was trying to add multiple ingress rules to a security group
What actually happened?
I only added one ingress rule to a security group
CDK CLI Version
latest
Framework Version
No response
Node.js Version
16
OS
mac
Language
Typescript
Language Version
No response
Other information
No response