1. Packages
  2. New Relic
  3. API Docs
  4. AlertPolicyChannel
New Relic v5.15.0 published on Tuesday, Sep 26, 2023 by Pulumi

newrelic.AlertPolicyChannel

Explore with Pulumi AI

newrelic logo
New Relic v5.15.0 published on Tuesday, Sep 26, 2023 by Pulumi

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

    WARNING: The newrelic.AlertPolicyChannel resource is deprecated and will be removed in the next major release. For managing channel resources in Workflows, use newrelic.NotificationChannel.

    Example Usage

    The example below will apply multiple alert channels to an existing New Relic alert policy.

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using NewRelic = Pulumi.NewRelic;
    
    return await Deployment.RunAsync(() => 
    {
        var examplePolicy = NewRelic.GetAlertPolicy.Invoke(new()
        {
            Name = "my-alert-policy",
        });
    
        // Creates an email alert channel.
        var emailChannel = new NewRelic.AlertChannel("emailChannel", new()
        {
            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()
        {
            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()
        {
            PolicyId = examplePolicy.Apply(getAlertPolicyResult => getAlertPolicyResult.Id),
            ChannelIds = new[]
            {
                emailChannel.Id,
                slackChannel.Id,
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-newrelic/sdk/v5/go/newrelic"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		examplePolicy, err := newrelic.LookupAlertPolicy(ctx, &newrelic.LookupAlertPolicyArgs{
    			Name: "my-alert-policy",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		emailChannel, err := newrelic.NewAlertChannel(ctx, "emailChannel", &newrelic.AlertChannelArgs{
    			Type: pulumi.String("email"),
    			Config: &newrelic.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: &newrelic.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.String(examplePolicy.Id),
    			ChannelIds: pulumi.IntArray{
    				emailChannel.ID(),
    				slackChannel.ID(),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.newrelic.NewrelicFunctions;
    import com.pulumi.newrelic.inputs.GetAlertPolicyArgs;
    import com.pulumi.newrelic.AlertChannel;
    import com.pulumi.newrelic.AlertChannelArgs;
    import com.pulumi.newrelic.inputs.AlertChannelConfigArgs;
    import com.pulumi.newrelic.AlertPolicyChannel;
    import com.pulumi.newrelic.AlertPolicyChannelArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var examplePolicy = NewrelicFunctions.getAlertPolicy(GetAlertPolicyArgs.builder()
                .name("my-alert-policy")
                .build());
    
            var emailChannel = new AlertChannel("emailChannel", AlertChannelArgs.builder()        
                .type("email")
                .config(AlertChannelConfigArgs.builder()
                    .recipients("foo@example.com")
                    .includeJsonAttachment("1")
                    .build())
                .build());
    
            var slackChannel = new AlertChannel("slackChannel", AlertChannelArgs.builder()        
                .type("slack")
                .config(AlertChannelConfigArgs.builder()
                    .channel("#example-channel")
                    .url("http://example-org.slack.com")
                    .build())
                .build());
    
            var foo = new AlertPolicyChannel("foo", AlertPolicyChannelArgs.builder()        
                .policyId(examplePolicy.applyValue(getAlertPolicyResult -> getAlertPolicyResult.id()))
                .channelIds(            
                    emailChannel.id(),
                    slackChannel.id())
                .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=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: examplePolicy.then(examplePolicy => examplePolicy.id),
        channelIds: [
            emailChannel.id,
            slackChannel.id,
        ],
    });
    
    resources:
      # Creates an email alert channel.
      emailChannel:
        type: newrelic:AlertChannel
        properties:
          type: email
          config:
            recipients: foo@example.com
            includeJsonAttachment: '1'
      # Creates a Slack alert channel.
      slackChannel:
        type: newrelic:AlertChannel
        properties:
          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.
      foo:
        type: newrelic:AlertPolicyChannel
        properties:
          policyId: ${examplePolicy.id}
          channelIds:
            - ${emailChannel.id}
            - ${slackChannel.id}
    variables:
      examplePolicy:
        fn::invoke:
          Function: newrelic:getAlertPolicy
          Arguments:
            name: my-alert-policy
    

    Create 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 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
    New Relic pulumi/pulumi-newrelic
    License
    Apache-2.0
    Notes

    This Pulumi package is based on the newrelic Terraform Provider.

    newrelic logo
    New Relic v5.15.0 published on Tuesday, Sep 26, 2023 by Pulumi