Skip to content

Commit f32431a

Browse files
authored
fix(ecs): make TaskDefinition accept IRoles (#2034)
The role input parameters are currently Roles but should be IRoles. Required adding the grant methods to the `IRole` definition, which weren't there before. Fixes #1925.
1 parent 1e50383 commit f32431a

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export interface CommonTaskDefinitionProps {
2323
*
2424
* @default An execution role will be automatically created if you use ECR images in your task definition
2525
*/
26-
executionRole?: iam.Role;
26+
executionRole?: iam.IRole;
2727

2828
/**
2929
* The IAM role assumable by your application code running inside the container
3030
*
3131
* @default A task role is automatically created for you
3232
*/
33-
taskRole?: iam.Role;
33+
taskRole?: iam.IRole;
3434

3535
/**
3636
* See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide//task_definition_parameters.html#volumes
@@ -112,7 +112,7 @@ export class TaskDefinition extends cdk.Construct {
112112
/**
113113
* Task role used by this task definition
114114
*/
115-
public readonly taskRole: iam.Role;
115+
public readonly taskRole: iam.IRole;
116116

117117
/**
118118
* Network mode used by this task definition

packages/@aws-cdk/aws-iam/lib/lazy-role.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cdk = require('@aws-cdk/cdk');
2-
import { Policy } from './policy';
2+
import { IPrincipal, Policy } from './policy';
33
import { PolicyPrincipal, PolicyStatement } from './policy-document';
44
import { IRole, Role, RoleImportProps, RoleProps } from './role';
55

@@ -85,6 +85,20 @@ export class LazyRole extends cdk.Construct implements IRole {
8585
return this.instantiate().principal;
8686
}
8787

88+
/**
89+
* Grant the actions defined in actions to the identity Principal on this resource.
90+
*/
91+
public grant(identity?: IPrincipal, ...actions: string[]): void {
92+
return this.instantiate().grant(identity, ...actions);
93+
}
94+
95+
/**
96+
* Grant permissions to the given principal to pass this role.
97+
*/
98+
public grantPassRole(identity?: IPrincipal): void {
99+
return this.instantiate().grantPassRole(identity);
100+
}
101+
88102
private instantiate(): Role {
89103
if (!this.role) {
90104
const role = new Role(this, 'Default', this.props);
@@ -95,4 +109,4 @@ export class LazyRole extends cdk.Construct implements IRole {
95109
}
96110
return this.role;
97111
}
98-
}
112+
}

packages/@aws-cdk/aws-iam/lib/role.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ export interface IRole extends IConstruct, IPrincipal {
245245
* Export this role to another stack.
246246
*/
247247
export(): RoleImportProps;
248+
249+
/**
250+
* Grant the actions defined in actions to the identity Principal on this resource.
251+
*/
252+
grant(identity?: IPrincipal, ...actions: string[]): void;
253+
254+
/**
255+
* Grant permissions to the given principal to pass this role.
256+
*/
257+
grantPassRole(identity?: IPrincipal): void;
248258
}
249259

250260
function createAssumeRolePolicy(principal: PolicyPrincipal, externalId?: string) {
@@ -331,4 +341,18 @@ class ImportedRole extends Construct implements IRole {
331341
public attachManagedPolicy(_arn: string): void {
332342
// FIXME: Add warning that we're ignoring this
333343
}
344+
345+
/**
346+
* Grant the actions defined in actions to the identity Principal on this resource.
347+
*/
348+
public grant(_identity?: IPrincipal, ..._actions: string[]): void {
349+
// FIXME: Add warning that we're ignoring this
350+
}
351+
352+
/**
353+
* Grant permissions to the given principal to pass this role.
354+
*/
355+
public grantPassRole(_identity?: IPrincipal): void {
356+
// FIXME: Add warning that we're ignoring this
357+
}
334358
}

0 commit comments

Comments
 (0)