Elastic Terraform provider lets you manage security detection rules as code and auto-detect drift
The Elastic Stack Terraform provider enables full management of detection rules and exceptions as code, with automatic drift detection and no need for manual exports.
Security & privacy Elastic Security Labs 13 Mar 2026 Tooling Deployed evidence
Published as “Managing Elastic Security Detection Rules with Terraform”
Why it matters
Treating detection rules as infrastructure code improves consistency, auditability, and integration with existing IaC pipelines.
Summary
The post introduces new Terraform resources (elasticstack_kibana_security_detection_rule, exception_list, exception_item) that let users define Elastic Security detection rules and exceptions in HCL. It shows an example rule for interactive logons by service accounts and demonstrates how Terraform apply can detect drift from manual changes in Kibana. The authors also highlight Elastic's AI Agent generating Terraform configs and compare the Terraform approach with the detection-rules repository, noting trade-offs such as lack of built-in query validation.
What they found 2
- Terraform apply automatically detects drift in detection rules edited directly in Kibana.
“Since terraform apply runs a plan before making changes, it will automatically detect if anyone has edited a rule directly in Kibana and show you exactly what drifted: no manual exports or diffs needed.”
- Elastic AI Agent can produce Terraform configuration from ES|QL rules.
“Turning ES|QL rules into Terraform's configuration syntax, HCL, is a great use case for Elastic's AI Agent.”
Caveats 2
- No built-in query validation: the provider relies on the Kibana API to accept or reject rule definitions at apply time.
- Any features or functionality not currently available may not be delivered on time or at all.
What’s new here 4
- Terraform resources for detection rules, exception lists, and exception items (v0.12.0/0.13.0).
- AI Agent can generate HCL configurations from ES|QL queries.
- Terraform plan automatically surfaces drift when rules are edited outside of IaC.
- Comparison of Terraform provider vs detection-rules repo for different user profiles.