New Relic

Pulumi Official
Package maintained by Pulumi
v4.19.0 published on Wednesday, Jul 20, 2022 by Pulumi

AlertPolicy

Use this resource to create and manage New Relic alert policies.

Example Usage

Basic Usage

using Pulumi;
using NewRelic = Pulumi.NewRelic;

class MyStack : Stack
{
    public MyStack()
    {
        var foo = new NewRelic.AlertPolicy("foo", new NewRelic.AlertPolicyArgs
        {
            IncidentPreference = "PER_POLICY",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-newrelic/sdk/v4/go/newrelic"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := newrelic.NewAlertPolicy(ctx, "foo", &newrelic.AlertPolicyArgs{
			IncidentPreference: pulumi.String("PER_POLICY"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var foo = new AlertPolicy("foo", AlertPolicyArgs.builder()        
            .incidentPreference("PER_POLICY")
            .build());

        }
}
import pulumi
import pulumi_newrelic as newrelic

foo = newrelic.AlertPolicy("foo", incident_preference="PER_POLICY")
import * as pulumi from "@pulumi/pulumi";
import * as newrelic from "@pulumi/newrelic";

const foo = new newrelic.AlertPolicy("foo", {
    incidentPreference: "PER_POLICY", // PER_POLICY is default
});
resources:
  foo:
    type: newrelic:AlertPolicy
    properties:
      incidentPreference: PER_POLICY

Provision multiple notification channels and add those channels to a policy

using Pulumi;
using NewRelic = Pulumi.NewRelic;

class MyStack : Stack
{
    public MyStack()
    {
        // Provision a Slack notification channel.
        var slackChannel = new NewRelic.AlertChannel("slackChannel", new NewRelic.AlertChannelArgs
        {
            Type = "slack",
            Config = new NewRelic.Inputs.AlertChannelConfigArgs
            {
                Url = "https://hooks.slack.com/services/xxxxxxx/yyyyyyyy",
                Channel = "example-alerts-channel",
            },
        });
        // Provision an email notification channel.
        var emailChannel = new NewRelic.AlertChannel("emailChannel", new NewRelic.AlertChannelArgs
        {
            Type = "email",
            Config = new NewRelic.Inputs.AlertChannelConfigArgs
            {
                Recipients = "example@testing.com",
                IncludeJsonAttachment = "1",
            },
        });
        // Provision the alert policy.
        var policyWithChannels = new NewRelic.AlertPolicy("policyWithChannels", new NewRelic.AlertPolicyArgs
        {
            IncidentPreference = "PER_CONDITION",
            ChannelIds = 
            {
                slackChannel.Id,
                emailChannel.Id,
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-newrelic/sdk/v4/go/newrelic"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		slackChannel, err := newrelic.NewAlertChannel(ctx, "slackChannel", &newrelic.AlertChannelArgs{
			Type: pulumi.String("slack"),
			Config: &AlertChannelConfigArgs{
				Url:     pulumi.String("https://hooks.slack.com/services/xxxxxxx/yyyyyyyy"),
				Channel: pulumi.String("example-alerts-channel"),
			},
		})
		if err != nil {
			return err
		}
		emailChannel, err := newrelic.NewAlertChannel(ctx, "emailChannel", &newrelic.AlertChannelArgs{
			Type: pulumi.String("email"),
			Config: &AlertChannelConfigArgs{
				Recipients:            pulumi.String("example@testing.com"),
				IncludeJsonAttachment: pulumi.String("1"),
			},
		})
		if err != nil {
			return err
		}
		_, err = newrelic.NewAlertPolicy(ctx, "policyWithChannels", &newrelic.AlertPolicyArgs{
			IncidentPreference: pulumi.String("PER_CONDITION"),
			ChannelIds: pulumi.IntArray{
				slackChannel.ID(),
				emailChannel.ID(),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var slackChannel = new AlertChannel("slackChannel", AlertChannelArgs.builder()        
            .type("slack")
            .config(AlertChannelConfig.builder()
                .url("https://hooks.slack.com/services/xxxxxxx/yyyyyyyy")
                .channel("example-alerts-channel")
                .build())
            .build());

        var emailChannel = new AlertChannel("emailChannel", AlertChannelArgs.builder()        
            .type("email")
            .config(AlertChannelConfig.builder()
                .recipients("example@testing.com")
                .includeJsonAttachment("1")
                .build())
            .build());

        var policyWithChannels = new AlertPolicy("policyWithChannels", AlertPolicyArgs.builder()        
            .incidentPreference("PER_CONDITION")
            .channelIds(            
                slackChannel.getId(),
                emailChannel.getId())
            .build());

        }
}
import pulumi
import pulumi_newrelic as newrelic

# Provision a Slack notification channel.
slack_channel = newrelic.AlertChannel("slackChannel",
    type="slack",
    config=newrelic.AlertChannelConfigArgs(
        url="https://hooks.slack.com/services/xxxxxxx/yyyyyyyy",
        channel="example-alerts-channel",
    ))
# Provision an email notification channel.
email_channel = newrelic.AlertChannel("emailChannel",
    type="email",
    config=newrelic.AlertChannelConfigArgs(
        recipients="example@testing.com",
        include_json_attachment="1",
    ))
# Provision the alert policy.
policy_with_channels = newrelic.AlertPolicy("policyWithChannels",
    incident_preference="PER_CONDITION",
    channel_ids=[
        slack_channel.id,
        email_channel.id,
    ])
import * as pulumi from "@pulumi/pulumi";
import * as newrelic from "@pulumi/newrelic";

// Provision a Slack notification channel.
const slackChannel = new newrelic.AlertChannel("slackChannel", {
    type: "slack",
    config: {
        url: "https://hooks.slack.com/services/xxxxxxx/yyyyyyyy",
        channel: "example-alerts-channel",
    },
});
// Provision an email notification channel.
const emailChannel = new newrelic.AlertChannel("emailChannel", {
    type: "email",
    config: {
        recipients: "example@testing.com",
        includeJsonAttachment: "1",
    },
});
// Provision the alert policy.
const policyWithChannels = new newrelic.AlertPolicy("policyWithChannels", {
    incidentPreference: "PER_CONDITION",
    channelIds: [
        slackChannel.id,
        emailChannel.id,
    ],
});
resources:
  slackChannel:
    type: newrelic:AlertChannel
    properties:
      type: slack
      config:
        url: https://hooks.slack.com/services/xxxxxxx/yyyyyyyy
        channel: example-alerts-channel
  emailChannel:
    type: newrelic:AlertChannel
    properties:
      type: email
      config:
        recipients: example@testing.com
        includeJsonAttachment: 1
  policyWithChannels:
    type: newrelic:AlertPolicy
    properties:
      incidentPreference: PER_CONDITION
      channelIds:
        - ${slackChannel.id}
        - ${emailChannel.id}

Reference existing notification channels and add those channel to a policy

using Pulumi;
using NewRelic = Pulumi.NewRelic;

class MyStack : Stack
{
    public MyStack()
    {
        var slackChannel = Output.Create(NewRelic.GetAlertChannel.InvokeAsync(new NewRelic.GetAlertChannelArgs
        {
            Name = "slack-channel-notification",
        }));
        var emailChannel = Output.Create(NewRelic.GetAlertChannel.InvokeAsync(new NewRelic.GetAlertChannelArgs
        {
            Name = "test@example.com",
        }));
        // Provision the alert policy.
        var policyWithChannels = new NewRelic.AlertPolicy("policyWithChannels", new NewRelic.AlertPolicyArgs
        {
            IncidentPreference = "PER_CONDITION",
            ChannelIds = 
            {
                slackChannel.Apply(slackChannel => slackChannel.Id),
                emailChannel.Apply(emailChannel => emailChannel.Id),
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-newrelic/sdk/v4/go/newrelic"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		slackChannel, err := newrelic.LookupAlertChannel(ctx, &GetAlertChannelArgs{
			Name: "slack-channel-notification",
		}, nil)
		if err != nil {
			return err
		}
		emailChannel, err := newrelic.LookupAlertChannel(ctx, &GetAlertChannelArgs{
			Name: "test@example.com",
		}, nil)
		if err != nil {
			return err
		}
		_, err = newrelic.NewAlertPolicy(ctx, "policyWithChannels", &newrelic.AlertPolicyArgs{
			IncidentPreference: pulumi.String("PER_CONDITION"),
			ChannelIds: pulumi.IntArray{
				pulumi.String(slackChannel.Id),
				pulumi.String(emailChannel.Id),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var slackChannel = Output.of(NewrelicFunctions.getAlertChannel(GetAlertChannelArgs.builder()
            .name("slack-channel-notification")
            .build()));

        final var emailChannel = Output.of(NewrelicFunctions.getAlertChannel(GetAlertChannelArgs.builder()
            .name("test@example.com")
            .build()));

        var policyWithChannels = new AlertPolicy("policyWithChannels", AlertPolicyArgs.builder()        
            .incidentPreference("PER_CONDITION")
            .channelIds(            
                slackChannel.apply(getAlertChannelResult -> getAlertChannelResult.getId()),
                emailChannel.apply(getAlertChannelResult -> getAlertChannelResult.getId()))
            .build());

        }
}
import pulumi
import pulumi_newrelic as newrelic

slack_channel = newrelic.get_alert_channel(name="slack-channel-notification")
email_channel = newrelic.get_alert_channel(name="test@example.com")
# Provision the alert policy.
policy_with_channels = newrelic.AlertPolicy("policyWithChannels",
    incident_preference="PER_CONDITION",
    channel_ids=[
        slack_channel.id,
        email_channel.id,
    ])
import * as pulumi from "@pulumi/pulumi";
import * as newrelic from "@pulumi/newrelic";

const slackChannel = newrelic.getAlertChannel({
    name: "slack-channel-notification",
});
const emailChannel = newrelic.getAlertChannel({
    name: "test@example.com",
});
// Provision the alert policy.
const policyWithChannels = new newrelic.AlertPolicy("policyWithChannels", {
    incidentPreference: "PER_CONDITION",
    channelIds: [
        slackChannel.then(slackChannel => slackChannel.id),
        emailChannel.then(emailChannel => emailChannel.id),
    ],
});
resources:
  policyWithChannels:
    type: newrelic:AlertPolicy
    properties:
      incidentPreference: PER_CONDITION
      channelIds:
        - ${slackChannel.id}
        - ${emailChannel.id}
variables:
  slackChannel:
    Fn::Invoke:
      Function: newrelic:getAlertChannel
      Arguments:
        name: slack-channel-notification
  emailChannel:
    Fn::Invoke:
      Function: newrelic:getAlertChannel
      Arguments:
        name: test@example.com

Create a AlertPolicy Resource

new AlertPolicy(name: string, args?: AlertPolicyArgs, opts?: CustomResourceOptions);
@overload
def AlertPolicy(resource_name: str,
                opts: Optional[ResourceOptions] = None,
                account_id: Optional[int] = None,
                channel_ids: Optional[Sequence[int]] = None,
                incident_preference: Optional[str] = None,
                name: Optional[str] = None)
@overload
def AlertPolicy(resource_name: str,
                args: Optional[AlertPolicyArgs] = None,
                opts: Optional[ResourceOptions] = None)
func NewAlertPolicy(ctx *Context, name string, args *AlertPolicyArgs, opts ...ResourceOption) (*AlertPolicy, error)
public AlertPolicy(string name, AlertPolicyArgs? args = null, CustomResourceOptions? opts = null)
public AlertPolicy(String name, AlertPolicyArgs args)
public AlertPolicy(String name, AlertPolicyArgs args, CustomResourceOptions options)
type: newrelic:AlertPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args AlertPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args AlertPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args AlertPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args AlertPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args AlertPolicyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

AlertPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The AlertPolicy resource accepts the following input properties:

AccountId int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

ChannelIds List<int>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

IncidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

Name string

The name of the policy.

AccountId int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

ChannelIds []int

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

IncidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

Name string

The name of the policy.

accountId Integer

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds List<Integer>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference String

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name String

The name of the policy.

accountId number

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds number[]

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name string

The name of the policy.

account_id int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channel_ids Sequence[int]

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incident_preference str

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name str

The name of the policy.

accountId Number

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds List<Number>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference String

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name String

The name of the policy.

Outputs

All input properties are implicitly available as output properties. Additionally, the AlertPolicy resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up an Existing AlertPolicy Resource

Get an existing AlertPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: AlertPolicyState, opts?: CustomResourceOptions): AlertPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        account_id: Optional[int] = None,
        channel_ids: Optional[Sequence[int]] = None,
        incident_preference: Optional[str] = None,
        name: Optional[str] = None) -> AlertPolicy
func GetAlertPolicy(ctx *Context, name string, id IDInput, state *AlertPolicyState, opts ...ResourceOption) (*AlertPolicy, error)
public static AlertPolicy Get(string name, Input<string> id, AlertPolicyState? state, CustomResourceOptions? opts = null)
public static AlertPolicy get(String name, Output<String> id, AlertPolicyState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AccountId int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

ChannelIds List<int>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

IncidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

Name string

The name of the policy.

AccountId int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

ChannelIds []int

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

IncidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

Name string

The name of the policy.

accountId Integer

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds List<Integer>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference String

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name String

The name of the policy.

accountId number

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds number[]

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference string

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name string

The name of the policy.

account_id int

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channel_ids Sequence[int]

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incident_preference str

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name str

The name of the policy.

accountId Number

The New Relic account ID to operate on. This allows the user to override the account_id attribute set on the provider. Defaults to the environment variable NEW_RELIC_ACCOUNT_ID.

channelIds List<Number>

An array of channel IDs (integers) to assign to the policy. Adding or removing channel IDs from this array will result in a new alert policy resource being created and the old one being destroyed. Also note that channel IDs cannot be imported.

incidentPreference String

The rollup strategy for the policy. Options include: PER_POLICY, PER_CONDITION, or PER_CONDITION_AND_TARGET. The default is PER_POLICY.

name String

The name of the policy.

Import

Alert policies can be imported using a composite ID of <id>:<account_id>, where account_id is the account number scoped to the alert policy resource. Example import

 $ pulumi import newrelic:index/alertPolicy:AlertPolicy foo 23423556:4593020

Please note that channel IDs (channel_ids) cannot be imported due channels being a separate resource. However, to add channels to an imported alert policy, you can import the policy, add the channel_ids attribute with the associated channel IDs, then run terraform apply. This will result in the original alert policy being destroyed and a new alert policy being created along with the channels being added to the policy.

Package Details

Repository
https://github.com/pulumi/pulumi-newrelic
License
Apache-2.0
Notes

This Pulumi package is based on the newrelic Terraform Provider.