TF CDF w/ Typescript best practices for production

Hi Team,

For all people who are using CDK in production - I am looking at best practices for the code format and declaring whole infrastructure.
Do we need to write everything in main.ts
Do I need to store my JSONs in Code only or I can keep them in MongoDB/S3 and fetch on realtime while deploying.

I would say best practice is not to put everything into main.ts. You should treat organization similar to an application where you divide your code into logical and functional groupings. You can even make reusable pieces and abstractions to share between different projects.

You can definitely fetch data to use. The actual app.synth call is synchronous, so make sure to retrieve data prior to that. Terraform data sources can also be used to retrieve data without having it appear in the synthesized Terraform json (still ends up in Terraform state).

Thanks, what would be the ideal file structure to declare the below resources.
˜100 EC2 Instances
˜10 ECS Clusters
˜10 ELBs
˜10 RDS Instances
˜50 Security Groups
˜5 VPCs

Also - I tried creating another .ts file with some of my resources, but cdktf deploy only picks from main.ts - what are the changes needed to be done there.

If you want to split up your application into separate files you need to import the files from your main.ts. You would typically build abstractions that make sense in your applications context and instantiate them in your main.ts. You can find some examples here;

If you want to see some examples on your specific instance types you can take a look at the End to End Docker example: https://github.com/hashicorp/docker-on-aws-ecs-with-terraform-cdk-using-typescript