Skip to content

Role.fromRoleArn(mutable: false) creates constructs with the wrong ID #7255

@rix0rrr

Description

@rix0rrr

This PR:

#6920

Broke the following piece of code:

    const existingRole = scope.node.tryFindChild(id) as iam.IRole;
    if (existingRole) {return existingRole; }
   return iam.Role.fromRoleArn(scope, id, arn, { mutable: false });

One would expect the second execution of this code to return the same immutable role that was created on the first go-around.

But in fact, because we create 2 constructs, the mutable one of which has the ID the user requested, the first go-around will return the immutable role as desired, but the second go-around will return the inner, mutable role object, leading to policies being added to a supposedly immutable role.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions