Skip to content

Commit c277419

Browse files
authored
feat(ec2): implement IPeer to PrefixList to be usable as a connection peer (#33617)
### Issue # (if applicable) Closes #33607. ### Reason for this change When we want to add a security group rule with `PrefixList` as a connection peer, we should write redundant `prefixList`: ``` ts const pl = new ec2.PrefixList(this, 'PrefixList', { ... }); instance.connections.allowFrom(ec2.Peer.prefixList(pl.prefixListId), ec2.Port.XXX); ``` This PR allows us to write DRY: ``` ts const pl = new ec2.PrefixList(this, 'PrefixList', { ... }); instance.connections.allowFrom(pl, ec2.Port.XXX); ``` ### Description of changes - Modify the `IPrefixList` interface to extend `IPeer` - Implement the required `IPeer` methods in `PrefixListBase` ### Describe any new or updated permissions being added Nothing ### Description of how you validated changes Added unit tests and updated an integ test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b1ad64c commit c277419

File tree

12 files changed

+1009
-22
lines changed

12 files changed

+1009
-22
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.prefix-list.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.prefix-list.js.snapshot/integ-ec2-prefix-list-test.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.prefix-list.js.snapshot/integ-ec2-prefix-list-test.template.json

Lines changed: 248 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,254 @@
11
{
22
"Resources": {
3+
"Vpc8378EB38": {
4+
"Type": "AWS::EC2::VPC",
5+
"Properties": {
6+
"CidrBlock": "10.0.0.0/16",
7+
"EnableDnsHostnames": true,
8+
"EnableDnsSupport": true,
9+
"InstanceTenancy": "default",
10+
"Tags": [
11+
{
12+
"Key": "Name",
13+
"Value": "integ-ec2-prefix-list-test/Vpc"
14+
}
15+
]
16+
}
17+
},
18+
"VpcPublicSubnet1Subnet5C2D37C4": {
19+
"Type": "AWS::EC2::Subnet",
20+
"Properties": {
21+
"AvailabilityZone": {
22+
"Fn::Select": [
23+
0,
24+
{
25+
"Fn::GetAZs": ""
26+
}
27+
]
28+
},
29+
"CidrBlock": "10.0.0.0/17",
30+
"MapPublicIpOnLaunch": true,
31+
"Tags": [
32+
{
33+
"Key": "aws-cdk:subnet-name",
34+
"Value": "Public"
35+
},
36+
{
37+
"Key": "aws-cdk:subnet-type",
38+
"Value": "Public"
39+
},
40+
{
41+
"Key": "Name",
42+
"Value": "integ-ec2-prefix-list-test/Vpc/PublicSubnet1"
43+
}
44+
],
45+
"VpcId": {
46+
"Ref": "Vpc8378EB38"
47+
}
48+
}
49+
},
50+
"VpcPublicSubnet1RouteTable6C95E38E": {
51+
"Type": "AWS::EC2::RouteTable",
52+
"Properties": {
53+
"Tags": [
54+
{
55+
"Key": "Name",
56+
"Value": "integ-ec2-prefix-list-test/Vpc/PublicSubnet1"
57+
}
58+
],
59+
"VpcId": {
60+
"Ref": "Vpc8378EB38"
61+
}
62+
}
63+
},
64+
"VpcPublicSubnet1RouteTableAssociation97140677": {
65+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
66+
"Properties": {
67+
"RouteTableId": {
68+
"Ref": "VpcPublicSubnet1RouteTable6C95E38E"
69+
},
70+
"SubnetId": {
71+
"Ref": "VpcPublicSubnet1Subnet5C2D37C4"
72+
}
73+
}
74+
},
75+
"VpcPublicSubnet1DefaultRoute3DA9E72A": {
76+
"Type": "AWS::EC2::Route",
77+
"Properties": {
78+
"DestinationCidrBlock": "0.0.0.0/0",
79+
"GatewayId": {
80+
"Ref": "VpcIGWD7BA715C"
81+
},
82+
"RouteTableId": {
83+
"Ref": "VpcPublicSubnet1RouteTable6C95E38E"
84+
}
85+
},
86+
"DependsOn": [
87+
"VpcVPCGWBF912B6E"
88+
]
89+
},
90+
"VpcIsolatedSubnet1SubnetE48C5737": {
91+
"Type": "AWS::EC2::Subnet",
92+
"Properties": {
93+
"AvailabilityZone": {
94+
"Fn::Select": [
95+
0,
96+
{
97+
"Fn::GetAZs": ""
98+
}
99+
]
100+
},
101+
"CidrBlock": "10.0.128.0/17",
102+
"MapPublicIpOnLaunch": false,
103+
"Tags": [
104+
{
105+
"Key": "aws-cdk:subnet-name",
106+
"Value": "Isolated"
107+
},
108+
{
109+
"Key": "aws-cdk:subnet-type",
110+
"Value": "Isolated"
111+
},
112+
{
113+
"Key": "Name",
114+
"Value": "integ-ec2-prefix-list-test/Vpc/IsolatedSubnet1"
115+
}
116+
],
117+
"VpcId": {
118+
"Ref": "Vpc8378EB38"
119+
}
120+
}
121+
},
122+
"VpcIsolatedSubnet1RouteTable4771E3E5": {
123+
"Type": "AWS::EC2::RouteTable",
124+
"Properties": {
125+
"Tags": [
126+
{
127+
"Key": "Name",
128+
"Value": "integ-ec2-prefix-list-test/Vpc/IsolatedSubnet1"
129+
}
130+
],
131+
"VpcId": {
132+
"Ref": "Vpc8378EB38"
133+
}
134+
}
135+
},
136+
"VpcIsolatedSubnet1RouteTableAssociationD300FCBB": {
137+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
138+
"Properties": {
139+
"RouteTableId": {
140+
"Ref": "VpcIsolatedSubnet1RouteTable4771E3E5"
141+
},
142+
"SubnetId": {
143+
"Ref": "VpcIsolatedSubnet1SubnetE48C5737"
144+
}
145+
}
146+
},
147+
"VpcIGWD7BA715C": {
148+
"Type": "AWS::EC2::InternetGateway",
149+
"Properties": {
150+
"Tags": [
151+
{
152+
"Key": "Name",
153+
"Value": "integ-ec2-prefix-list-test/Vpc"
154+
}
155+
]
156+
}
157+
},
158+
"VpcVPCGWBF912B6E": {
159+
"Type": "AWS::EC2::VPCGatewayAttachment",
160+
"Properties": {
161+
"InternetGatewayId": {
162+
"Ref": "VpcIGWD7BA715C"
163+
},
164+
"VpcId": {
165+
"Ref": "Vpc8378EB38"
166+
}
167+
}
168+
},
169+
"SGADB53937": {
170+
"Type": "AWS::EC2::SecurityGroup",
171+
"Properties": {
172+
"GroupDescription": "integ-ec2-prefix-list-test/SG",
173+
"VpcId": {
174+
"Ref": "Vpc8378EB38"
175+
}
176+
}
177+
},
178+
"SGfromIndirectPeer2262072E50": {
179+
"Type": "AWS::EC2::SecurityGroupIngress",
180+
"Properties": {
181+
"Description": {
182+
"Fn::Join": [
183+
"",
184+
[
185+
"from ",
186+
{
187+
"Fn::GetAtt": [
188+
"PrefixList469FCC0B",
189+
"PrefixListId"
190+
]
191+
},
192+
":22"
193+
]
194+
]
195+
},
196+
"FromPort": 22,
197+
"GroupId": {
198+
"Fn::GetAtt": [
199+
"SGADB53937",
200+
"GroupId"
201+
]
202+
},
203+
"IpProtocol": "tcp",
204+
"SourcePrefixListId": {
205+
"Fn::GetAtt": [
206+
"PrefixList469FCC0B",
207+
"PrefixListId"
208+
]
209+
},
210+
"ToPort": 22
211+
}
212+
},
213+
"SGtoIndirectPeer280E1219622": {
214+
"Type": "AWS::EC2::SecurityGroupEgress",
215+
"Properties": {
216+
"Description": {
217+
"Fn::Join": [
218+
"",
219+
[
220+
"to ",
221+
{
222+
"Fn::GetAtt": [
223+
"PrefixList469FCC0B",
224+
"PrefixListId"
225+
]
226+
},
227+
":80"
228+
]
229+
]
230+
},
231+
"DestinationPrefixListId": {
232+
"Fn::GetAtt": [
233+
"PrefixList469FCC0B",
234+
"PrefixListId"
235+
]
236+
},
237+
"FromPort": 80,
238+
"GroupId": {
239+
"Fn::GetAtt": [
240+
"SGADB53937",
241+
"GroupId"
242+
]
243+
},
244+
"IpProtocol": "tcp",
245+
"ToPort": 80
246+
}
247+
},
3248
"PrefixList469FCC0B": {
4249
"Type": "AWS::EC2::PrefixList",
5250
"Properties": {
6251
"AddressFamily": "IPv4",
7-
"MaxEntries": 2,
8-
"PrefixListName": "integec2prefixlisttestPrefixList498BBB96",
9252
"Entries": [
10253
{
11254
"Cidr": "10.0.0.1/32"
@@ -14,7 +257,9 @@
14257
"Cidr": "10.0.0.2/32",
15258
"Description": "sample1"
16259
}
17-
]
260+
],
261+
"MaxEntries": 2,
262+
"PrefixListName": "integec2prefixlisttestPrefixList498BBB96"
18263
}
19264
}
20265
},

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.prefix-list.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.prefix-list.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)