Most teams start the same way. Someone builds a dashboard in the UI and adds an alert, and it works. Then the team grows. You add a staging environment, a second region, and a few more services. Soon nobody can answer simple questions. Which alerts exist in production? Who changed that threshold last month? Why does staging look nothing like prod? Terraform offers a better answer: describe your monitoring in files, and let those files be the record. That’s the cost of monitoring set up by hand. It works until it doesn’t, and by then it’s hard to fix.
Why Teams Switch to Observability as Code
- Version control: Define dashboards, alerts, and settings in code so every change is tracked, reviewed, and audited.
- Drift prevention: Automatically reconcile live resource states with configuration files to catch manual UI modifications.
- Simple deployment: Declare the provider, pass credentials via environment variables, and apply configuration changes via standard CLI workflows.
Why hand-built monitoring breaks down
- Changes go untracked. When someone edits a setting in the UI, nothing records it. You find out only when something breaks.
- Environments drift apart. Staging and production start the same and slowly diverge. Problems that show up in production never appear in testing.
- Nobody reviews changes. A new alert or a changed threshold doesn’t go through the same review as application code.
- Recovery is slow. If something gets deleted or misconfigured, rebuilding it means remembering what was there.
Configuration drift, the gap between what you think is running and what actually is, is the root of most of these problems.
Treat monitoring like Infrastructure as Code (IaC) with Terraform
Terraform lets you describe infrastructure in configuration files. With the New Relic Terraform provider, you can describe alert policies and other observability settings the same way.
Those files become the record of what your monitoring should look like. They give you three things:
- Governance: Changes go through the same review as application code, with a history of who changed what and why.
- Drift prevention: Terraform keeps a record that maps each resource in your configuration to the real object it created in New Relic. Every plan checks that record against what's actually live, which is how a manual edit in the UI shows up as a difference instead of going unnoticed. No state, no record, no way to tell what changed.
- Consistency: You define a setup once and apply it to each environment. Variables handle the differences, such as a stricter alert threshold in production.
Expert note: Running regular plans will catch most changes made outside your code. However, keep in mind a couple of exceptions: sensitive fields (like webhook URLs) are not read back from the API, and dashboard widget ordering can sometimes trigger false-positive diffs.
How Terraform fits the New Relic platform
Terraform and New Relic each handle a different part of the work:
- You describe the monitoring you want in Terraform configuration files, using the New Relic provider.
- Terraform applies it to your New Relic account, creating or updating the alert policies, conditions, and notifications you defined.
- Your services send data to New Relic through agents. Make sure at least one application has an agent installed, since alerts need data to evaluate.
- You check the results in the New Relic UI, such as the Alert Policies page, to confirm everything is set up as intended.
Terraform manages the configuration. New Relic evaluates the data and shows what it finds, so you can review your monitoring in the same place it runs.
What you can manage with Terraform
The New Relic provider covers the core alerting settings:
- Alert policies and NRQL-based alert conditions (newrelic_alert_policy, newrelic_nrql_alert_condition)
- Notification destinations, channels, and workflows (newrelic_notification_destination, newrelic_notification_channel, newrelic_workflow)
- Dashboards (newrelic_one_dashboard)
- Synthetic monitors (newrelic_synthetics_monitor, plus monitor-type variants for scripts, steps, and broken links)
- Service levels and SLOs (newrelic_service_level)
- Cloud integrations for AWS, Azure, and GCP (newrelic_cloud_aws_integrations, newrelic_cloud_azure_integrations, newrelic_cloud_gcp_integrations)
- Workloads and teams (newrelic_workload, newrelic_team)
- Log parsing rules, scorecards, fleet management, muting rules, and more
See the full list in the official docs: https://registry.terraform.io/providers/newrelic/newrelic/latest/docs
Getting started
The setup takes a few steps:
- Declare the New Relic provider in your Terraform configuration, with a pinned version.
- Set your account ID and user key as environment variables. Don’t put them in the file.
- Describe the alert policy and conditions you want, such as latency, traffic, errors, and saturation.
- Run a terraform plan to preview the changes.
- Run terraform apply to create them.
Code Block:
terraform { required_version = "~> 1.0" required_providers { newrelic = { source = "newrelic/newrelic" version = "~> 3.0" } } } variable "newrelic_account_id" { description = "Your New Relic account ID" type = number sensitive = true } variable "newrelic_api_key" { description = "Your New Relic User API key (NRAK-...)" type = string sensitive = true } provider "newrelic" { account_id = var.newrelic_account_id api_key = var.newrelic_api_key region = "US" } resource "newrelic_alert_policy" "golden_signals" { name = "Golden signals - prod" incident_preference = "PER_CONDITION" }
Commands:
$ terraform init # Downloads the New Relic provider and sets up the working directory. Run this once per configuration, and again any time you change the provider version. $ terraform plan # Shows what Terraform will create or change, without touching your New Relic account yet. $ terraform apply # Creates the alert policy and conditions. Terraform shows the same plan again and asks you to type "yes" to confirm.
Code results:
$ terraform plan Terraform used the selected providers to generate the following execution plan. # newrelic_alert_policy.golden_signals will be created + resource "newrelic_alert_policy" "golden_signals" { + account_id = (known after apply) + entity_guid = (known after apply) + id = (known after apply) + incident_preference = "PER_CONDITION" + name = "Golden signals - prod" } Plan: 1 to add, 0 to change, 0 to destroy. $ terraform apply newrelic_alert_policy.golden_signals: Creating... newrelic_alert_policy.golden_signals: Creation complete after 0s [id=8324692] Apply complete! Resources: 1 added, 0 changed, 0 destroyed. $ terraform destroy # newrelic_alert_policy.golden_signals will be destroyed - resource "newrelic_alert_policy" "golden_signals" { - account_id = [REDACTED] -> null - entity_guid = "[REDACTED]" -> null - id = "8324692" -> null - incident_preference = "PER_CONDITION" -> null - name = "Golden signals - prod" -> null } Plan: 0 to add, 0 to change, 1 to destroy. newrelic_alert_policy.golden_signals: Destroying... [id=8324692] newrelic_alert_policy.golden_signals: Destruction complete after 1s Destroy complete! Resources: 1 destroyed.
The full guide walks through four alert conditions, one for each golden signal, plus notifications. Those resources are the current versions, so use them rather than the deprecated alert channel resources. Once the configuration is in version control, the next change to your monitoring goes through a pull request, just like your code.
Scaling across teams
Teams with several services and environments can share configuration through reusable modules. The modules and remote storage guide covers how to organize and store that configuration.
Terraform made easy
Building every configuration manually isn’t required. Selecting the "View as code" option within any New Relic alert condition automatically produces the corresponding Terraform block pre-populated with your account ID, NRQL query, and threshold parameters. Simply paste that block into your repository to place the condition under code management.
Dashboards follow a similar workflow: export the dashboard JSON definition directly from the interface, then pass it to the newrelic_one_dashboard_json resource. Both approaches allow you to convert existing UI configurations into version-controlled files without starting from scratch.
What this means for engineering leaders
For engineering leaders, the value is visibility and control. Monitoring configuration has a single record, changes are reviewed before they apply, and every environment can follow the same setup. When that record lives in code, reliability becomes a shared practice rather than one person’s knowledge.
Next steps
- Start free with New Relic and connect your first environment.
- Read Getting started with New Relic and Terraform for the full setup guide.
- Talking about this for a larger team? Request a demo.
FAQs about Terraform and observability
- What is observability as code?It means managing dashboards, alerts, and other monitoring settings in configuration files. Those files are reviewed and versioned like application code.
- Do I still use the New Relic UI?Yes. Use the UI to explore your data. Use Terraform to define the monitoring settings you want to keep consistent across environments.
- Who should own the Terraform configuration?The team that owns the service usually owns its monitoring configuration. Platform teams often provide shared modules and standards.
Terraform Observability | Request a demo
Ben Rivera is a Senior Product Marketing Manager at New Relic, focused on OpenTelemetry-first experiences that help platform teams standardize faster and operate telemetry with confidence.
Gabriel "Gabe" Alabastro is a Senior Software Engineer at New Relic with a strong background in designing and developing scalable software solutions, building APIs and front-end services, and tackling complex technical challenges. Known for his thoughtful problem-solving, technical versatility, and collaborative approach, Gabe brings a strong sense of ownership to his work and enjoys helping teams deliver innovative, high-quality solutions.
The views expressed on this blog are those of the author and do not necessarily reflect the views of New Relic. Any solutions offered by the author are environment-specific and not part of the commercial solutions or support offered by New Relic. Please join us exclusively at the Explorers Hub (support.newrelic.com) for questions and support related to this blog post. This blog may contain links to content on third-party sites. By providing such links, New Relic does not adopt, guarantee, approve or endorse the information, views or products available on such sites.












