# Export to Terraform

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 resource detail pages (e.g., alert sources and escalation policies). It generates a valid 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 complete Terraform resource definition for any supported ilert resource.
* **Import command** — get the matching `terraform import` command so you can link the existing resource to your Terraform state without creating a duplicate.
* **Copy to clipboard** — quickly copy the HCL block or import command 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&#x26;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
   ```

   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&#x26;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 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.
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 almost all resources, except for Call flows, Event flows, and Status pages. 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](https://docs.ilert.com/developer-docs/terraform/terraform).
{% endhint %}

## Sensitive fields

Sensitive values such as integration keys or API tokens are **not** included in the exported HCL. You will need to supply these values separately, for example through Terraform variables or a secrets manager.

## 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](https://docs.ilert.com/developer-docs/terraform/terraform) for provider configuration and examples, and the guide on [importing existing resources into Terraform state](https://docs.ilert.com/developer-docs/terraform/importing-ilert-ui-resources-into-terraform-state) for a detailed walkthrough.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
