How do you use Pulumi to destroy resources like Cl...
# general
f
How do you use Pulumi to destroy resources like CloudFront distributions (which need to be disabled before they can be destroyed) that require other operations to be preformed before they can be removed. I cannot seem to find a way to add custom destroy logic to a Pulumi stack. Does anyone have experience doing this? (Stackoverflow question here: https://stackoverflow.com/questions/55730860/custom-pulumi-destroy-logic)
w
There is not yet a first-class feature for adding custom logic to resource deletion. The closest thing that you can do today is using Dynamic Providers. These allow you to write a new kind of resource whose Create, Read, Update and Delete operations are defined in JavaScript, and so can put your custom logic in the Delete operation of this resource, and then make your CloudFront resource dependent on this custom resource so that it must be deleted before attempting to delete the CoudFront distribution. We have limited documentation on these Dynamic Providers currently (I will be adding some docs soon!) - but you can see one example of this here: https://github.com/pulumi/examples/blob/733235b50e8fbe7d7fe76103e09a70b143d9316d/aws-ts-ec2-provisioners/provisioner.ts That said, I have not seen issues destroying CloudFront distributions in the past. What specifically are the "other operations" you need to do prior to deleting it in your case?
m
@fierce-carpet-95079 can you post the specific error as well? The error had to do with not being able to destroy an enabled cloudfront distro.
f
So sorry! We were acutally able to track down the issue to a statefile/reality miss-match. Sorry for the false alarm. We are though experiencing an issue with the destruction sequencing. Such as the bucket destroy fails because the bucket objects are not deleted yet. A second run of the destroy removes all the failed resources but I was wondering how we needed to declare it to get proper sequencing.