Event Architecture
Events flow through Infrahub in this pattern:- Action occurs (node created, branch merged, etc.)
- Event emitted to Prefect event system
- Triggers evaluate event against conditions
- Automations execute matching workflows/webhooks
Event Types
Node Events
Emitted when nodes are created, updated, or deleted:infrahub.node.createdinfrahub.node.updatedinfrahub.node.deleted
Branch Events
Emitted for branch lifecycle operations:Repository Events
Emitted when repositories change:infrahub.repository.createdinfrahub.repository.updatedinfrahub.repository.deleted
Artifact Events
infrahub.artifact.createdinfrahub.artifact.updatedinfrahub.artifact.generated
Generator Events
infrahub.generator.executedinfrahub.generator.completed
Schema Events
infrahub.schema.updatedinfrahub.schema.validated
Proposed Change Events
infrahub.proposed_change.createdinfrahub.proposed_change.updatedinfrahub.proposed_change.mergedinfrahub.proposed_change.closed
Validator Events
infrahub.validator.createdinfrahub.validator.completed
Event Structure
Base Event Model
Event Metadata
Event Resources
Events include resource metadata for filtering:Creating Events
Emit Event from Code
Event Metadata Options
Event Triggers
Triggers define conditions that cause automations to execute.Trigger Types
Event Trigger Definition
Example Trigger Definitions
Webhook Configuration Trigger
Branch Filter Trigger
Exclude Branch Trigger
Trigger Actions
Execute Workflow Action
Parameter Templating
Actions support Jinja2 templating for parameters:Built-in Triggers
Infrahub includes several built-in triggers:Repository Triggers
- Repository Add: Configure new repositories
- Repository Update: Reconfigure on updates
- Repository Delete: Clean up automations
Generator Triggers
- Group Member Added: Run generator when target added
- Group Member Removed: Update when target removed
- Generator Definition Updated: Reconfigure generator
Webhook Triggers
- Webhook Created: Configure automation
- Webhook Updated: Update automation
- Webhook Deleted: Remove automation
Custom Triggers
Define Trigger
Register Trigger
Setup Triggers
Event Service
Emit Events
Query Events
Events are stored in Prefect and can be queried:Event Context Propagation
Events maintain context across nested operations:Event Filtering
Events can be filtered using resource metadata:By Node Kind
By Multiple Kinds
By Branch
By Account
By Attribute Change
Real-World Examples
Automatic IPAM Validation
Schema Migration on Update
Audit Trail
Best Practices
Event Design
- Include all relevant context in events
- Use descriptive event names
- Keep event payloads focused
- Include correlation IDs for tracing
Trigger Design
- Make triggers specific to reduce unnecessary executions
- Use match filters to target exact resources
- Avoid overly broad event patterns
- Test triggers in non-production branches first
Performance
- Minimize event payload size
- Use async workflows for long operations
- Batch process when possible
- Monitor trigger execution times
Debugging
- Use event IDs for correlation
- Check Prefect UI for event history
- Review automation execution logs
- Test event emission in isolation
Troubleshooting
Events Not Triggering
- Verify event name matches trigger pattern
- Check match/match_related filters
- Ensure trigger is registered and active
- Review Prefect automation status
Duplicate Triggers
- Check for multiple trigger definitions
- Verify trigger names are unique
- Review automation list in Prefect UI
Performance Issues
- Profile event emission overhead
- Optimize event payload size
- Review trigger execution frequency
- Consider event batching