How do I create a plan with cdktf and terraform apply plan?

Hey folks,

I am trying CDKTF for the first time and I want to create a pipeline that produces a valid plan file so that I can terraform apply plan. The documentation is very vague here and it does not say which commands exactly I should run and in what order

cdktf synth?
cdktf diff?
terraform init?
terraform plan?
terraform apply?

I cannot use cdktf deploy because I want the option to manually review the changes/diff/plan in some cases, and that requires the plan and apply to be in separate pipeline steps

Hi @mpicard :wave:

Thank you for raising that! Running cdktf synth will be enough from the CDKTF side of things. For the required Terraform commands that would be following Terraform best practices – here is a related link from the Terraform docs that we should’ve linked: Running Terraform in Automation | Terraform | HashiCorp Developer

You would also need to run these Terraform CLI commands for the output directory of every stack (if you have multiple stacks).

Hope that helped!

– Ansgar

Hi thanks for answering, the issue is it’s not clear that you must do

cdktf synth
terraform apply cdktf.out/stacks/<stack>/plan

Are there any plans in cdktf to provid a more “cdktf native” approach? e.g have something like a --plan option to the cdktf deploy cli? Or will using the terraform internals be the solution to use for the time being?

I’m not sure if there are any specific plans, but feel free to create a feature request.