Skip to content

Commit

Permalink
fix(nx-aws-cdk): fix role checking method
Browse files Browse the repository at this point in the history
  • Loading branch information
NarongOk committed Nov 20, 2024
1 parent 7569088 commit 0c37441
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions libs/aws-cdk-stack/src/lib/stacks/role-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ export class RoleStack extends Stack {
constructor(scope: Construct, id: string, _props: RoleStackProperties) {
super(scope, id, _props);

const existingRole: IRole = this.getExistingRole(_props.name);
if (_props.existingRole || existingRole) {
if (_props.existingRole) {
const existingRole: IRole = Role.fromRoleName(
this,
_props.name,
_props.name,
{}
);
existingRole;
this.output = { role: existingRole };
} else {
logger.debug(`creating role -- ${_props.name}`);
Expand All @@ -22,15 +28,4 @@ export class RoleStack extends Stack {
this.output = { role: newRole };
}
}

private getExistingRole(roleName: string): IRole {
try {
const role = Role.fromRoleName(this, roleName, roleName, {});
console.log('Instance role exists:', role.roleName);
return role;
} catch (error) {
console.log('Instance role does not exist:', error.message);
return null;
}
}
}

0 comments on commit 0c37441

Please sign in to comment.