diff --git a/packages/@aws-cdk/aws-ec2/lib/instance.ts b/packages/@aws-cdk/aws-ec2/lib/instance.ts index 75878d86eab75..d86d047438c47 100644 --- a/packages/@aws-cdk/aws-ec2/lib/instance.ts +++ b/packages/@aws-cdk/aws-ec2/lib/instance.ts @@ -167,6 +167,15 @@ export interface InstanceProps { * @default true */ readonly sourceDestCheck?: boolean; + + /** + * Defines a private IP address to associate with an instance. + * + * Private IP should be available within the VPC that the instance is build within. + * + * @default - no association + */ + readonly privateIpAddress?: string } /** @@ -284,6 +293,7 @@ export class Instance extends Resource implements IInstance { subnetId: subnet.subnetId, availabilityZone: subnet.availabilityZone, sourceDestCheck: props.sourceDestCheck, + privateIpAddress: props.privateIpAddress }); this.instance.node.addDependency(this.role); diff --git a/packages/@aws-cdk/aws-ec2/test/test.instance.ts b/packages/@aws-cdk/aws-ec2/test/test.instance.ts index bbaea12bc9299..66513308c9fd5 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.instance.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.instance.ts @@ -100,6 +100,27 @@ export = { }, })); + test.done(); + }, + 'instance can be created with Private IP Address'(test: Test) { + // GIVEN + const stack = new Stack(); + const vpc = new Vpc(stack, 'VPC'); + + // WHEN + new Instance(stack, 'Instance', { + vpc, + machineImage: new AmazonLinuxImage(), + instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE), + privateIpAddress: "10.0.0.2" + }); + + // THEN + expect(stack).to(haveResource('AWS::EC2::Instance', { + InstanceType: 't3.large', + PrivateIpAddress: '10.0.0.2' + })); + test.done(); }, };