> For the complete documentation index, see [llms.txt](https://docs.ilert.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ilert.com/developer-docs/terraform/export-to-terraform.md).

# Export to Terraform

Export any ilert resource as Terraform HCL code directly from the web UI to adopt Infrastructure-as-Code practices incrementally.

ilert lets you export individual resources as ready-to-use Terraform (HCL) configuration blocks directly from the web application. This makes it easy to transition from UI-managed resources to Infrastructure-as-Code without having to write Terraform definitions from scratch.

## Overview

The **Export to Terraform** feature is available on the pages of supported resources (e.g., alert sources and escalation policies). It generates an HCL resource block that maps to the [ilert Terraform provider](https://registry.terraform.io/providers/iLert/ilert/latest/docs), so you can copy the output into your `.tf` files and start managing the resource with Terraform right away.

Key capabilities:

* **One-click export** — generate a Terraform resource definition for any supported ilert resource.
* **Import command or block** — get the matching `terraform import` command or `import` block so you can link the existing resource to your Terraform state without creating a duplicate.
* **Copy to clipboard** — quickly copy the HCL block, or the import command or block, with a single click.
* **Syntax-highlighted preview** — review the generated code in a readable, syntax-highlighted modal before copying.

## How to export a resource

1. Navigate to the detail page of the resource you want to export (for example, **Alert sources → \<your alert source>**).
2. Click the **Export to Terraform** button in the top-right action bar.<br>

   <figure><img src="https://1534978131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F684bnaGsqSFjESghpiiu%2Fuploads%2FGF3PQEutrE0S2IFIvb60%2Fimage.png?alt=media&amp;token=4aaaf026-b9b0-4cbb-a9fd-81ad4b5eafab" alt=""><figcaption></figcaption></figure>
3. A modal opens with two sections:

   **Resource definition** — the generated HCL block that you can add to your `.tf` configuration file. For example:

   ```hcl
   resource "ilert_alert_source" "prometheus" {
     integration_type  = "PROMETHEUS"
     name              = "Prometheus"
     alert_creation    = "INTELLIGENT_GROUPING"
     escalation_policy = "2207280"
     active            = true
     team {
       id   = 1
       name = "SRE Team"
     }
     alert_grouping_window = "PT5M"
     alert_priority_rule   = "LOW"
   }
   ```

   **Import existing resource** — a `terraform import` command that links the already existing ilert resource to your Terraform state. Running this before `terraform apply` prevents Terraform from creating a duplicate:

   ```bash
   terraform import ilert_alert_source.prometheus 2194927
   ```

   Switch the section from **Command** to **Block** to get an `import` block instead. Add it to your `.tf` configuration file, and the next `terraform apply` imports the resource rather than creating a duplicate. Import blocks need Terraform 1.5 or later:

   ```hcl
   import {
     to = ilert_alert_source.prometheus
     id = "2194927"
   }
   ```

   After importing, run `terraform plan` to verify there is no configuration drift between the definition and the live resource.<br>

   <figure><img src="https://1534978131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F684bnaGsqSFjESghpiiu%2Fuploads%2FOv9gvaOmsgcVqoHAF1I0%2Fimage.png?alt=media&amp;token=fdeb7b63-5e90-42d0-a15c-fee40289aac9" alt=""><figcaption></figcaption></figure>
4. Use the **copy** button next to each section to copy the content to your clipboard.

## Typical workflow

A common workflow for adopting Terraform for an existing ilert setup looks like this:

1. **Export** — open the resource in ilert and click **Export to Terraform** to get the HCL block.
2. **Add to your repository** — paste the HCL block into a `.tf` file in your Infrastructure-as-Code repository.
3. **Import state** — run the provided `terraform import` command, or add the `import` block, to tell Terraform that this resource already exists.
4. **Verify** — run `terraform plan` to confirm there is no drift. If the plan shows changes, adjust the `.tf` file until the plan is clean. Right after an import, the plan can also show blocks such as alert sources, teams or escalation rules as added although ilert already has them: the provider reads them only once they are in the state. Don't remove them from the configuration to clean the plan.
5. **Manage with Terraform** — from now on, use `terraform apply` to make changes to the resource.

{% hint style="info" %}
You can adopt Terraform incrementally — export and import resources one by one at your own pace. There is no need to migrate everything at once.
{% endhint %}

## Supported resources

Export to Terraform is available for alert sources, alert actions, connectors, escalation policies, on-call schedules, support hours, heartbeat monitors, event flows, call flows, services, status pages, metrics, metric data sources, incident templates, deployment pipelines, teams and users. Exporting a status page also exports its groups. Some exports fail `terraform validate` because the provider has no equivalent for them yet. Known cases are a call flow that uses a **Branch** node, and an Azure DevOps or Argo CD deployment pipeline. Support for additional resource types is being rolled out progressively.

{% hint style="info" %}
The generated HCL maps to the resource types defined in the [ilert Terraform provider](https://registry.terraform.io/providers/iLert/ilert/latest/docs). Make sure you have the provider configured in your Terraform project. For provider setup instructions, see the [Terraform overview](/developer-docs/terraform/terraform.md).
{% endhint %}

## Sensitive fields

Integration keys and integration URLs are left out of the exported HCL, except for email alert sources: their integration key is their email address, and the export writes it as `email`. Other credentials, such as a connector's password or API key, are included only if your role can read them, which for connectors means admins and the account owner. Before you commit the file, replace these values with Terraform variables or a secrets manager reference.

## FAQ

**Does Export to Terraform change anything in my ilert account?**

No. The export is read-only — it generates code for you to copy but does not modify the resource or its state in ilert.

**What happens if I skip the `terraform import` step?**

If you run `terraform apply` without importing first, Terraform will attempt to create a new resource instead of managing the existing one, resulting in a duplicate.

**Can I export multiple resources at once?**

Bulk export is not yet supported. You can export resources one at a time from their respective detail pages.

**Which Terraform provider version do I need?**

Use the latest version of the [ilert Terraform provider](https://registry.terraform.io/providers/iLert/ilert/latest) to ensure all exported attributes are supported.

**Where can I learn more about using the ilert Terraform provider?**

See the [Terraform overview](/developer-docs/terraform/terraform.md) for provider configuration and examples, and the guide on [importing existing resources into Terraform state](/developer-docs/terraform/importing-ilert-ui-resources-into-terraform-state.md) for a detailed walkthrough.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ilert.com/developer-docs/terraform/export-to-terraform.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
