Notification policies in Spacelift allow you to create custom notifications that can be routed to the notification inbox, Slack, or webhooks to give you the information you need to manage your deployments. These policies are Space aware and apply to components in the same or inherited Spaces. You can also configure filters to ensure you only get the notifications you need and cut out the rest of the noise.
Let’s take a look at a simple example of a notification policy.
This policy will send a notification to the notification inbox with a severity level of “info” every time a tracked run finishes. This notification will create a link to the run id to allow you to access the run information and see what happened in the run.
Also, notice the Space is the “root” Space. If you wish to allow all Spaces with inheritance enabled to be part of the notification policy, this is probably the Space in which you should save your policy.
The copyable version of the policy is here:
package spacelift
inbox[{
"title": "Tracked run finished!",
"body": sprintf("http://saturnhead.app.spacelift.io/stack/%s/run/%s has finished", [stack.id, run.id]),
"severity": "INFO",
}] {
stack := input.run_updated.stack
run := input.run_updated.run
run.type == "TRACKED"
run.state == "FINISHED"
}
sample { true }
Let’s take a look at one more example that notifies on a tracked run failure. I’ll just paste the relevant policy code below:
package spacelift
inbox[{
"title": "Tracked run failed!",
"body": sprintf("http://saturnhead.app.spacelift.io/stack/%s/run/%s has failed", [stack.id, run.id]),
"severity": "ERROR",
}] {
stack := input.run_updated.stack
run := input.run_updated.run
run.type == "TRACKED"
run.state == "FAILED"
}
sample { true }
As you can see, I have changed the “severity” to “ERROR”, the message to indicate the run has failed, and the run.state
to “FAILED” instead of “FINISHED”. A pretty simple modification, and we now have notifications for all finished and failed runs.
Perfect!
Check out this short video with the Notification Policy introduction:
As you can see, the notification policy feature is extremely valuable and powerful when auditing and managing your infrastructure deployments. Much more information can be found in the documentation.
I hope you enjoy the new feature and keep deploying!
The most flexible management platform for Infrastructure as Code
Spacelift is a flexible orchestration solution for IaC development. It delivers enhanced collaboration, automation and controls to simplify and accelerate the provisioning of cloud based infrastructures.