[CDKTF] How to prevent Google Storage Bucket to be destroyed

Hi, I am new to CDKTF so please bear with me if I ask something that’s obvious.

I am implementing a CDKTF stack that provisions a Google Storage bucket. I would like to avoid the bucket being deleted even I destory the stack with cdktf destroy. In the Terraform documentation of Google Storage Bucket resource, there is a force_destroy attribute that can be set to true can achieve this goal. However, in the latest version of the CDKTF Google Provider, there doesn’t seem to be a way to set this force_destroy attribute when instanitating a DataGoogleStorage, as the config type DataGoogleStorageBucketConfig does not seem to include it. (cdktf-provider-google/src/data-google-storage-bucket/index.ts at 3793b2ab85d7bcc8cd13f9fb1caca169e1b5c08e · cdktf/cdktf-provider-google · GitHub) Also it seems a bunch of attributes are missing there. Can I ask if someone can help me out to prevent my bucket being deleted with CDKTF? Many thanks.

You tried prevent_destroy in lifecycle?
https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#prevent_destroy

DataGoogleStorageBucket is a data source. That means it is just used retrieve information that can be used by other resources.
Try using StorageBucket instead which should be use to create one.

1 Like