busser / tfautomv

Generate Terraform moved blocks automatically for painless refactoring
https://github.com/busser/tfautomv
Apache License 2.0
682 stars 24 forks source link

Support cdktf #92

Closed keidarcy closed 2 months ago

keidarcy commented 2 months ago

Hi, tfautomv is a great idea!

It would be nice to support cdktf, even only supports generating terraform state mv commands 😄.

busser commented 2 months ago

Hi! I've never used cdktf before, but based on these docs it seems that the cdktf synth command generates Terraform code. Have you tried running tfautomv -o commands in these generated directories? 🤔

keidarcy commented 2 months ago

Hi, I tested a little bit more. tfautomv works find with cdktf!

Maybe some resources, not supported yet? In my case, an aws s3 bucket is ok, but aws_kinesis_firehose_delivery_stream is not.

s3

$ tfautomv --output=commands
getting Terraform plan for current directory...

┌─ Summary
│ tfautomv made 1 comparison and found 1 move
│
│ 1 move within current directory
└─

terraform state mv "aws_s3_bucket.name_1_XXXXXXX" "aws_s3_bucket.name_2_YYYYYYY"
1 move written to standard output

aws_kinesis_firehose_delivery_stream

$ tfautomv --output=commands
getting Terraform plan for current directory...

┌─ Summary
│ tfautomv made 1 comparison and found 0 moves
│
│ 0 matches for aws_cloudwatch_metric_stream.name_1_XXXXXXX (create) in current directory
│
│ 0 matches for aws_cloudwatch_metric_stream.name_2_YYYYYYY (delete) in current directory
└─
busser commented 2 months ago

tfautomv is provider- and resource-agnostic. I suggest increasing verbosity to understand what differences it's seeing between those two resources. You can find more info about that here: Understanding why a resource was not moved.

Since tfautomv seems to work with cdktf, I'll close this issue. If we discover any problems in the future, I'm open to adding better integration :)

busser commented 2 months ago

For anyone coming upon this issue in the future:

Running cdktf synth generates Terraform stacks. Running tfautomv within those stacks seems to work.