Mixing AWS CDK L2 constructs with Terraform CDK L1 constructs

Hi, I am trying to create an S3 bucket using AwsTerraformAdapter and AWS CDK L2 constructs. I started with something like this.

const awsAdapter = new AwsTerraformAdapter(this, 'adapter')

const bucket = new aws_s3.Bucket(awsAdapter, `${id}--bucket`, {
    bucketName: `foo-bar-${env}`,
    eventBridgeEnabled: true,
}

When I tried to run cdktf synth, I got the error message

There is no custom mapping registered for Custom::S3BucketNotifications and the AWS CloudControl API does not seem to support it yet

Since there is no way to generate a mapping for a custom CloudFormation resource, I attempted to bring the Terraform CDK L1 construct into the mix.

import {s3 as tf_s3} from "@cdktf/aws-cdk/lib/aws";

const awsAdapter = new AwsTerraformAdapter(this, 'adapter')

const bucket = new aws_s3.Bucket(awsAdapter, `${id}--bucket`, {
    bucketName: `foo-bar-${env}`,
    eventBridgeEnabled: false,
}
new tf_s3.S3BucketNotification(scope, `${id}--event-brigdge-notification`, {
    bucket: bucket.bucketName,
    eventbridge: true
})

This successfully synthesized the Terraform but bucket.bucketName resolved to ${Token[TOKEN.XXX]}. While AWS CDK with Terraform adapter understands these tokens, Terraform CDK doesn’t. I also tried changing this to,

import {CfnOutput, Fn} from 'aws-cdk-lib'

const bucketNameOutput = new CfnOutput(awsAdapter, `${id}--bucket-name-output`, {
    exportName: `${id}--bucket-name-output`,
    value: bucket.bucketName
})
new tf_s3.S3BucketNotification(this, `${id}--enable-event-bridge`, {
    bucket: Fn.importValue(bucketNameOutput.exportName || ''),
    eventbridge: props.eventBridgeEnabled || false,
})

But that resulted in a similar resolution of the bucket name into a token.

Is interop between the AWS and Terraform CDK constructs even possible? If yes, what am I missing here?

Hi @aa8y,

were you able to find out whether there was a bug in your code somewhere?
Using tokens of both token systems (AWS CDK vs CDKTF) is not completely tested at the moment, so there might be problems we still need to fix for this to work.

– Ansgar

I don’t believe there was any bug in my code. At the moment, it seems like CDKTF L1 are incompatible with AWS CDK L2 constructs (using AwsTerraformAdapter). We just had to fall back to fully using L1 constructs to unblock ourselves.