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?