How to import already created AWS resources in TF CDK

Hi Team,

I’ve been working with TF CDK and able to complete a successful POC - I am looking for ways to import the already existing entities on my AWS Console.

If the existing resources were created with Terraform, you can use the from-terraform-project when initializing a cdktf project to convert the configuration. You’ll likely need to tweak a couple things by hand, but then you should be good to go.

If they weren’t created with Terraform, you have a couple options.

  • Use a tool to generate Terraform and then follow the above procedure. I have not personally used any of these tools, so I can’t speak to how will that will work.
  • Create cdktf code that mirrors the structure of the existing resource. You can then use Terraform to import the existing resources into the new configuration. See Import - Terraform by HashiCorp for more information on importing.

I used Terraform import for existing resources using cdktf code which mirrors the existing structure and it works perfectly.

Hi,

Are you able to modify the imported instances now easily?

Once imported terraform will make the required changes when you update your code and deploy

I’m trying to do this myself. Are you able to provide a code example? It would be very much appreciated.

There isn’t really a code sample to provide. The cdktf code needs to exactly match the existing resources that you are tying to import. There may be some tools that would help there, but you can also write by hand. You may need to use overrideLogicalId to make sure the resource names match.