---
title: Manage your workloads with Terraform
source: https://docs.newrelic.com/docs/new-relic-solutions/new-relic-one/workloads/terraform-guide
---

You can use Terraform to create, manage, and update your New Relic workloads, whether using [intelligent workloads](#intelligent-workloads) to track important business transactions or a [standard workload](#standard-workloads) to group entities owned by a specific team. The `newrelic_workload` resource within the official `terraform-provider-newrelic` repository now supports both workload types.

## Prerequisites [#prerequisites]

Before you begin:

-   Install the Terraform CLI on your machine.
-   Initialize a local working directory for your Terraform project.
-   Obtain a valid New Relic User API key (NerdGraph API access) and your [account ID](https://docs.newrelic.com/docs/accounts/accounts-billing/account-structure/account-id).
-   Export your credentials as environment variables (`NEW_RELIC_API_KEY`, `NEW_RELIC_ACCOUNT_ID`, and `NEW_RELIC_REGION`) rather than hardcoding them in your configuration files to keep your credentials secure.
-   Install `terraform-provider-newrelic` v3.94.0 or later. This is the minimum version required for Intelligent Workload support (`dynamic_flows`, `status_config_alert_policy`).

> #### ⚠️ IMPORTANT
>
> Do not use a License or Ingest key. Provisioning workload resources requires user-level API permissions.

## Set up authentication [#setup]

Declare the New Relic provider in your primary Terraform configuration file:

```terraform
terraform {
  required_providers {
    newrelic = {
      source  = "newrelic/newrelic"
      version = ">= 3.94.0"
    }
  }
}

provider "newrelic" {
  # Configuration inherits NEW_RELIC_API_KEY, NEW_RELIC_ACCOUNT_ID, and NEW_RELIC_REGION from environment variables
}
```

## Create standard workloads [#standard-workloads]

Define the `newrelic_workload` resource using search queries, explicit entity GUID lists, or account scope boundaries. Use this approach when you want to manually group specific infrastructure, applications, or services owned by a team.

```terraform
resource "newrelic_workload" "team_standard_workload" {
  name       = "Payments Team Workload"
  account_id = 1234567 # Replace with your New Relic Account ID

  # Group entities using a search query
  entity_search_query {
    query = "name LIKE 'payment-%' AND type = 'SERVICE'"
  }
}
```

## Create intelligent workloads [#intelligent-workloads]

Use the `dynamic_flows` configuration block. The main benefit of intelligent workloads is that once you designate an entry point entity GUID and transaction name in the `dynamic_flows` block, New Relic automatically discovers and maps upstream and downstream entity dependencies via distributed tracing (Transaction 360), refreshing them every 5 minutes. This means you don't need to manually update GUIDs or re-apply Terraform configurations when your underlying service architecture changes.

> #### 💡 TIP
>
> To find your entry point entity GUID, navigate to the entity in the New Relic UI and copy the GUID from the entity's metadata, or retrieve it using the [NerdGraph entities API](https://docs.newrelic.com/docs/apis/nerdgraph/examples/nerdgraph-entities-api-tutorial).

Intelligent workloads can also derive their health status from alert conditions: Set `status_config_alert_policy { enabled = true }` on the workload, then attach `newrelic_nrql_alert_condition` resources by setting their `target_entity` to the workload's guid.

> #### ⚠️ IMPORTANT
>
> `target_entity` support on `newrelic_nrql_alert_condition` is currently in public preview and available on a per-account basis. For more information, see the [Terraform registry documentation](https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/resources/nrql_alert_condition#description-1).

```terraform
resource "newrelic_workload" "checkout_intelligent_workload" {
  name       = "Checkout Transaction Flow"
  account_id = 1234567 # Replace with your New Relic Account ID

  dynamic_flows {
    entity_guid      = "Mzg3fEFQTX..." # Replace with your entry point entity GUID
    transaction_name = "WebTransaction/Action/checkout"
  }

  status_config_alert_policy {
    enabled = true
  }
}
```

## Apply your configuration [#apply]

After you define the resource block, run the following commands from your terminal:

```bash
terraform init
terraform plan
terraform apply
```

After Terraform successfully provisions the workload, navigate to **[one.newrelic.com > All capabilities](https://one.newrelic.com/all-capabilities) > Workloads**> to verify the new resource. You can inspect the automatically discovered entities in the transaction flow, review the alert policy bindings, and verify that the status rollups reflect the correct workload health.
