Skip to content

Commit d38592d

Browse files
Removed client side validations and added/removed corresponding unit tests
1 parent d88641e commit d38592d

File tree

2 files changed

+14
-118
lines changed

2 files changed

+14
-118
lines changed

packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,10 @@ export class InterfaceVpcEndpoint extends VpcEndpoint implements IInterfaceVpcEn
10321032
subnetIds,
10331033
vpcId: props.vpc.vpcId,
10341034
ipAddressType: props.ipAddressType,
1035-
dnsOptions: this.getDnsOptions(props),
1035+
dnsOptions: {
1036+
privateDnsOnlyForInboundResolverEndpoint: props.privateDnsOnlyForInboundResolverEndpoint,
1037+
dnsRecordIpType: props.dnsRecordIpType,
1038+
},
10361039
});
10371040

10381041
this.vpcEndpointId = endpoint.ref;
@@ -1041,48 +1044,6 @@ export class InterfaceVpcEndpoint extends VpcEndpoint implements IInterfaceVpcEn
10411044
this.vpcEndpointNetworkInterfaceIds = endpoint.attrNetworkInterfaceIds;
10421045
}
10431046

1044-
private getDnsOptions(props: InterfaceVpcEndpointProps): CfnVPCEndpoint.DnsOptionsSpecificationProperty | undefined {
1045-
if (!props.privateDnsEnabled && props.privateDnsOnlyForInboundResolverEndpoint !== undefined) {
1046-
throw new Error('Enable private DNS to set the private DNS only for inbound endpoints');
1047-
}
1048-
1049-
if (!props.ipAddressType && props.dnsRecordIpType !== undefined) {
1050-
throw new Error('Configure the ipAddressType to use in the VPC endpoint');
1051-
}
1052-
1053-
/**
1054-
* Checks to see if dnsRecordIpType and ipAddressType are compatible, throw error if not
1055-
* @see https://docs.aws.amazon.com/vpc/latest/privatelink/create-endpoint-service.html#connect-to-endpoint-service
1056-
*/
1057-
switch (props.dnsRecordIpType) {
1058-
case VpcEndpointDnsRecordIpType.IPV4:
1059-
if (props.ipAddressType === VpcEndpointIpAddressType.IPV6) {
1060-
throw new Error('Cannot create a VPC endpoint with ipAddressType of IPv6 with DNS Records for IPv4');
1061-
}
1062-
break;
1063-
case VpcEndpointDnsRecordIpType.IPV6:
1064-
if (props.ipAddressType === VpcEndpointIpAddressType.IPV4) {
1065-
throw new Error('Cannot create a VPC endpoint with ipAddressType of IPv4 with DNS Records for IPv6');
1066-
}
1067-
break;
1068-
case VpcEndpointDnsRecordIpType.DUALSTACK:
1069-
if (props.ipAddressType !== VpcEndpointIpAddressType.DUALSTACK) {
1070-
throw new Error('VPC endpoints with dualstack ipAddressType should set dnsRecordIpType to dualstack');
1071-
}
1072-
break;
1073-
case VpcEndpointDnsRecordIpType.SERVICE_DEFINED:
1074-
if (props.ipAddressType !== VpcEndpointIpAddressType.DUALSTACK) {
1075-
throw new Error('VPC endpoints with service defined configuration should set dnsRecordIpType to dualstack');
1076-
}
1077-
break;
1078-
}
1079-
1080-
return {
1081-
privateDnsOnlyForInboundResolverEndpoint: props.privateDnsOnlyForInboundResolverEndpoint,
1082-
dnsRecordIpType: props.dnsRecordIpType,
1083-
};
1084-
}
1085-
10861047
/**
10871048
* Determine which subnets to place the endpoint in. This is in its own function
10881049
* because there's a lot of code.

packages/aws-cdk-lib/aws-ec2/test/vpc-endpoint.test.ts

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Match, Template } from '../../assertions';
2-
import { AnyPrincipal, PolicyStatement } from '../../aws-iam';
1+
import {Match, Template} from '../../assertions';
2+
import {AnyPrincipal, PolicyStatement} from '../../aws-iam';
33
import * as cxschema from '../../cloud-assembly-schema';
4-
import { ContextProvider, Fn, Stack } from '../../core';
4+
import {ContextProvider, Fn, Stack} from '../../core';
55
// eslint-disable-next-line max-len
66
import {
77
GatewayVpcEndpoint,
@@ -13,7 +13,8 @@ import {
1313
SubnetFilter,
1414
SubnetType,
1515
Vpc,
16-
VpcEndpointDnsRecordIpType, VpcEndpointIpAddressType,
16+
VpcEndpointDnsRecordIpType,
17+
VpcEndpointIpAddressType,
1718
} from '../lib';
1819

1920
describe('vpc endpoint', () => {
@@ -180,91 +181,25 @@ describe('vpc endpoint', () => {
180181
});
181182
});
182183

183-
test('throws when adding dnsRecordIpType without private dns enabled', () => {
184-
// GIVEN
185-
const stack = new Stack();
186-
const vpc = new Vpc(stack, 'VpcNetwork');
187-
188-
// WHEN
189-
expect(() => {
190-
vpc.addInterfaceEndpoint('EcrDocker', {
191-
privateDnsEnabled: false,
192-
service: InterfaceVpcEndpointAwsService.ECR_DOCKER,
193-
dnsRecordIpType: VpcEndpointDnsRecordIpType.DUALSTACK,
194-
});
195-
// THEN
196-
}).toThrow();
197-
});
198-
199-
test('throws when adding dnsRecordIpType without ipAddressType', () => {
200-
// GIVEN
201-
const stack = new Stack();
202-
const vpc = new Vpc(stack, 'VpcNetwork');
203-
204-
// WHEN
205-
expect(() => {
206-
vpc.addInterfaceEndpoint('EcrDocker', {
207-
service: InterfaceVpcEndpointAwsService.ECR_DOCKER,
208-
dnsRecordIpType: VpcEndpointDnsRecordIpType.DUALSTACK,
209-
});
210-
// THEN
211-
}).toThrow();
212-
});
213-
214-
test.each([
215-
[VpcEndpointIpAddressType.IPV4, VpcEndpointDnsRecordIpType.IPV4],
216-
[VpcEndpointIpAddressType.DUALSTACK, VpcEndpointDnsRecordIpType.IPV4],
217-
[VpcEndpointIpAddressType.IPV6, VpcEndpointDnsRecordIpType.IPV6],
218-
[VpcEndpointIpAddressType.DUALSTACK, VpcEndpointDnsRecordIpType.IPV6],
219-
[VpcEndpointIpAddressType.DUALSTACK, VpcEndpointDnsRecordIpType.DUALSTACK],
220-
[VpcEndpointIpAddressType.DUALSTACK, VpcEndpointDnsRecordIpType.SERVICE_DEFINED],
221-
])('add an endpoint to a vpc with various matching IP address types', (
222-
ipAddressType: VpcEndpointIpAddressType,
223-
dnsRecordIpType: VpcEndpointDnsRecordIpType) => {
184+
test('check ipAddressType and dnsOptions are present when specified', () => {
224185
// GIVEN
225186
const stack = new Stack();
226187
const vpc = new Vpc(stack, 'VpcNetwork');
227188

228189
// WHEN
229190
vpc.addInterfaceEndpoint('EcrDocker', {
230191
service: InterfaceVpcEndpointAwsService.ECR_DOCKER,
231-
ipAddressType: ipAddressType,
232-
dnsRecordIpType: dnsRecordIpType,
192+
ipAddressType: VpcEndpointIpAddressType.DUALSTACK,
193+
dnsRecordIpType: VpcEndpointDnsRecordIpType.DUALSTACK,
233194
});
234195

235196
// THEN
236197
Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', {
237-
IpAddressType: ipAddressType,
238-
DnsOptions: { DnsRecordIpType: dnsRecordIpType },
198+
IpAddressType: VpcEndpointIpAddressType.DUALSTACK,
199+
DnsOptions: { DnsRecordIpType: VpcEndpointDnsRecordIpType.DUALSTACK },
239200
});
240201
});
241202

242-
test.each([
243-
[VpcEndpointIpAddressType.IPV6, VpcEndpointDnsRecordIpType.IPV4],
244-
[VpcEndpointIpAddressType.IPV4, VpcEndpointDnsRecordIpType.IPV6],
245-
[VpcEndpointIpAddressType.IPV4, VpcEndpointDnsRecordIpType.DUALSTACK],
246-
[VpcEndpointIpAddressType.IPV6, VpcEndpointDnsRecordIpType.DUALSTACK],
247-
[VpcEndpointIpAddressType.IPV4, VpcEndpointDnsRecordIpType.SERVICE_DEFINED],
248-
[VpcEndpointIpAddressType.IPV6, VpcEndpointDnsRecordIpType.SERVICE_DEFINED],
249-
])('add an endpoint to a vpc with mismatched ipAddressType and dnsRecordIpType, which throws error', (
250-
ipAddressType: VpcEndpointIpAddressType,
251-
dnsRecordIpType: VpcEndpointDnsRecordIpType,
252-
) => {
253-
// GIVEN
254-
const stack = new Stack();
255-
const vpc = new Vpc(stack, 'VpcNetwork');
256-
257-
// WHEN
258-
expect(() => {
259-
vpc.addInterfaceEndpoint('EcrDocker', {
260-
service: InterfaceVpcEndpointAwsService.ECR_DOCKER,
261-
ipAddressType: ipAddressType,
262-
dnsRecordIpType: dnsRecordIpType,
263-
});
264-
// THEN
265-
}).toThrow();
266-
});
267-
268203
test('import/export', () => {
269204
// GIVEN
270205
const stack2 = new Stack();

0 commit comments

Comments
 (0)