<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Elastic Security Labs - Articles by Omer Kushmaro</title>
        <link>https://www.elastic.co/security-labs</link>
        <description>Trusted security news &amp; research from the team at Elastic.</description>
        <lastBuildDate>Wed, 05 Aug 2026 21:07:31 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>Elastic Security Labs - Articles by Omer Kushmaro</title>
            <url>https://www.elastic.co/security-labs/assets/security-labs-thumbnail.png</url>
            <link>https://www.elastic.co/security-labs</link>
        </image>
        <copyright>© 2026. elasticsearch B.V. All Rights Reserved</copyright>
        <item>
            <title><![CDATA[Managing Elastic Security Detection Rules with Terraform]]></title>
            <link>https://www.elastic.co/security-labs/managing-rules-with-terraform</link>
            <guid>managing-rules-with-terraform</guid>
            <pubDate>Fri, 13 Mar 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[Learn to define and deploy Elastic Security detection rules and exceptions using the Elastic Stack Terraform Provider vs detection-rules repository DaC capabilities.]]></description>
            <content:encoded><![CDATA[<p>At the core of Elastic Security lie <a href="https://www.elastic.co/blog/elastic-security-detection-engineering">outstanding detection capabilities</a>, allowing users to <a href="https://www.elastic.co/blog/elastic-security-building-effective-threat-hunting-detection-rules">create</a>, test, tune, manage, deploy detection rules, as code, in their environments. The ability to create robust detections is critical for Security Operations as detection logic elevates threat signal from the telemetry noise.</p>
<p>This article highlights how Elastic's new Terraform resources for security detection rules and exceptions expand practitioners' capabilities for detection-as-code deployment. Below you will find examples of defining and deploying your detection artifacts in Elastic Security with Terraform. We will also show how you can use Elastic's AI Agent to help quickly create the Terraform configuration for your custom rules. Finally, it also provides guidance on when to use the Elastic Stack Terraform <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_detection_rule">provider</a> versus <a href="https://github.com/elastic/detection-rules/blob/main/README.md#detections-as-code-dac">tools from the detection-rules repository</a>.</p>
<h2>Managing Elastic with Terraform</h2>
<p><a href="https://developer.hashicorp.com/terraform">Terraform is</a> a tool created by HashiCorp (now IBM) to manage infrastructure in the cloud, or in self-managed environments, as code. With a simple stroke of HCL (HashiCorp configuration language), users can define the desired state of their cloud provider infrastructure, application, configuration, and in Elastic’s case, cluster settings, configuration, indices or streams, and now also detection rules and alerts, as fully configurable, traceable, and reviewable code in your favorite source management tool.</p>
<p>The <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_detection_rule">Elastic Stack Terraform provider</a> helps search, observability, and security professionals, as well as DevOps and SREs, configure their Elastic clusters with the right indices and mappings for their search use cases, SLOs or Fleet policies for their observability use case, and now, detection rules, alerts, and exceptions for their security use case. It can easily configure those, and many more objects and settings in the Elastic Stack.</p>
<h2>Security Detection rules - now as code with Terraform</h2>
<p>With <a href="https://github.com/elastic/terraform-provider-elasticstack/releases/tag/v0.12.0">V0.12.0</a> and <a href="https://github.com/elastic/terraform-provider-elasticstack/releases/tag/v0.13.0">V0.13.0</a> of the <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_detection_rule">Elastic Stack Terraform provider,</a> users can now manage their Detection rules and rule exceptions using Terraform. This is especially useful for users who have already been managing their Elastic deployments with Terraform and want to extend it to Detection rules.</p>
<h3>Using the Elastic Stack Terraform Provider to deploy Rules and Exceptions</h3>
<p>Let's look at an example of using the Elastic Stack Terraform Provider to deploy an Elastic Security Rule. In this example, we want to detect Windows Service Accounts that are performing an interactive logon on a host.</p>
<p>Service accounts typically have elevated privileges and rarely-rotated passwords, making them high-value targets for attackers. Since these accounts should only perform automated service logons, an interactive logon can indicate credential theft or misuse.</p>
<p>The first thing we need to think of is what telemetry we need to see which logons are happening on our host. <a href="https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/auditing/event-4624">Logon events</a> are logged by the Windows Local Security Authority Subsystem Service (LSASS) whenever a logon session is successfully created on the machine. We can pick this up via an Elastic Agent with the <a href="https://www.elastic.co/docs/reference/integrations/windows">Windows Integration</a> installed.</p>
<p>The data will be written by the Elastic Agent into the system.security Data Stream, we can match it with this index pattern: <code>logs-system.security-*.</code> We also know that Logon events generate event code <code>4624</code> and that, in our example, the service account name starts with <code>svc</code> or ends with <code>$</code>.  In addition, an interactive login will have a logon type of <code>interactive</code>.</p>
<p>So, we can match these events with an <a href="https://www.elastic.co/docs/reference/query-languages/esql">ES|QL</a> rule like:</p>
<pre><code class="language-sql">FROM logs-system.security-\*  
| WHERE event.code \== &quot;4624&quot; AND (user.name LIKE &quot;svc\_\*&quot; OR user.name LIKE &quot;svc-\*&quot;  
     OR user.name LIKE &quot;\*\_svc&quot; OR user.name LIKE &quot;\*$&quot;)  
     AND winlog.logon.type IN (&quot;Interactive&quot;, &quot;RemoteInteractive&quot;,  
         &quot;CachedInteractive&quot;, &quot;CachedRemoteInteractive&quot;)  
</code></pre>
<p>There may be situations where we don't want this rule to run, for example, if there is a legacy application that we want to permit interactive logons from. So, we can create an <a href="https://www.elastic.co/docs/solutions/security/detect-and-alert/rule-exceptions">Exception Item</a>, like: <code>user.name IS svc\_sqlbackup</code>.</p>
<p>Now that we know what we want the Rule and its Exceptions to look like, we can use the Terraform provider's <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_detection_rule">elasticstack_kibana_security_detection_rule</a>, <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_exception_list">elasticstack_kibana_security_exception_list</a>, and <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_exception_item">elasticstack_kibana_security_exception_item</a> resources to define them in code.</p>
<p>Turning ES|QL rules into Terraform's configuration syntax, <a href="https://developer.hashicorp.com/terraform/language/syntax/configuration">HCL</a>, is a great use case for Elastic's <a href="https://www.elastic.co/docs/solutions/security/ai/agent-builder/agent-builder">AI Agent</a>.<br />
Elastic AI Agent capabilities help accelerate security operations across a wide range of tasks - from <a href="https://www.elastic.co/security-labs/speeding-apt-attack-discovery-confirmation-with-attack-discovery-workflows-and-agent-builder">alerts triage and incident response</a> to helping with detection lifecycle tasks.</p>
<p>Simply open AI Agent, and ask it to create Terraform configurations based on your query and exceptions.</p>
<p><img src="https://www.elastic.co/security-labs/assets/images/managing-rules-with-terraform/image2.png" alt="" /></p>
<p>You should end up with something like this:</p>
<p><img src="https://www.elastic.co/security-labs/assets/images/managing-rules-with-terraform/image1.png" alt="" /></p>
<p>Here's a closer look at the code.</p>
<p>There are a few elements to call out specifically:</p>
<ul>
<li><code>type</code>: The type of exception list. For example: detection, endpoint, or endpoint_trusted_apps</li>
<li><code>namespace_type</code>: Determines whether the exception list is available in all Kibana spaces or just the single space in which it was created.</li>
</ul>
<pre><code>resource &quot;elasticstack_kibana_security_exception_list&quot; &quot;svc_account_interactive_login&quot; {
  list_id        = &quot;svc-account-interactive-login-exceptions&quot;
  name           = &quot;Service Account Interactive Login Exceptions&quot;
  description    = &quot;Documented exceptions for service accounts that legitimately require interactive logon&quot;
  type           = &quot;detection&quot;
  namespace_type = &quot;single&quot;
  tags           = [&quot;service-accounts&quot;,&quot;windows&quot;,&quot;authentication&quot;]
}  
</code></pre>
<p>This creates a new exception list.</p>
<p>Of note, the <code>entries</code> array contains the conditions under which the exception applies.</p>
<pre><code>resource &quot;elasticstack_kibana_security_exception_item&quot; &quot;svc_sqlbackup&quot; {
  list_id        = elasticstack_kibana_security_exception_list.svc_account_interactive_login.list_id
  item_id        = &quot;svc-sqlbackup-exception&quot;
  name           = &quot;svc_sqlbackup - Legacy SQL Backup Agent&quot;
  description    = &quot;Approved exception: Legacy SQL backup agent requires interactive logon per vendor documentation.&quot;
  type           = &quot;simple&quot;
  namespace_type = &quot;single&quot;
  tags           = [&quot;sql&quot;,&quot;backup&quot;,&quot;approved&quot;]
entries = [
    {
      field    = &quot;user.name&quot;
      type     = &quot;match&quot;
      operator = &quot;included&quot;
      value    = &quot;svc_sqlbackup&quot;
    }
  ]
} 
</code></pre>
<p>This adds our exception: that we don't want the rule to run if the username is <code>svc\_sqlbackup</code>.</p>
<p>Of note, the elements from <code>enabled</code> to the <code>technique</code> array are examples of the other properties that can be set on a rule.</p>
<pre><code>resource &quot;elasticstack_kibana_security_detection_rule&quot; &quot;svc_account_interactive_login&quot; {
  name        = &quot;Service Account Interactive Login&quot;
  description = &lt;&lt;-EOT
    Detects interactive logins by service accounts. Service accounts should authenticate
    via service (Type 5) or batch (Type 4) logon types, not interactively. Interactive
    logins by service accounts may indicate credential theft or misuse.

    This rule identifies service accounts by common naming conventions (svc_*, svc-*,
    *_svc) and managed service accounts (*$).
  EOT

  type     = &quot;esql&quot;
  language = &quot;esql&quot;
  query    = &lt;&lt;-EOT
    FROM logs-system.security-* metadata _id, _version, _index
    | WHERE event.code == &quot;4624&quot;
      AND (user.name LIKE &quot;svc_*&quot; OR user.name LIKE &quot;svc-*&quot; OR user.name LIKE &quot;*_svc&quot; OR user.name LIKE &quot;*$&quot;)
      AND winlog.logon.type IN (&quot;Interactive&quot;, &quot;RemoteInteractive&quot;, &quot;CachedInteractive&quot;, &quot;CachedRemoteInteractive&quot;)
    | KEEP @timestamp, host.name, user.name, user.domain, winlog.logon.type, source.ip, _id, _version, _index
  EOT

  enabled    = true 
  severity   = &quot;high&quot;
  risk_score = 73

  from     = &quot;now-6m&quot;
  to       = &quot;now&quot;
  interval = &quot;5m&quot;

  author  = [&quot;Security Team&quot;]
  license = &quot;Elastic License v2&quot;
  tags    = [
    &quot;Domain: Endpoint&quot;,
    &quot;OS: Windows&quot;,
    &quot;Use Case: Identity and Access Audit&quot;,
    &quot;Tactic: Initial Access&quot;,
    &quot;Data Source: Windows Security Event Log&quot;
  ]

  false_positives = [
    &quot;Service accounts with documented exceptions that require interactive logon&quot;,
    &quot;Break-glass procedures during incident response&quot;,
    &quot;Initial service account configuration or troubleshooting&quot;
  ]

  references = [
    &quot;https://learn.microsoft.com/en-us/entra/architecture/service-accounts-on-premises&quot;,
    &quot;https://blog.quest.com/10-microsoft-service-account-best-practices/&quot;,
    &quot;https://attack.mitre.org/techniques/T1078/002/&quot;
  ]

  threat = [
    {
      framework = &quot;MITRE ATT&amp;CK&quot;
      tactic = {
        id        = &quot;TA0001&quot;
        name      = &quot;Initial Access&quot;
        reference = &quot;https://attack.mitre.org/tactics/TA0001/&quot;
      }
      technique = [
        {
          id        = &quot;T1078&quot;
          name      = &quot;Valid Accounts&quot;
          reference = &quot;https://attack.mitre.org/techniques/T1078/&quot;
          subtechnique = [
            {
              id        = &quot;T1078.002&quot;
              name      = &quot;Domain Accounts&quot;
              reference = &quot;https://attack.mitre.org/techniques/T1078/002/&quot;
            }
          ]
        }
      ]
    }
  ]

  exceptions_list = [
    {
      id             = elasticstack_kibana_security_exception_list.svc_account_interactive_login.id
      list_id        = elasticstack_kibana_security_exception_list.svc_account_interactive_login.list_id
      namespace_type = elasticstack_kibana_security_exception_list.svc_account_interactive_login.namespace_type
      type           = elasticstack_kibana_security_exception_list.svc_account_interactive_login.type
    }
  ]
}
</code></pre>
<p>Finally, we define the rule, including the ES|QL query we provided earlier and MITRE ATT&amp;CK classification.</p>
<p>You can add these resource definitions into one configuration file (perhaps security-rules.tf), add it to your <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs#kibana">configured</a> Elastic Stack terraform directory, and then run the `terraform apply` command and parameter to deploy the Rule.</p>
<pre><code class="language-shell">terraform apply --auto-approve
</code></pre>
<p>Since <code>terraform apply</code> 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.</p>
<p>After Terraform has made the changes, we can see the Rule in Kibana:</p>
<p><img src="https://www.elastic.co/security-labs/assets/images/managing-rules-with-terraform/image5.png" alt="" /></p>
<p>We can also see the Exception List:</p>
<p><img src="https://www.elastic.co/security-labs/assets/images/managing-rules-with-terraform/image4.png" alt="" /></p>
<p>This way, you can define your detections in Terraform and benefit from automatic deployment along with other objects you manage with Terraform.</p>
<h2>Terraform workspaces for multi-space Elastic deployments</h2>
<p>Terraform uses a concept called “<a href="https://developer.hashicorp.com/terraform/language/state/workspaces">workspaces</a>” allowing you to reuse the same infrastructure code for multiple deployments, for example, a dev, testing, and production environment. This concept is useful for managing rules across multiple deployments and/or Kibana spaces.</p>
<h2>Managing detections with Terraform and Detections as code</h2>
<p>Elastic also has <a href="https://www.elastic.co/security-labs/detection-as-code-timeline-and-new-features">Detections as Code functionality</a> available via our open <a href="https://github.com/elastic/detection-rules">detection-rules repository.</a></p>
<p>The two tools have complementary strengths and are aligned with different user profiles and workflow stages for implementing Detections as Code.</p>
<h3>Detection as Code features in detection-rules</h3>
<ul>
<li><strong>Best fit user profile</strong>: Detection engineers</li>
<li><strong>Intended workflow phase</strong>: Rule authoring and validation</li>
</ul>
<p>With dual-sync between your GitHub repo and Kibana, linting, schema validation, and unit-testing, detection-rules functionality is well-suited to experienced Detection Engineers comfortable with Git-based version control.</p>
<h3>Elastic Stack Terraform Provider</h3>
<ul>
<li><strong>Best fit user profile</strong>: DevOps engineers / Platform teams</li>
<li><strong>Intended workflow phase</strong>: Deployment and operations</li>
</ul>
<p>For users already using Terraform to manage their Elastic clusters, the Terraform Provider is a great fit, bringing consistency to all &quot;x-as-code&quot; operations and familiar state management and parameterization.</p>
<p>The key differences and optimal use cases for each tool are detailed in the comparison table below:</p>
<table>
<thead>
<tr>
<th align="left">Workflow Stage</th>
<th align="left">detection-rules</th>
<th align="left">Terraform Provider</th>
<th align="left">Best Fit</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><strong>Rule Authoring</strong></td>
<td align="left">Purpose-built tooling: create-rule wizard, TOML schema, KQL/EQL validation, field checks against ECS, Kibana-to-code export.</td>
<td align="left">Standard HCL definitions; teams integrate their preferred validation tooling into existing pipelines.</td>
<td align="left"><strong>detection-rules:</strong> Detection engineers authoring and refining rules daily. Teams wanting to automatically convert rules from Kibana into code. <strong>Terraform:</strong> Teams already using Terraform in their workflows, or teams wanting to automate and deploy detection rules as code, but without an established CI/CD platform.</td>
</tr>
<tr>
<td align="left"><strong>Testing &amp; Validation</strong></td>
<td align="left">Built-in unit testing framework, schema validation, query validation, configurable test suites.</td>
<td align="left">Terraform tests for optional unit testing. No built-in query validation: the provider relies on the Kibana API to accept or reject rule definitions at apply time.</td>
<td align="left"><strong>detection-rules:</strong> Teams wanting out-of-the-box detection testing. <strong>Terraform:</strong> Platform teams managing rules as part of broader IaC with existing validation pipelines. Teams happy to write custom tests in Terraform.</td>
</tr>
<tr>
<td align="left"><strong>Exception Management</strong></td>
<td align="left">Native exception list handling; export/import with rules, TOML storage, and rule linking.</td>
<td align="left">Exception lists can be referenced via rule attributes.</td>
<td align="left"><strong>detection-rules:</strong> Teams managing exceptions as part of detection content. <strong>Terraform:</strong> Teams managing exceptions as separate infrastructure resources.</td>
</tr>
<tr>
<td align="left"><strong>Governance &amp; Drift Management</strong></td>
<td align="left">VCS-based with dual sync: push rules from repo to Kibana and export from Kibana back to repo, allowing either to serve as the source of truth. Drift detection is achievable with custom export-and-diff tooling.</td>
<td align="left">VCS-authoritative: state file enforces declared configuration.  Native drift detection: Terraform plan surfaces any out-of-band changes made in Kibana.</td>
<td align="left"><strong>detection-rules:</strong> Teams comfortable with Git-based workflows and flexible sync models. <strong>Terraform:</strong> Organisations requiring formal state reconciliation and audit trails.</td>
</tr>
<tr>
<td align="left"><strong>Rollback</strong></td>
<td align="left">Git history provides version control; re-import previous versions from the repo.</td>
<td align="left">Revert HCL configuration in Git and re-apply to restore the previous state.</td>
<td align="left"><strong>detection-rules:</strong> Teams using Git-centric recovery workflows. <strong>Terraform:</strong> Organisations with standardised rollback mechanisms across infrastructure and rulesets.</td>
</tr>
<tr>
<td align="left"><strong>Parameterisation &amp; Templating</strong></td>
<td align="left">Achievable with external preprocessing (Jinja2, etc.) before import.</td>
<td align="left">Native HCL features: variables, locals, for_each, dynamic blocks, and modules.</td>
<td align="left"><strong>detection-rules:</strong> Teams not requiring parameterisation or with existing templating solutions.  <strong>Terraform:</strong> Teams wanting native IaC parameterisation.</td>
</tr>
<tr>
<td align="left"><strong>Operational Integration</strong></td>
<td align="left">Focused tooling optimised for detection engineering workflows.</td>
<td align="left">Unified control plane managing detection rules alongside cloud infrastructure, network policies, and other security tooling.  Integrates with other resources that may be required by detections such as external connectors.</td>
<td align="left"><strong>detection-rules:</strong> Specialist detection teams. More flexible if dual-sync (Kibana and repo are both sources of truth).  <strong>Terraform:</strong> Platform teams managing Elastic as part of broader infrastructure.</td>
</tr>
</tbody>
</table>
<p>In short, Detection Engineers are better served by the specialized creation and testing tools provided in the <code>detection-rules</code> repository, while DevOps/Platform Teams should use the Terraform provider to manage detection rules as part of their broader infrastructure-as-code strategy for deployment and operations.</p>
<h2>Try it out</h2>
<p>To experience the full benefits of what Elastic has to offer for detection engineers, upgrade to 9.3 or start your Elastic Security <a href="https://cloud.elastic.co/registration">free trial</a>. Visit <a href="https://www.elastic.co/security">elastic.co/security</a> to learn more and get started.</p>
<p><em>The release and timing of any features or functionality described in this post remain at Elastic's sole discretion. Any features or functionality not currently available may not be delivered on time or at all.</em></p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/security-labs/assets/images/managing-rules-with-terraform/managing-rules-with-terraform.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Manage your Elastic security stack as code with the Elastic Stack Terraform provider]]></title>
            <link>https://www.elastic.co/security-labs/manage-elastic-with-terraform</link>
            <guid>manage-elastic-with-terraform</guid>
            <pubDate>Fri, 27 Feb 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[From detection rules to AI connectors - the latest Terraform provider releases bring security, observability, and ML capabilities to your infrastructure-as-code workflows.]]></description>
            <content:encoded><![CDATA[<p>The <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs">Elastic Stack Terraform provider</a> has reached a significant milestone. Starting with release v0.13.1, you can manage your Elastic security posture - detection rules, exception lists, and prebuilt rules - alongside ML anomaly detection jobs, synthetics monitors, and AI connectors, all as code.</p>
<p>This brings your detection logic and ML jobs into the same versioned, peer-reviewed workflow as your core clusters. It ensures your security posture and AI connectors are no longer manual outliers in an otherwise automated environment.</p>
<h2>The challenge: Security and observability configuration at scale</h2>
<p>As Elastic deployments grow, so does the complexity of managing them. Security teams maintain hundreds of detection rules. SREs configure monitoring across dozens of clusters. ML engineers tune anomaly detection jobs across multiple environments. All of these configurations must be consistent, auditable, and reproducible.</p>
<p>Without infrastructure as code, teams face two problems:</p>
<ol>
<li>
<p><strong>Configuration drift.</strong> Rules, policies, and monitors are created manually through the Kibana UI. Over time, production and staging diverge. No one is sure which version of a detection rule is running where.</p>
</li>
<li>
<p><strong>Buried audit trail.</strong> When a detection rule changes or an exception is added, there's no pull request to review, no commit history to trace, and no rollback path if something breaks. Users need to put in extra effort to access such history.</p>
</li>
</ol>
<p><a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs">Elastic Stack Terraform provider</a> solves this by bringing these configurations into the same version-controlled, peer-reviewed workflow that teams already use for infrastructure.</p>
<h2>Security artifacts as code: Detection rules, exceptions, and prebuilt rules</h2>
<p>You can now manage the full lifecycle of Elastic Security detection rules through Terraform.</p>
<h3>Detection rules</h3>
<p>The <code>elasticstack_kibana_security_detection_rule</code> resource lets you define, version, and deploy detection rules in the <a href="https://github.com/hashicorp/hcl">HashiCorp Configuration Language</a> (HCL) format:</p>
<pre><code>resource &quot;elasticstack_kibana_security_detection_rule&quot; &quot;suspicious_admin_logon&quot; {
  name        = &quot;Suspicious Admin Logon Activity&quot;
  type        = &quot;query&quot;
  query       = &quot;event.action:logon AND user.name:admin&quot;
  language    = &quot;kuery&quot;
  enabled     = true
  description = &quot;Detects suspicious admin logon activities&quot;
  severity    = &quot;high&quot;
  risk_score  = 75
  from        = &quot;now-6m&quot;
  to          = &quot;now&quot;
  interval    = &quot;5m&quot;
  tags        = [&quot;security&quot;, &quot;authentication&quot;, &quot;admin&quot;]
}
</code></pre>
<p>This means your detection rules live in Git, undergo code review, and are deployed consistently across environments. No more clicking through the Kibana UI to replicate rules from staging to production.</p>
<p><a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/kibana_security_detection_rule">Detection rule resource docs</a></p>
<h3>Exception lists and items</h3>
<p>The security-as-code story extends to a full suite of exception management resources:</p>
<ul>
<li><code>elasticstack_kibana_security_exception_list</code> - Create and manage exception lists</li>
<li><code>elasticstack_kibana_security_exception_item</code> - Define individual exception items within a list</li>
<li><code>elasticstack_kibana_security_list</code> and <code>elasticstack_kibana_security_list_item</code> - Manage value lists for IP allowlists, file hashes, and other indicators</li>
<li><code>elasticstack_kibana_security_list_data_streams</code> - Associate lists with specific data streams</li>
</ul>
<p>Here's an example that ties them together - an exception list with items that suppress known false positives for a detection rule:</p>
<pre><code>resource &quot;elasticstack_kibana_security_exception_list&quot; &quot;vuln_scanner_exceptions&quot; {
  list_id        = &quot;vuln-scanner-exceptions&quot;
  name           = &quot;Vulnerability Scanner Exceptions&quot;
  description    = &quot;Suppress alerts from authorized vulnerability scanners&quot;
  type           = &quot;detection&quot;
  namespace_type = &quot;single&quot;
  tags           = [&quot;security&quot;, &quot;vulnerability-scanning&quot;]
}

resource &quot;elasticstack_kibana_security_exception_item&quot; &quot;nessus_scanner&quot; {
  list_id        = elasticstack_kibana_security_exception_list.vuln_scanner_exceptions.list_id
  item_id        = &quot;nessus-scanner&quot;
  name           = &quot;Nessus Scanner - Authorized&quot;
  description    = &quot;Suppress alerts from authorized Nessus scanner hosts&quot;
  type           = &quot;simple&quot;
  namespace_type = &quot;single&quot;

  entries = [
    {
      type     = &quot;match&quot;
      field    = &quot;source.ip&quot;
      operator = &quot;included&quot;
      value    = &quot;10.0.50.10&quot;
    },
    {
      type     = &quot;match_any&quot;
      field    = &quot;process.name&quot;
      operator = &quot;included&quot;
      values   = [&quot;nessus&quot;, &quot;nessusd&quot;]
    }
  ]

  tags = [&quot;nessus&quot;, &quot;authorized-scanner&quot;]
}

resource &quot;elasticstack_kibana_security_exception_item&quot; &quot;qualys_scanner&quot; {
  list_id        = elasticstack_kibana_security_exception_list.vuln_scanner_exceptions.list_id
  item_id        = &quot;qualys-scanner&quot;
  name           = &quot;Qualys Scanner - Authorized&quot;
  description    = &quot;Suppress alerts from authorized Qualys scanner subnet&quot;
  type           = &quot;simple&quot;
  namespace_type = &quot;single&quot;

  entries = [
    {
      type     = &quot;match&quot;
      field    = &quot;source.ip&quot;
      operator = &quot;included&quot;
      value    = &quot;10.0.51.0/24&quot;
    }
  ]

  tags = [&quot;qualys&quot;, &quot;authorized-scanner&quot;]
}
</code></pre>
<p>The exception list and its items are linked by <code>list_id</code>, so Terraform manages the dependency graph automatically. Adding a new authorized scanner is a one-line PR - no clicking through the Kibana UI, no risk of forgetting which environment got the update.</p>
<h3>Prebuilt security rules</h3>
<p>The <code>elasticstack_kibana_prebuilt_rule</code> resource lets you manage Elastic's prebuilt detection rules via Terraform. This is particularly valuable for organizations that need to track which prebuilt rules are enabled, customize their parameters, and ensure consistent deployment across environments.</p>
<h2>ML anomaly detection as code</h2>
<p>Machine learning anomaly detection is one of Elasticsearch's most powerful capabilities - but managing ML jobs across environments has traditionally been a manual process. You create a job in the Kibana UI, tune the detectors, configure the datafeed, and hope someone documents the settings so they can be replicated in the next environment.</p>
<p>The <code>elasticstack_elasticsearch_ml_anomaly_detection_job</code> resource changes that. You can now define the full configuration of an anomaly detection job in HCL - detectors, bucket spans, influencers, data feeds, and analysis limits - and deploy it consistently across dev, staging, and production.</p>
<pre><code>resource &quot;elasticstack_elasticsearch_ml_anomaly_detection_job&quot; &quot;cpu_anomalies&quot; {
  job_id      = &quot;high-cpu-by-host&quot;
  description = &quot;Detect unusual CPU usage patterns&quot;

  analysis_config = {
    bucket_span = &quot;15m&quot;
    detectors   = [{
      function   = &quot;high_mean&quot;
      field_name = &quot;system.cpu.user_pct&quot;
    }]
    influencers = [&quot;host.name&quot;]
  }

  data_description = {
    time_field = &quot;@timestamp&quot;
  }
}
</code></pre>
<p>This matters for teams that rely on ML to catch infrastructure anomalies, unusual user behavior, or security threats. Instead of manually recreating jobs when spinning up new clusters or recovering from failures, the entire ML configuration lives in version control - reviewable, repeatable, and recoverable.</p>
<h2>Cross-cluster automation with API keys</h2>
<p>For organizations running multiple Elasticsearch clusters, the provider now supports <strong>cluster API keys for cross-cluster search (CCS) and cross-cluster replication (CCR)</strong>. You can create API keys specifically designed for secure cross-cluster communication, enabling end-to-end automation of multi-cluster architectures.</p>
<p>This means you can provision two clusters, configure CCS/CCR between them, and set up the necessary security credentials - all in a single Terraform configuration.</p>
<pre><code>resource &quot;elasticstack_elasticsearch_security_api_key&quot; &quot;ccs_key&quot; {
  name = &quot;cross-cluster-search-key&quot;
  type = &quot;cross_cluster&quot;

  access = {
    search = [{
      names = [&quot;logs-*&quot;, &quot;metrics-*&quot;]
    }]
    replication = [{
      names = [&quot;archive-*&quot;]
    }]
  }

  expiration = &quot;90d&quot;

  metadata = jsonencode({
    environment = &quot;production&quot;
    purpose     = &quot;ccs-ccr-between-prod-clusters&quot;
    team        = &quot;platform&quot;
  })
}
</code></pre>
<p>When the <code>type</code> is set to <code>cross_cluster</code>, the API key is scoped to CCS/CCR operations. You define which index patterns are accessible for search and replication, set an expiration policy, and tag the key with metadata - all reviewable in a pull request.</p>
<p>Learn more about <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/elasticsearch_security_api_key">API key resources</a> in the documentation.</p>
<h2>AI connectors as code</h2>
<p>The provider now supports <code>.bedrock</code> and <code>.gen-ai</code> connectors, bringing AI infrastructure into your Terraform workflows. As teams increasingly integrate large language models into their Elastic workflows - for AI assistants, attack discovery, and automated investigations - managing these connector configurations as code becomes essential.</p>
<pre><code>resource &quot;elasticstack_kibana_action_connector&quot; &quot;bedrock&quot; {
  name              = &quot;aws-bedrock&quot;
  connector_type_id = &quot;.bedrock&quot;
  config = jsonencode({
    apiUrl       = &quot;https://bedrock-runtime.us-east-1.amazonaws.com&quot;
    defaultModel = &quot;anthropic.claude-v2&quot;
  })
  secrets = jsonencode({
    accessKey = var.aws_access_key
    secret    = var.aws_secret_key
  })
}

resource &quot;elasticstack_kibana_action_connector&quot; &quot;openai&quot; {
  name              = &quot;openai&quot;
  connector_type_id = &quot;.gen-ai&quot;
  config = jsonencode({
    apiProvider  = &quot;OpenAI&quot;
    apiUrl       = &quot;https://api.openai.com/v1/chat/completions&quot;
    defaultModel = &quot;gpt-4&quot;
  })
  secrets = jsonencode({
    apiKey = var.openai_api_key
  })
}
</code></pre>
<p>With these connectors defined in Terraform, you can version your AI integration configuration alongside the rest of your Elastic infrastructure - and swap models or providers through a simple PR.</p>
<h2>Observability enhancements</h2>
<h3>Synthetics monitors</h3>
<p>The <code>elasticstack_kibana_synthetics_monitor</code> resource now includes a <code>labels</code> field, enabling better organization and filtering of synthetic checks. Labels let you tag monitors by team, environment, or service, making it easier to manage synthetic monitoring at scale.</p>
<h2>Additional platform improvements</h2>
<p>Recent releases also included several resources and attributes that round out the provider's coverage:</p>
<ul>
<li><code>elasticstack_elasticsearch_alias</code> - Manage Elasticsearch aliases as a dedicated resource</li>
<li><code>elasticstack_kibana_default_data_view</code> - Set the default data view for a Kibana space</li>
<li><code>solution</code> attribute on <code>elasticstack_kibana_space</code> - Configure the solution type for Kibana spaces (available from 8.16)</li>
<li>Fleet agent policy enhancements - <code>host_name_format</code> for configuring hostname vs. FQDN, and <code>required_versions</code> for version pinning</li>
</ul>
<h2>Getting started</h2>
<p>If you're already using the Elastic Stack Terraform provider, upgrade to the latest provider version to get all of these capabilities:</p>
<pre><code>terraform {
  required_providers {
    elasticstack = {
      source  = &quot;elastic/elasticstack&quot;
      version = &quot;~&gt; 0.14&quot;
    }
  }
}
</code></pre>
<p>If you're new to managing your Elastic Stack with Terraform, start with the <a href="https://registry.terraform.io/providers/elastic/elasticstack/latest/docs">provider documentation</a> on the Terraform registry.</p>
<p>To start using Elastic Cloud today, log in to the <a href="https://cloud.elastic.co/">Elastic Cloud console</a> or sign up for a <a href="https://cloud.elastic.co/registration">free trial</a>.<br />
For the full set of changes, check out the <a href="https://github.com/elastic/terraform-provider-elasticstack/releases">release notes on GitHub</a>.</p>
]]></content:encoded>
            <category>security-labs</category>
            <enclosure url="https://www.elastic.co/security-labs/assets/images/manage-elastic-with-terraform/manage-elastic-with-terraform.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>