Skip to content

Commit

Permalink
feat(ec2): add privateIpAddress to Instance
Browse files Browse the repository at this point in the history
Add an optional privateIpAddress prop to the Instance class to allow the specification of a Private IP address

Fixes #4004
  • Loading branch information
ialford authored and rix0rrr committed Dec 18, 2019
1 parent 1e5fad9 commit a00906d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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);

Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
};

0 comments on commit a00906d

Please sign in to comment.