Repository: cdklabs/cdk-enterprise-iac (language: python)

Issue:
bug: Adding permissions boundaries can include spaces in a role name
### What is the problem?

If a role has spaces in it's ID, the generated name of a role/policy/instanceprofile will include the space in it's name, violating the naming convention

### Reproduction Steps

```ts
new Role(stack,  'A Role With Spaces In name', {
  assumedBy: new ServicePrincipal('ec2.amazonaws.com')
})
Aspects.of(stack).add(
  new AddPermissionBoundary({
    permissionsBoundaryPolicyName: 'somePBName',
    rolePrefix: 'Bananas_',
  })
);
```

Generates a policy name of
```yaml
RoleName: "Bananas_Default-A Role With Spaces In name-Resource"
```

### What did you expect to happen?

A `RoleName` that doesn't violate Role name policy of `_+=,.@-`. [Ref](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-rolename)

### What actually happened?

A cloudformation error due to `RoleName` violating the naming convention

### cdk-enterprise-iac version

0.0.52

### Language

Python

### Other information

_No response_


Discussion / hints:

Fix patch:
diff --git a/src/patches/addPermissionsBoundary.ts b/src/patches/addPermissionsBoundary.ts
index 869d710..55c2a7d 100644
--- a/src/patches/addPermissionsBoundary.ts
+++ b/src/patches/addPermissionsBoundary.ts
@@ -66,11 +66,11 @@ export class AddPermissionBoundary implements IAspect {
   ): void {
     if (!cdkProp?.startsWith(prefix)) {
       const policySuffix = !Token.isUnresolved(cdkProp)
-        ? cdkProp
+        ? (cdkProp as string)
         : getResourceId(node.node.path);
       node.addPropertyOverride(
         cfnProp,
-        `${prefix}${policySuffix}`.substring(0, length - 1)
+        `${prefix}${policySuffix.replace(/\s/g, '')}`.substring(0, length - 1)
       );
     }
   }


Test patch:
diff --git a/test/patches/addPermissionsBoundary.test.ts b/test/patches/addPermissionsBoundary.test.ts
index dbca5f4..be9e826 100644
--- a/test/patches/addPermissionsBoundary.test.ts
+++ b/test/patches/addPermissionsBoundary.test.ts
@@ -104,6 +104,22 @@ describe('Permissions Boundary patch', () => {
         },
       });
     });
+    test('Roles with spaces in id are supported', () => {
+      const idWithSpaces: string = 'A Role With Spaces In name';
+      new Role(stack, idWithSpaces, {
+        assumedBy: new ServicePrincipal('ec2.amazonaws.com'),
+      });
+      Aspects.of(stack).add(
+        new AddPermissionBoundary({
+          permissionsBoundaryPolicyName: pbName,
+          rolePrefix: 'Bananas_',
+        })
+      );
+      const template = Template.fromStack(stack);
+      template.hasResourceProperties('AWS::IAM::Role', {
+        RoleName: `Bananas_Default-${idWithSpaces.replace(/\s/g, '')}-Resource`,
+      });
+    });
   });
   describe('Policies', () => {
     const policyPrefix = 'POLICY_PREFIX_';