Skip to content

Commit

Permalink
feat(autoscaling): bring your own IAM role
Browse files Browse the repository at this point in the history
Allow specifying an IAM role (`IRole`) when defining an AutoScalingGroup. This allows
either passing a role created in the same stack or passing in an imported role.

Fixes #1701
  • Loading branch information
Elad Ben-Israel committed Feb 11, 2019
1 parent 016a5d6 commit 9d20aee
Show file tree
Hide file tree
Showing 4 changed files with 666 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
* AMI to launch
*/
machineImage: ec2.IMachineImageSource;

/**
* An IAM role to associate with the instance profile assigned to this Auto Scaling Group.
* @default A role will automatically be created, it can be accessed via the `role` property
*/
role?: iam.IRole;
}

/**
Expand Down Expand Up @@ -187,7 +193,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
/**
* The IAM role assumed by instances of this fleet.
*/
public readonly role: iam.Role;
public readonly role: iam.IRole;

/**
* Name of the AutoScalingGroup
Expand Down Expand Up @@ -217,7 +223,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
this.securityGroups.push(this.securityGroup);
this.apply(new cdk.Tag(NAME_TAG, this.node.path));

this.role = new iam.Role(this, 'InstanceRole', {
this.role = props.role || new iam.Role(this, 'InstanceRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});

Expand Down
Loading

0 comments on commit 9d20aee

Please sign in to comment.