I have an existing project with a lot of terraform files, and it would be nice to switch to using typescript to define them, and Ideally I’d like to rewrite the definitions for existing resources in typescript. Is it possible to import the existing terraform state files into the synthesized output from the CLI?
Is it possible to reuse the state from an existing project that uses the terraform CLI?
It’s currently rather difficult to reference existing state. Take a look here for some more information.
If tearing down and rebuilding is an option, then hcl2cdktf might be of use.
Most of it can be torn down, but the frontend is deployed through a cloudfront distribution with a custom domain, and I’ve found that AWS won’t let you immediately reuse the domain name for a new distribution. I also have dynamodb tables that would need to be backed up and restored, which I’d rather avoid if possible.
For an existing hand-written configuration being replaced with a CDK-generated one, I think the shortest path (assuming you want to keep all of the existing objects) would be to use
terraform mv to translate from the names you originally chose manually to the names that the CDK tool is choosing for you. The underlying Terraform will then just see this as a new name for the existing object, rather than as a new object.