Cdktf - programmatically determine if synth is for destroy or for apply

Hi,

I would like to programmatically determine if I am synthing a Stack for apply, or for deletion.

I have the following workflow:
→ network cfg → vms → k8s cluster forming → flux2 setup …

doing it reverse is not possible at the moment, because deleting flux leaves some resources that won’t let me delete it’s namespace.
I could clean/handle this - or don’t care, because afterwards I would delete the whole cluster :slight_smile:

So I would like to not generate the flux2 manifest resources if I am destroying the stack.

Or does terraform has something like “retain” for deletion policys? I didn’t found anything like that (coming from the “real” cdk)

There isn’t a way to detect this currently and I’m not sure adding would get the desired effect.
Terraform keeps a state file which allows it to determine which changes need to be made. Omitting something from the cdktf app would trigger a deletion.

Terraform doesn’t have a lifecycle option to prevent destruction, but that just blocks deleting something and will fail the operation as a whole.

There is a Terraform cli command to remove a resource from it’s state file. This would probably get at what you want, but isn’t the most convenient.