Resolve `Role.fromRoleArn()` to `roleName` instead of first path element
-
I'm submitting a ...
- [ ] :beetle: bug report
- [x] :rocket: feature request
- [ ] :books: construct library gap
- [ ] :phone: security issue or vulnerability => Please see policy
- [ ] :question: support request => Please see note at the top of this template.
-
What is the current behavior?
const adminRole = Fn.importValue('admin-role-arn') // arn: ....:role/users/admin-role
const role = Role.fromRoleArn(adminRole)
Now role.roleName will eventually be resolved to the first path component, i.e. users
- What is the expected behavior (or behavior of feature suggested)?
Expected behavior is returning the role name, i.e., admin-role.
I understand that this is not possible.
- What is the motivation / use case for changing the behavior or adding this feature?
In our organization all user-assumable IAM Roles have the path users so that this path can be used in IAM Policies. We need to refer to existing IAM Roles from within a CDK App.
-
Please tell us about your environment:
- CDK CLI Version: 1.2.0
- Module Version: 1.2.0
- OS: OSX Mojave
- Language: all
-
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
My current workaround is allowing the user to specify the depth of the path so that the real role name can be selected:
public static fromRoleArn(scope: Construct, id: string, roleArn: string, pathDepth: number = 0): IRole {
...
public readonly roleName = Fn.select(pathDepth + 1, Fn.split('/', roleArn))
...
}
Hi @tader,
I'm not sure I'm quite understanding the bug being reported. From what I understand, role.fromRoleArn is documented to resolve to the first element of the path if provided with a path.
Its certainly a parameter limitation, but I'm not sure it is a bug.
We can shift this to a feature-request for implementation down the line, but we are somewhat limited by Cloudformation.
Let me know if I'm off or missing something!
Hi @NGL321,
I was uncertain myself if it would count as a bug or a feature request... Turning it in a feature request is fine with me. What I would like is a way to be able to use it without having to wait on the CloudFormation team to provide an Fn::Slice function. For now, I just copy-pasted the code and added the pathDepth argument.
Hi @NGL321,
I was uncertain myself if it would count as a bug or a feature request... Turning it in a feature request is fine with me. What I would like is a way to be able to use it without having to wait on the CloudFormation team to provide an Fn::Slice function. For now, I just copy-pasted the code and added the pathDepth argument.
Sounds good! I have adjusted this into a feature request. Someone from the team will make note here if there is movement!
Because of a lack of CloudFormation primitives to do slicing, this is an issue that can never be resolved.
We should document the limitation that objects with paths cannot be imported this way.