1
1
import iam = require( '@aws-cdk/aws-iam' ) ;
2
2
3
+ import { IGrantable , IPrincipal } from '@aws-cdk/aws-iam' ;
3
4
import { Construct , Duration , Fn , IResource , Lazy , Resource , Tag } from '@aws-cdk/core' ;
4
5
import { Connections , IConnectable } from './connections' ;
5
6
import { CfnInstance } from './ec2.generated' ;
@@ -14,7 +15,7 @@ import { IVpc, SubnetSelection } from './vpc';
14
15
*/
15
16
const NAME_TAG : string = 'Name' ;
16
17
17
- export interface IInstance extends IResource , IConnectable {
18
+ export interface IInstance extends IResource , IConnectable , IGrantable {
18
19
/**
19
20
* The instance's ID
20
21
*
@@ -179,6 +180,11 @@ export class Instance extends Resource implements IInstance {
179
180
*/
180
181
public readonly role : iam . IRole ;
181
182
183
+ /**
184
+ * The principal to grant permissions to
185
+ */
186
+ public readonly grantPrincipal : IPrincipal ;
187
+
182
188
/**
183
189
* UserData for the instance
184
190
*/
@@ -234,6 +240,7 @@ export class Instance extends Resource implements IInstance {
234
240
this . role = props . role || new iam . Role ( this , 'InstanceRole' , {
235
241
assumedBy : new iam . ServicePrincipal ( 'ec2.amazonaws.com' )
236
242
} ) ;
243
+ this . grantPrincipal = this . role ;
237
244
238
245
const iamProfile = new iam . CfnInstanceProfile ( this , 'InstanceProfile' , {
239
246
roles : [ this . role . roleName ]
@@ -320,4 +327,5 @@ export class Instance extends Resource implements IInstance {
320
327
} ;
321
328
}
322
329
}
330
+
323
331
}
0 commit comments