Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS CDK Aspects #153

Open
ansgarm opened this issue Oct 22, 2021 · 1 comment
Open

Support AWS CDK Aspects #153

ansgarm opened this issue Oct 22, 2021 · 1 comment

Comments

@ansgarm
Copy link
Member

ansgarm commented Oct 22, 2021

Invoke them before converting AWS CDK constructs to CDKTF constructs.

@ansgarm ansgarm added the enhancement New feature or request label Oct 22, 2021
@xiehan xiehan transferred this issue from hashicorp/terraform-cdk Jun 1, 2023
@xiehan xiehan added the backlog label Jun 1, 2023
@xiehan xiehan changed the title AWS Adapter: Support AWS CDK Aspects Support AWS CDK Aspects Jun 29, 2023
@xiehan xiehan added this to the General Availability milestone Jun 29, 2023
@sapslaj
Copy link

sapslaj commented Feb 21, 2024

I took a stab at implementing this, but ran into a few issues.

  1. 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.
  2. 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.
  3. createGuessingResourceMapper doesn't seem to handle Tags very well. A lot of CloudFormation resources use a type shaped like Array<{ Key: string; Value: string }> but most Terraform schemas use something more akin to Record<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 Remove custom mappings for resources that are supported by Cloud Control API #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants