cdktf-aws-cdk
cdktf-aws-cdk copied to clipboard
Support AWS CDK Aspects
Invoke them before converting AWS CDK constructs to CDKTF constructs.
I took a stab at implementing this, but ran into a few issues.
- CDK's
invokeAspects
function isn't exported https://github.com/aws/aws-cdk/blob/eca1bcf0b8a449d07692e6363cefa149b1fe0ce4/packages/aws-cdk-lib/core/lib/private/synthesis.ts#L217. For my proof-of-concept I just copied the function body and that worked, but that's probably not great for anything PR-able. - The Aspect execution order gets really tricky, especially since CDKTF doesn't have any way to tweak that order without arcane tricks (e.g.
Aspects.of(scope)['_aspects'].unshift(new MyAspect(this))
). This means that the Aspect responsible for doing the resource conversion pretty much has to be the last Aspect invoked, otherwise you end up with half-built resources. -
createGuessingResourceMapper
doesn't seem to handle Tags very well. A lot of CloudFormation resources use a type shaped likeArray<{ Key: string; Value: string }>
but most Terraform schemas use something more akin toRecord<string, string>
. Even in CDK there's a whole lot of logic to render tags correctly based on the resource. I'll admit this is mostly solved by #554 but even then tags are gonna be a pain point for any custom mappings.
Aside from those issues the implementation is actually quite simple, as you just have to call invokeAspects
with the CDK scope before host.convert()
. That said, invokeAspects
itself uses CDK Annotations so we need #152 before it can be fully feature-complete.