With Terraform, I have used e.g. terraform state ...
, terraform import ...
, and terraform taint
to manipulate the state.
With AWS CDK, I only see an option to import existing resources into the CloudFormation stack:
cdk import [STACK]
Currently, I'm facing an issue, where AWS CDK (CloudFormation) believes an S3 bucket exists, which it doesn't, as it was removed manually. Terraform would detect this, as it performs a "refresh" on terraform plan
and terraform apply
. Furthermore, with Terraform I would be able to remove the S3 bucket from the state manually using terraform state rm ...
.
How can I make AWS CDK perform a refresh and manipulate state manually?
The equivalent of a "state refresh" in CloudFormation is Drift detection. It has to be triggered manually, check the docs here.
CloudFormation does not remediate drift automatically - you'd have to do that manually by importing the bucket into the stack.
Not all resources support drift detection and import, but S3 Buckets support both. You can check the list of supported resources here.
Another solution that @kichik suggested in the comments would also work - triggering any change that would result in a resource replacement (like changing the construct ID) would force CloudFormation to create a new resource.