Running terraform init -migrate-state via CDKTF

Hi,

This is my first post here, so I apologise if I’m missing any structure required for forum posts.

When I run npx cdktf diff sr-test the following error is produced:

         │ Error: Backend configuration changed
         │
         │ A change in the backend configuration has been detected, which may require
         │ migrating existing state.
         │
         │ If you wish to attempt automatic migration of the state, use "terraform init
         │ -migrate-state".
         │ If you wish to store the current configuration with no changes to the state,
         │ use "terraform init -reconfigure".

My issue is that I cannot figure out how to perform these terraform commands via CDKTF. Running the suggested terraform command throws the following error:

Terraform initialized in an empty directory!

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.
zsh: command not found: │

I looked through the hashicorp forums and couldn’t find anyone who has ran into this issue and has had a solution presented, I also couldn’t find much information at all about the cdktf equivalent of terraform commands.

I have been deploying resources via the AWS Console and have refactored my cdktf project quite a lot, but I figured there should be some way of resolving these conflicts beyond delete the s3 backend and recreating it.

Thanks!

Possible workarounds:

  1. Once the .tf.json is generated by cdktf synth or the .tf file by cdktf synth --hcl, you can use the plain old terraform command line interface with it. Just change to the directory it’s in and run terraform init -migrate-state. Here’s an example explanation for changing directory and running terraform import: How to import already created AWS resources in TF CDK - #11 by DanielMSchmidt

  2. You may be able to find the difference in the backend configuration and remove it if it’s unnecessary. I used .add_override() recently to get to CDKTF first, and migrate state later.

I use CDKTF extensively as a Python to HCL conversion library but stick with terraform on the command line (I don’t think it’s broken or in need of replacement).