GET Resource object or ResourceConfig object from State File in CDK

Hi All,

I’m building a functionality for partial update in terraform cdk. So the idea is if I have a stack created, say with a S3Bucket and an IamPolicy. And now the user wants to update the tags of the S3Bucket, my code should:

  1. Take the new Tags from user as input
  2. Fetch the current state of the resource through CDK as S3Bucket object or S3BucketConfig object
  3. Override the tags params
  4. Use the modified state to do terraform apply

How can the 2nd step be achieved in CDK?
Also, has anyone tried something similar before? I would love to know your experience building this functionality.

This goes against the declarative nature of terraform, so it would be an uphill battle. If your stack takes tags as TerraformVariables for example you could set them to the new value and deploy the stack again. Terraform will only do the smallest change possible so only the tags will be updated.

This is where I am unsure how a user would do this, are they editing some Construct code, sending an API request? If it’s the latter you could write e.g. edit a varfile that you can then use in your cdktf deploy invocation (we added support for this in 0.15).