New Relic

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

AlertPolicyChannel

Use this resource to map alert policies to alert channels in New Relic.

Example Usage

using Pulumi;
using NewRelic = Pulumi.NewRelic;

class MyStack : Stack
{
    public MyStack()
    {
        var examplePolicy = Output.Create(NewRelic.GetAlertPolicy.InvokeAsync(new NewRelic.GetAlertPolicyArgs
        {
            Name = "my-alert-policy",
        }));
        // Creates an email alert channel.
        var emailChannel = new NewRelic.AlertChannel("emailChannel", new NewRelic.AlertChannelArgs
        {
            Type = "email",
            Config = new NewRelic.Inputs.AlertChannelConfigArgs
            {
                Recipients = "foo@example.com",
                IncludeJsonAttachment = "1",
            },
        });
        // Creates a Slack alert channel.
        var slackChannel = new NewRelic.AlertChannel("slackChannel", new NewRelic.AlertChannelArgs
        {
            Type = "slack",
            Config = new NewRelic.Inputs.AlertChannelConfigArgs
            {
                Channel = "#example-channel",
                Url = "http://example-org.slack.com",
            },
        });
        // Applies the created channels above to the alert policy
        // referenced at the top of the config.
        var foo = new NewRelic.AlertPolicyChannel("foo", new NewRelic.AlertPolicyChannelArgs
        {
            PolicyId = newrelic_alert_policy.Example_policy.Id,
            ChannelIds = 
            {
                emailChannel.Id,
                slackChannel.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 {
		_, err := newrelic.LookupAlertPolicy(ctx, &GetAlertPolicyArgs{
			Name: "my-alert-policy",
		}, nil)
		if err != nil {
			return err
		}
		emailChannel, err := newrelic.NewAlertChannel(ctx, "emailChannel", &newrelic.AlertChannelArgs{
			Type: pulumi.String("email"),
			Config: &AlertChannelConfigArgs{
				Recipients:            pulumi.String("foo@example.com"),
				IncludeJsonAttachment: pulumi.String("1"),
			},
		})
		if err != nil {
			return err
		}
		slackChannel, err := newrelic.NewAlertChannel(ctx, "slackChannel", &newrelic.AlertChannelArgs{
			Type: pulumi.String("slack"),
			Config: &AlertChannelConfigArgs{
				Channel: pulumi.String("#example-channel"),
				Url:     pulumi.String("http://example-org.slack.com"),
			},
		})
		if err != nil {
			return err
		}
		_, err = newrelic.NewAlertPolicyChannel(ctx, "foo", &newrelic.AlertPolicyChannelArgs{
			PolicyId: pulumi.Any(newrelic_alert_policy.Example_policy.Id),
			ChannelIds: pulumi.IntArray{
				emailChannel.ID(),
				slackChannel.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 examplePolicy = Output.of(NewrelicFunctions.getAlertPolicy(GetAlertPolicyArgs.builder()
            .name("my-alert-policy")
            .build()));

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

        var slackChannel = new AlertChannel("slackChannel", AlertChannelArgs.builder()        
            .type("slack")
            .config(AlertChannelConfig.builder()
                .channel("#example-channel")
                .url("http://example-org.slack.com")
                .build())
            .build());

        var foo = new AlertPolicyChannel("foo", AlertPolicyChannelArgs.builder()        
            .policyId(newrelic_alert_policy.getExample_policy().getId())
            .channelIds(            
                emailChannel.getId(),
                slackChannel.getId())
            .build());

        }
}
import pulumi
import pulumi_newrelic as newrelic

example_policy = newrelic.get_alert_policy(name="my-alert-policy")
# Creates an email alert channel.
email_channel = newrelic.AlertChannel("emailChannel",
    type="email",
    config=newrelic.AlertChannelConfigArgs(
        recipients="foo@example.com",
        include_json_attachment="1",
    ))
# Creates a Slack alert channel.
slack_channel = newrelic.AlertChannel("slackChannel",
    type="slack",
    config=newrelic.AlertChannelConfigArgs(
        channel="#example-channel",
        url="http://example-org.slack.com",
    ))
# Applies the created channels above to the alert policy
# referenced at the top of the config.
foo = newrelic.AlertPolicyChannel("foo",
    policy_id=newrelic_alert_policy["example_policy"]["id"],
    channel_ids=[
        email_channel.id,
        slack_channel.id,
    ])
import * as pulumi from "@pulumi/pulumi";
import * as newrelic from "@pulumi/newrelic";

const examplePolicy = newrelic.getAlertPolicy({
    name: "my-alert-policy",
});
// Creates an email alert channel.
const emailChannel = new newrelic.AlertChannel("emailChannel", {
    type: "email",
    config: {
        recipients: "foo@example.com",
        includeJsonAttachment: "1",
    },
});
// Creates a Slack alert channel.
const slackChannel = new newrelic.AlertChannel("slackChannel", {
    type: "slack",
    config: {
        channel: "#example-channel",
        url: "http://example-org.slack.com",
    },
});
// Applies the created channels above to the alert policy
// referenced at the top of the config.
const foo = new newrelic.AlertPolicyChannel("foo", {
    policyId: newrelic_alert_policy.example_policy.id,
    channelIds: [
        emailChannel.id,
        slackChannel.id,
    ],
});
resources:
  emailChannel:
    type: newrelic:AlertChannel
    properties:
      type: email
      config:
        recipients: foo@example.com
        includeJsonAttachment: 1
  slackChannel:
    type: newrelic:AlertChannel
    properties:
      type: slack
      config:
        channel: '#example-channel'
        url: http://example-org.slack.com
  foo:
    type: newrelic:AlertPolicyChannel
    properties:
      policyId: ${newrelic_alert_policy.example_policy.id}
      channelIds:
        - ${emailChannel.id}
        - ${slackChannel.id}
variables:
  examplePolicy:
    Fn::Invoke:
      Function: newrelic:getAlertPolicy
      Arguments:
        name: my-alert-policy

Create a AlertPolicyChannel Resource

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

name string
The unique name of the resource.
args AlertPolicyChannelArgs
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 AlertPolicyChannelArgs
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 AlertPolicyChannelArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args AlertPolicyChannelArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args AlertPolicyChannelArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

AlertPolicyChannel 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 AlertPolicyChannel resource accepts the following input properties:

ChannelIds List<int>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

PolicyId int

The ID of the policy.

AccountId int

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

ChannelIds []int

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

PolicyId int

The ID of the policy.

AccountId int

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds List<Integer>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId Integer

The ID of the policy.

accountId Integer

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds number[]

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId number

The ID of the policy.

accountId number

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channel_ids Sequence[int]

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policy_id int

The ID of the policy.

account_id int

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds List<Number>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId Number

The ID of the policy.

accountId Number

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

Outputs

All input properties are implicitly available as output properties. Additionally, the AlertPolicyChannel 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 AlertPolicyChannel Resource

Get an existing AlertPolicyChannel 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?: AlertPolicyChannelState, opts?: CustomResourceOptions): AlertPolicyChannel
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        account_id: Optional[int] = None,
        channel_ids: Optional[Sequence[int]] = None,
        policy_id: Optional[int] = None) -> AlertPolicyChannel
func GetAlertPolicyChannel(ctx *Context, name string, id IDInput, state *AlertPolicyChannelState, opts ...ResourceOption) (*AlertPolicyChannel, error)
public static AlertPolicyChannel Get(string name, Input<string> id, AlertPolicyChannelState? state, CustomResourceOptions? opts = null)
public static AlertPolicyChannel get(String name, Output<String> id, AlertPolicyChannelState 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

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

ChannelIds List<int>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

PolicyId int

The ID of the policy.

AccountId int

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

ChannelIds []int

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

PolicyId int

The ID of the policy.

accountId Integer

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds List<Integer>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId Integer

The ID of the policy.

accountId number

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds number[]

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId number

The ID of the policy.

account_id int

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channel_ids Sequence[int]

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policy_id int

The ID of the policy.

accountId Number

Determines the New Relic account where the alert policy channel will be created. Defaults to the account associated with the API key used.

channelIds List<Number>

Array of channel IDs to apply to the specified policy. We recommended sorting channel IDs in ascending order to avoid drift in your state.

policyId Number

The ID of the policy.

Import

Alert policy channels can be imported using the following notation<policyID>:<channelID>:<channelID>, e.g.

 $ pulumi import newrelic:index/alertPolicyChannel:AlertPolicyChannel foo 123456:3462754:2938324

When importing newrelic_alert_policy_channel resource, the attribute channel_ids* will be set in your Terraform state. You can import multiple channels as long as those channel IDs are included as part of the import ID hash.

Package Details

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

This Pulumi package is based on the newrelic Terraform Provider.