New Relic Terraform Provider for Declarative Observability

New Relic and Terraform together turn observability configuration into repeatable infrastructure code. Terraform is a popular infrastructure-as-code software tool built by HashiCorp. You use it to provision all kinds of infrastructure and services, including New Relic and alerts. New Relic has developed a Terraform provider to configure alerts, synthetics, dashboards, and other parts of New Relic through declarative configuration files.

When they work together, monitoring becomes part of your infrastructure code rather than an afterthought. Terraform provisions dashboards, alert policies, notification channels, and workloads. New Relic receives those definitions, applies them to your account, and starts collecting telemetry the moment your stack lands. This turns observability from a manual admin task into repeatable configuration logic.

What the New Relic Terraform Provider Automates

With the New Relic Terraform provider you are able to automate the configuration of New Relic. The provider lets you define alert policies, notification channels, dashboards, and synthetic monitors as code, so your observability configuration gets the same rigor as your infrastructure.

Terraform handles authentication, dependencies, and updates. The provider takes care of idempotency, so you never overwrite data by accident. Provide the right project API key and Terraform ensures New Relic’s configuration matches your desired state.

The provider is documented at the official registry and is supported alongside Terraform releases. New Relic and the Terraform team will support Terraform versions up to 2 years after the latest release. We advice to always upgrade to the latest version of Terraform and the New Relic Terraform provider.

To use the latest version of the provider in your Terraform environment, run terraform init and Terraform will automatically install the provider.

If you wish to pin your environment to a specific release of the provider, you can do so with a required_providers statement in your Terraform manifest. The terraform configuration block varies slightly depending on which Terraform version you're using.

Getting Started Prerequisites

Before you begin, you should have some basic knowledge of both New Relic and Terraform. If you haven't deployed a New Relic open source agent yet, install New Relic for your application. Also, install the Terraform CLI.

You need three things from your New Relic account:

  • Account ID - Found in the URL when logged in or in Account Settings
  • API Key - A User API key (not the License key or Insights key)
  • Region - US, EU, or JP

Getting Your API Key

  • Go to New Relic > API Keys (under your profile menu)
  • Click "Create a key"
  • Select "User" as the key type
  • Give it a name like "Terraform Automation"

Set environment variables

export NEW_RELIC_ACCOUNT_ID="1234567" export NEW_RELIC_API_KEY="NRAK-your-api-key-here" export NEW_RELIC_REGION="US" # or "EU" / "JP"

Most user keys begin with the prefix NRAK-.

Provider Configuration

Bootstrap Terraform and the New Relic provider starts by initializing a working directory and creating a Terraform configuration file:

$mkdir terraform-project && cd terraform-project $touch main.tf

Next, instruct Terraform to install and use the New Relic provider, by setting the terraform and required_providers blocks in main.tf:

terraform { required_version = "~> 1.0" required_providers { newrelic = { source = "newrelic/newrelic" } } }

In this code block, you're setting the required version of Terraform to 1.0 and setting the New Relic provider to the latest 2.x version. Using the right version constraints for your setup will provide better stability with your Terraform runs.

Now configure the New Relic provider with the following items:

  • Your New Relic account ID.
  • Your New Relic API key. Most user keys begin with the prefix NRAK-.
  • Your New Relic region

Basic Provider Configuration

```

versions.tf

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

```

provider.tf

provider "newrelic" {
accountid = var.newrelicaccountid
apikey = var.newrelicapikey
region = var.newrelicregion
}
```

Variable definitions:

variable "new_relic_account_id" { description = "New Relic account ID" type = number } variable "new_relic_api_key" { description = "New Relic User API key" type = string sensitive = true } variable "new_relic_region" { description = "New Relic region (US, EU, or JP)" type = string default = "US" }

Or using environment variables, the simplest approach:

provider "newrelic" { # Reads from NEW_RELIC_ACCOUNT_ID, NEW_RELIC_API_KEY, and }

The Terraform New Relic provider lets you define alert policies, notification channels, dashboards, and synthetic monitors as code, so your observability configuration gets the same rigor as your infrastructure.

Golden Signals Alert Foundation

In this guide you will learn how to set up New Relic with Terraform, but you can review the New Relic Terraform provider documentation to learn how to set up other New Relic resources.

You'll start by provisioning an alert policy, four alert conditions, and a notification channel. The four alert conditions are based on the four golden signals of monitoring introduced in Google’s Site Reliability Engineering book:

  • Latency: The amount of time it takes your application to service a request.
  • Traffic: The amount of requests your system receives.
  • Errors: The rate of requests that fail.
  • Saturation: The stress on resources to meet the demands of your application.
Signal Definition
Latency The amount of time it takes your application to service a request
Traffic The amount of requests your system receives
Errors The rate of requests that fail
Saturation The stress on resources to meet the demands of your application

This pattern provides a consistent baseline for observability across services.

Workflow Benefits

What problems does New Relic Terraform actually solve?

  • Eliminates drift between environments by codifying observability setup.
  • Reduces manual dashboard creation across accounts and teams.
  • Simplifies compliance by keeping monitoring config under version control.
  • Speeds onboarding of new services with preapproved policies.
  • Keeps alerting consistent, transparent, and traceable.

Teams that adopt this workflow find shorter review cycles and cleaner rollbacks. Infrastructure engineers stop wasting energy replicating the same dashboards. Developers gain faster feedback when performance shifts, without digging through multiple consoles.

You deploy the same infrastructure twice. It behaves differently both times. The logs don’t match, the metrics drift, and that one dashboard keeps disappearing. This is the exact kind of chaos that New Relic Terraform was built to fix.

New Relic tracks how your systems behave. Terraform defines what those systems should be. When they work together, monitoring becomes part of your infrastructure code rather than an afterthought. No more “oh right, we forgot to instrument that service.” Instead, your observability setup spins up right alongside your compute and storage resources.

Think of New Relic Terraform like a handshake between two universes: automation and visibility. Terraform provisions dashboards, alert policies, notification channels, and workloads. New Relic receives those definitions, applies them to your account, and starts collecting telemetry the moment your stack lands. This turns observability from a manual admin task into repeatable configuration logic.

IDE Integration and Tips

Simplify your workflow by bringing the Terraform documentation right into your IDE with New Relic's CodeStream IDE extension. Add templates for any New Relic resource type with just a click.

How do I connect New Relic and Terraform?

You link your New Relic API key into Terraform’s provider configuration, add a few resource blocks for things like alerts or applications, and apply. Terraform handles authentication, dependencies, and updates. The provider takes care of idempotency, so you never overwrite data by accident.

Follow the instructions on Terraform provider documentation: Getting Started with the New Relic Provider

Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files.

Provider Specs

Item Value
Provider newrelic/newrelic
Minimum Terraform 1.0+
Support window Up to 2 years after latest Terraform release
Authentication User API key starting with NRAK-
Regions US, EU, JP
Core resources alert policies, notification channels, dashboards, synthetic monitors, workloads

Conclusion

New Relic Terraform bridges infrastructure automation and observability. By codifying alert policies, notification channels, dashboards, and synthetic monitors, teams eliminate drift, enforce consistent alerting, and keep monitoring configuration under version control. The provider supports Terraform 1.0+, requires an Account ID, User API key, and region, and enables idempotent application of observability resources through declarative configuration.

The four golden signals provide a practical starting point for alert conditions. Provider configuration can be done with explicit variables or environment variables, and version pinning improves stability. When combined with IDE extensions and a required_providers block, the workflow becomes repeatable across environments and teams.

Adopting the New Relic Terraform provider turns observability setup from manual admin work into infrastructure code that spins up alongside compute and storage, with shorter review cycles, cleaner rollbacks, and transparent, traceable alerting.

Sources

  1. New Relic Terraform Intro
  2. New Relic Terraform Provider GitHub
  3. New Relic Instant Observability Terraform
  4. OneUptime New Relic Terraform Configuration
  5. Hoop Dev New Relic Terraform Guide

Related Posts