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
	})
}
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
});

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,
            },
        });
    }

}

Coming soon!

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,
    ],
});

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),
            },
        });
    }

}

Coming soon!

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),
    ],
});

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)
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.

AlertPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model 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 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.

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 str
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)
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.

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 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.

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.