Skip to content

Commit

Permalink
chore(ec2): add missing test to Instance (#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegertn authored and mergify[bot] committed Sep 27, 2019
1 parent 7adb5ea commit 4620552
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/test.instance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { StringParameter } from '@aws-cdk/aws-ssm';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { AmazonLinuxImage, Instance, InstanceClass, InstanceSize, InstanceType, Vpc } from "../lib";
Expand Down Expand Up @@ -42,6 +43,63 @@ export = {
SourceDestCheck: false,
}));

test.done();
},
'instance is grantable'(test: Test) {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');
const param = new StringParameter(stack, 'Param', {stringValue: 'Foobar'});
const instance = new Instance(stack, 'Instance', {
vpc,
machineImage: new AmazonLinuxImage(),
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.LARGE),
});

// WHEN
param.grantRead(instance);

// THEN
expect(stack).to(haveResource('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: [
"ssm:DescribeParameters",
"ssm:GetParameters",
"ssm:GetParameter",
"ssm:GetParameterHistory"
],
Effect: "Allow",
Resource: {
"Fn::Join": [
"",
[
"arn:",
{
Ref: "AWS::Partition"
},
":ssm:",
{
Ref: "AWS::Region"
},
":",
{
Ref: "AWS::AccountId"
},
":parameter",
{
Ref: "Param165332EC"
}
]
]
}
}
],
Version: "2012-10-17"
},
}));

test.done();
},
};

0 comments on commit 4620552

Please sign in to comment.