New Relic Terraform Provider

repository·main·Indexed 42 days ago

https://github.com/newrelic/terraform-provider-newrelic

Allows users to automate the configuration and management of New Relic resources using Terraform HCL. Includes tools for bulk importing users via run_bulk_users_import.sh and migrating legacy newrelic_nrql_drop_rule resources to newrelic_pipeline_cloud_rule (requiring provider version 3.72.1 or above).

Tokens
163.5K
Snippets
381
Records
595
Agent score
48%

What's inside New Relic Terraform Provider

  1. Manage New Relic fleets with newrelic_fleet

    main

    Use the newrelic_fleet resource to create and manage New Relic fleets for centralized agent management. Fleets allow you to organize agents across infrastructure types (HOST or KUBERNETESCLUSTER), deploy agent configurations centrally, manage updates, and organize entities using tags.

    resource "newrelic_fleet" "example" {
      name                = "Example Fleet"
      managed_entity_type = "HOST"
      operating_system    = "LINUX"
    }
  2. Use the newrelic_one_dashboard_raw resource

    main

    The newrelic_one_dashboard_raw resource allows you to create and manage New Relic One dashboards using a RawConfiguration.

    Warning: The newrelic_one_dashboard_json resource is preferred for configuring dashboards. newrelic_one_dashboard_raw does not support the latest dashboard features and receives less investment from New Relic.

    resource "newrelic_one_dashboard_raw" "exampledash" {
      name = "New Relic Terraform Example"
    
      page {
        name = "Page Name"
        widget {
          title = "Custom widget"
          row = 1
          column = 1
          width = 1
          height = 1
          visualization_id = "viz.custom"
          configuration = <<EOT
          {
            "legend": {
              "enabled": false
            },
            "nrqlQueries": [
              {
                "accountId": ` + accountID + `,
                "query": "SELECT average(loadAverageOneMinute), average(loadAverageFiveMinute), average(loadAverageFifteenMinute) from SystemSample SINCE 60 minutes ago    TIMESERIES"
              }
            ],
            "yAxisLeft": {
              "max": 100,
              "min": 50,
              "zero": false
            }
          }
          EOT
        }
      }
    }
  3. Manage New Relic account cardinality limit overrides

    main

    Use the newrelic_cardinality_management resource to control the cardinality limits for dimensional metrics in a New Relic account. Cardinality is the maximum number of unique attribute-value combinations a single metric name can produce per day.

    You can manage these limits in two modes:

    1. DEFAULT mode: Sets a single account-wide limit that applies to all metrics not otherwise specified.
    2. PER_METRIC mode: Sets specific, individual limits for one or more named metrics using metric blocks.

    Important Lifecycle Note: Cardinality overrides are managed via reset rather than removal. Running terraform destroy will reset the affected limit(s) back to the platform default of 100,000.

  4. Oracle Cloud Infrastructure (OCI) Integration Overview

    main

    The New Relic OCI integration collects metrics, logs, and metadata from supported OCI services. It utilizes Service Connector Hub pipelines for data export, Functions for transformation, and API polling for metadata/tags.

    Supported OCI Service Namespaces

    Use these namespaces when configuring Service Connector Hub to export metrics to New Relic:

    • API Gateway
    • Block Storage
    • Compute
    • Compute Agent
    • Compute Infrastructure Health
    • Compute Instance Health
    • Container Engine (OKE)
    • Container Instance
    • Functions (FaaS)
    • Health Checks
    • Instance Pools
    • Load Balancer (LBaaS)
    • Logging
    • Network Load Balancer
    • Object Storage
    • PostgreSQL
    • Queue
    • Service Connector Hub
    • Streaming
  5. Configure arguments for `newrelic_cloud_aws_integrations` integration blocks

    main

    The newrelic_cloud_aws_integrations resource uses specific integration blocks (e.g., cloudtrail, vpc, s3) to enable AWS service monitoring. Most arguments must be defined within these blocks.

    Common arguments across many blocks include:

    • aws_regions: A list of AWS regions to monitor.
    • metrics_polling_interval: The frequency of metric collection in seconds. Valid values vary by integration (typically 300, 900, 1800, or 3600).
    • tag_key and tag_value: Used to filter resources by AWS tags.
    • fetch_tags: Boolean to enable/disable tag fetching.
    • fetch_extended_inventory: Boolean to enable/disable extended inventory fetching.

    Note that account_id and linked_account_id are specified at the resource level, while service-specific configurations must reside inside their respective integration blocks.

  6. Manage New Relic Fleet entity assignments with newrelic_fleet_members

    main

    The newrelic_fleet_members resource manages which entities are assigned to one or more rings within a specific New Relic Fleet.

    Membership Model

    This resource uses an opt-in management model. It only tracks and manages the entities explicitly listed in the entity_ids argument of each ring block.

    Entities can enter a fleet ring via two paths:

    1. Agent Control instrumentation: Automatic assignment via the platform. These entities are invisible to Terraform and are not managed by this resource unless you explicitly add them to entity_ids.
    2. Explicit assignment: Managed via this resource using the FleetControlAddFleetMembers and FleetControlRemoveFleetMembers API mutations.

    Key Behaviors

    • Adopting Agent Control entities: To bring an entity managed by Agent Control under Terraform control, add its GUID to the entity_ids list. You will see a warning that the entity was skipped during the add mutation, but it will be adopted into the Terraform state on the next read. Once adopted, removing the GUID from your configuration will remove the entity from the ring.
    • Drift: If an entity listed in entity_ids is removed from the ring via an external process (out-of-band), Terraform will issue a warning and attempt to re-add it on the next apply. To stop Terraform from re-adding it, remove the GUID from your configuration.
    • Permissions: This resource requires the provider's API key to have Fleet Control permissions.
    resource "newrelic_fleet_members" "example" {
      fleet_id = newrelic_fleet.example.id
    
      ring {
        name       = "default"
        entity_ids = [
          "MXxOR0VQfEhPU1R8MTIzNDU2Nzg",
          "MXxOR0VQfEhPU1R8ODc2NTQzMjE",
        ]
      }
    }
  7. Configure scope for cross-account destinations

    main

    By default, the data source looks for destinations within the account scope linked to your API key. To access account-scoped or cross-account (Organization-scoped) destinations, you must provide the scope argument.

    The scope block requires:

    • type: Either ORGANIZATION or ACCOUNT.
    • id: The Organization UUID (if type is ORGANIZATION) or the New Relic account ID (if type is ACCOUNT).
    # Creating a cross-account destination
    resource "newrelic_notification_destination" "foo-destination" {
      name           = "webhook-example-cross-account-destination"
      type           = "WEBHOOK"
    
      property {
        key   = "source"
        value = "{\n\t\"name\": \"foo\"\n}"
        label = "Payload Template"
      }
    
      scope {
        type = "ORGANIZATION"
        id   = "00000000-0000-0000-0000-000000000000"
      }
    }
    
    # Looking up a cross-account destination
    data "newrelic_notification_destination" "foo-destination" {
      id = "destination_id"
    
      scope {
        type = "ORGANIZATION"
        id   = "organization_id"
      }
    }
  8. Configure authentication for notification destinations

    main

    Notification destinations support several authentication methods via nested blocks. Only one of auth_basic or auth_token can be used per destination. auth_custom_header is optional for most but required for WORKFLOW_AUTOMATION.

    • auth_basic: Requires user and password.
    • auth_token: Requires prefix (e.g., Token token=) and token.
    • auth_custom_header: Requires key and value. Multiple blocks are permitted.
    • OAuth2: Not available via Terraform.
  9. Understand the Synthetic Legacy Runtime EOL implications

    main

    New Relic is deprecating the legacy runtime for Synthetic monitors. If your monitors are not updated to the new runtime before the EOL dates, they may fail to run Synthetic checks.

    Key EOL Dates:

    • August 18, 2026: Node browser runtime monitors (Scripted Browser).
    • November 18, 2026: Node API runtime monitors (Scripted API).

    Implications for Terraform users: If you manage monitors via Terraform and do not update your configuration to use the new runtime attributes before the EOL:

    1. Drift: After the EOL, New Relic will force-upgrade monitors to the new runtime via the API. Running terraform plan will show a drift because the actual state in New Relic no longer matches your legacy configuration.
    2. Errors: Running terraform apply without updating your configuration to the new runtime values will result in an API error stating that usage of the legacy runtime is no longer supported.
  10. Configure `newrelic_one_dashboard` pages and widgets

    main

    A newrelic_one_dashboard is composed of one or more page blocks. Each page contains various widget types (e.g., widget_line, widget_pie, widget_table, widget_markdown).

    Page Configuration:

    • name (Required): The name of the page. If there is only one page, this becomes the Dashboard name.
    • description (Optional): Text describing the page.

    Common Widget Arguments: All widget blocks support these shared arguments:

    • title (Required): Widget title.
    • row / column (Required): Position starting at 1.
    • width / height: Dimensions from 1 to 12 (defaults: 4 and 3).
    • refresh_rate: Frequency in milliseconds (e.g., 30000 for 30s, 60000 for 60s, or auto).
    • ignore_time_range: If true, the widget's query time range overrides the dashboard time picker.
  11. Configure end_repeat for recurring downtimes

    main

    The end_repeat block specifies when a recurring downtime cycle (DAILY, WEEKLY, or MONTHLY) should stop. It is an optional argument for these modes.

    Inside end_repeat, you must provide exactly one of the following:

    • on_date: A string in YYYY-MM-DD format (Note: documentation says DDDD-MM-YY but example uses YYYY-MM-DD).
    • on_repeat: An integer specifying the number of occurrences after which the cycle ends.
    end_repeat {
      on_date = "2023-12-25"
    }
    
    # OR
    
    end_repeat {
      on_repeat = 6
    }
  12. Filter entities by Account ID

    main

    By default, newrelic_entity searches for entities and filters them using the account_id specified in your provider configuration.

    To retrieve an entity belonging to a specific subaccount (even if using a parent account's API key), use the account_id argument within the data source. This overrides the provider's default account filter.

    Note on accountId tag vs account_id argument:

    • The account_id argument filters the final result returned by the data source.
    • Adding a tag with the key accountID adds that ID to the NRQL query sent to NerdGraph, filtering the API response itself. The final entity returned will still be subject to the account_id argument or provider configuration.
    # Retrieve an entity from a specific subaccount
    data "newrelic_entity" "app" {
      name       = "my-app"
      account_id = 654321
      domain     = "APM"
      type       = "APPLICATION"
    }
    
    # Using a subaccount created via newrelic_account_management
    data "newrelic_entity" "app" {
      account_id = newrelic_account_management.default.id 
      name       = "my-app"
      domain     = "APM"
      type       = "APPLICATION"
    }