Skip to content

Commit 87f096e

Browse files
hoegertnmergify[bot]
authored andcommitted
feat(ec2): let Instance be IGrantable (#4190)
1 parent e17bfc3 commit 87f096e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/@aws-cdk/aws-ec2/lib/bastion-host.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IRole, PolicyStatement } from "@aws-cdk/aws-iam";
1+
import { IPrincipal, IRole, PolicyStatement } from "@aws-cdk/aws-iam";
22
import { CfnOutput, Construct, Stack } from "@aws-cdk/core";
33
import { AmazonLinuxGeneration, AmazonLinuxImage, InstanceClass, InstanceSize, InstanceType } from ".";
44
import { Connections } from "./connections";
@@ -81,6 +81,11 @@ export class BastionHostLinux extends Construct implements IInstance {
8181
*/
8282
public readonly role: IRole;
8383

84+
/**
85+
* The principal to grant permissions to
86+
*/
87+
public readonly grantPrincipal: IPrincipal;
88+
8489
/**
8590
* The underlying instance resource
8691
*/
@@ -137,6 +142,7 @@ export class BastionHostLinux extends Construct implements IInstance {
137142

138143
this.connections = this.instance.connections;
139144
this.role = this.instance.role;
145+
this.grantPrincipal = this.instance.role;
140146
this.instanceId = this.instance.instanceId;
141147
this.instancePrivateIp = this.instance.instancePrivateIp;
142148
this.instanceAvailabilityZone = this.instance.instanceAvailabilityZone;

packages/@aws-cdk/aws-ec2/lib/instance.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import iam = require('@aws-cdk/aws-iam');
22

3+
import { IGrantable, IPrincipal } from '@aws-cdk/aws-iam';
34
import { Construct, Duration, Fn, IResource, Lazy, Resource, Tag } from '@aws-cdk/core';
45
import { Connections, IConnectable } from './connections';
56
import { CfnInstance } from './ec2.generated';
@@ -14,7 +15,7 @@ import { IVpc, SubnetSelection } from './vpc';
1415
*/
1516
const NAME_TAG: string = 'Name';
1617

17-
export interface IInstance extends IResource, IConnectable {
18+
export interface IInstance extends IResource, IConnectable, IGrantable {
1819
/**
1920
* The instance's ID
2021
*
@@ -179,6 +180,11 @@ export class Instance extends Resource implements IInstance {
179180
*/
180181
public readonly role: iam.IRole;
181182

183+
/**
184+
* The principal to grant permissions to
185+
*/
186+
public readonly grantPrincipal: IPrincipal;
187+
182188
/**
183189
* UserData for the instance
184190
*/
@@ -234,6 +240,7 @@ export class Instance extends Resource implements IInstance {
234240
this.role = props.role || new iam.Role(this, 'InstanceRole', {
235241
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
236242
});
243+
this.grantPrincipal = this.role;
237244

238245
const iamProfile = new iam.CfnInstanceProfile(this, 'InstanceProfile', {
239246
roles: [this.role.roleName]
@@ -320,4 +327,5 @@ export class Instance extends Resource implements IInstance {
320327
};
321328
}
322329
}
330+
323331
}

0 commit comments

Comments
 (0)