Skip to content

Commit

Permalink
fix(ec2): VpnConnection fails if ip is a Token (aws#12923)
Browse files Browse the repository at this point in the history
Add support to use Token for `VpnConnectionProps.ip` and skip `net.isIPv4(...)` validation in that case.

Fixes issue aws#11633 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jwoehrle authored and NovakGu committed Feb 18, 2021
1 parent e505f4d commit 855c3f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ec2/lib/vpn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class VpnConnection extends Resource implements IVpnConnection {
});
}

if (!net.isIPv4(props.ip)) {
if (!Token.isUnresolved(props.ip) && !net.isIPv4(props.ip)) {
throw new Error(`The \`ip\` ${props.ip} is not a valid IPv4 address.`);
}

Expand Down
22 changes: 21 additions & 1 deletion packages/@aws-cdk/aws-ec2/test/vpn.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Duration, Stack } from '@aws-cdk/core';
import { Duration, Stack, Token } from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { PublicSubnet, Vpc, VpnConnection } from '../lib';

Expand Down Expand Up @@ -322,4 +322,24 @@ nodeunitShim({
}));
test.done();
},
'can add a vpn connection with a Token as customer gateway ip'(test:Test) {
// GIVEN
const stack = new Stack();
const token = Token.asAny('192.0.2.1');

// WHEN
new Vpc(stack, 'VpcNetwork', {
vpnConnections: {
VpnConnection: {
ip: token as any,
},
},
});

// THEN
expect(stack).to(haveResource('AWS::EC2::CustomerGateway', {
IpAddress: '192.0.2.1',
}));
test.done();
},
});

0 comments on commit 855c3f4

Please sign in to comment.