Company
Date Published
Author
Will Jones
Word count
5270
Language
English
Hacker News points
None

Summary

Pulumi, a declarative infrastructure tool, has introduced resource hooks, allowing users to execute custom code during any point in a resource's lifecycle from version 3.182.0 onward. These hooks provide a way for users to engage more deeply with Pulumi's operations by attaching callbacks to create, update, and delete actions, offering the flexibility to run arbitrary code before or after these operations. This feature enables scenarios such as setting up SSH tunnels before creating resources or sending metrics to a data warehouse when resources are updated. The hooks can be used within Pulumi's command provider, allowing for complex operations like opening a local TCP port and forwarding it to a remote host before executing a command, as illustrated by a contrived example of using the command provider to invoke curl. Another practical application is in the deployment of an EC2 web server, where resource hooks are used to perform health checks, ensuring the server is operational before Pulumi finalizes the deployment. Such hooks are a significant enhancement, expanding Pulumi's capabilities for handling custom scripts, collecting logs, and performing application health checks, although they require the use of the --run-program flag for refresh and destroy operations.