Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ec2): VpnConnection fails if ip is a Token #12923

Merged
merged 3 commits into from Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ec2/lib/vpn.ts
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
@@ -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();
},
});