Expose props as read/write properties in CFN resources and remove propertyOverrides
See original GitHub issuePerfectly reasonable application of aspects came up on Gitter:
Hello, I’m trying to write a custom IAspect which sets the RoleName of any IAM Role in a stack to include a particular prefix (for resource matching in IAM permissions). Unfortunately, this overrides any RoleName that is manually set in the stack itself. Is there a way for an IAspect to check whether an IAM Role already has RoleName set?
To enable this we would need to allow read/write access to the configured properties of a CfnResource
, in a typed fashion (so it needs to be done in cfn2ts
).
We need to think about types and JSII though.
A RoleProps
struct will have readonly
properties for evertyhing, so cannot be mutated. So the syntax will have to be something like:
cfnrole.properties = {
...cfnrole.properties,
roleName: 'MyPrefix-' + cfnrole.properties.roleName
};
Not great…
Same story across JSII, except in Javaland it will be even more annoying to copy the existing properties into a new builder object. We need to generate a “copy constructor” as well then.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
We could also code generate an
IInterface
for that mutable property. This should also feature an arbitrary accessor ([key: string]: any
) so people could leverage properties that did t make it to the spec yet.It’d maintain the namespace-like encapsulation that prevents name collisions from being a problem, and retain the strong typed overrides. It may need a JSII feature to support objects with an index signature.
I’m digging in here, the code needs a little unwinding. Hopefully I’ll have something in a couple of days.