Pulumi Webhook Handler
This example creates a Pulumi cloud.HttpEndpoint
that will receive webhook events delivered
by Pulumi Cloud. It then echos the event to Slack.
Prerequisites
Steps
After cloning this repo, run these commands from the working directory:
Install prerequisites:
npm install
Create a new Pulumi stack, which is an isolated deployment target for this example:
pulumi stack init
Create a Slack App:
Give your app the
incoming-webhook
scope.Add your Slack app to the Slack channel in which you want to post webhook events.
Set the region for this program:
pulumi config set aws:region <your-region>
Set the Slack webhook for your app. You can find yours by going to
Features -> Incoming Webhooks
from your Slack app’s API page.pulumi config set slackWebhook --secret <webhook-url>
Set the Slack channel for your app. This should be the same channel in which you added your Slack app. For example,
#pulumi-events
.pulumi config set slackChannel <your-channel>
(Optional) Set the shared secret for your app. Webhook deliveries can optionally be signed with a shared secret token. The shared secret is given to Pulumi, and will be used to verify the contents of the message. You can find yours by going to
Settings -> Basic Information -> Signing Secret
from your Slack app’s API page.pulumi config set sharedSecret --secret <your-secret>
Execute the Pulumi program:
pulumi up
Retrieve our new URL:
pulumi stack output url
Create a Pulumi webhook. Use the output from the previous step as the
Payload URL
.Ping our webhook by clicking
Ping
underDeliveries
from your webhook’s page. You should see the messageJust a friendly ping from Pulumi
in your Slack channel.From there, feel free to experiment. Simply making edits and running
pulumi up
will update your program.Afterwards, destroy your stack and remove it:
pulumi destroy --yes pulumi stack rm --yes
Troubleshooting
Message Delivery
If you aren’t seeing webhook deliveries in Slack, there are several places to look for more information.
- Pulumi Cloud: If you go to the webhook’s page within the Pulumi console, you can navigate to recent webhook deliveries. If Pulumi Cloud has any trouble contacting your webhook handler, you will see the error there.
- The Pulumi stack’s logs: If the webhooks are being delivered, but aren’t showing up in Slack for some
reason, you can view the webhook handler’s runtime logs by running the
pulumi logs
command.