newrelic.AlertPolicyChannel
Explore with Pulumi AI
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 a future major release. As an alternative, you can map channels to policies using the resourcenewrelic.Workflow
for a detailed illustration on setting up channels and workflows with these resources.
Example Usage
The example below will apply multiple alert channels to an existing New Relic alert policy.
import * as pulumi from "@pulumi/pulumi";
import * as newrelic from "@pulumi/newrelic";
// Fetches the data for this policy from your New Relic account
// and is referenced in the newrelic_alert_policy_channel block below.
const examplePolicy = newrelic.getAlertPolicy({
name: "my-alert-policy",
});
// Creates an email alert channel.
const emailChannel = new newrelic.AlertChannel("email_channel", {
name: "bar",
type: "email",
config: {
recipients: "foo@example.com",
includeJsonAttachment: "1",
},
});
// Creates a Slack alert channel.
const slackChannel = new newrelic.AlertChannel("slack_channel", {
name: "slack-channel-example",
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,
],
});
import pulumi
import pulumi_newrelic as newrelic
# Fetches the data for this policy from your New Relic account
# and is referenced in the newrelic_alert_policy_channel block below.
example_policy = newrelic.get_alert_policy(name="my-alert-policy")
# Creates an email alert channel.
email_channel = newrelic.AlertChannel("email_channel",
name="bar",
type="email",
config=newrelic.AlertChannelConfigArgs(
recipients="foo@example.com",
include_json_attachment="1",
))
# Creates a Slack alert channel.
slack_channel = newrelic.AlertChannel("slack_channel",
name="slack-channel-example",
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,
])
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 {
// Fetches the data for this policy from your New Relic account
// and is referenced in the newrelic_alert_policy_channel block below.
examplePolicy, err := newrelic.LookupAlertPolicy(ctx, &newrelic.LookupAlertPolicyArgs{
Name: "my-alert-policy",
}, nil)
if err != nil {
return err
}
// Creates an email alert channel.
emailChannel, err := newrelic.NewAlertChannel(ctx, "email_channel", &newrelic.AlertChannelArgs{
Name: pulumi.String("bar"),
Type: pulumi.String("email"),
Config: &newrelic.AlertChannelConfigArgs{
Recipients: pulumi.String("foo@example.com"),
IncludeJsonAttachment: pulumi.String("1"),
},
})
if err != nil {
return err
}
// Creates a Slack alert channel.
slackChannel, err := newrelic.NewAlertChannel(ctx, "slack_channel", &newrelic.AlertChannelArgs{
Name: pulumi.String("slack-channel-example"),
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
}
// Applies the created channels above to the alert policy
// referenced at the top of the config.
_, err = newrelic.NewAlertPolicyChannel(ctx, "foo", &newrelic.AlertPolicyChannelArgs{
PolicyId: pulumi.String(examplePolicy.Id),
ChannelIds: pulumi.StringArray{
emailChannel.ID(),
slackChannel.ID(),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using NewRelic = Pulumi.NewRelic;
return await Deployment.RunAsync(() =>
{
// Fetches the data for this policy from your New Relic account
// and is referenced in the newrelic_alert_policy_channel block below.
var examplePolicy = NewRelic.GetAlertPolicy.Invoke(new()
{
Name = "my-alert-policy",
});
// Creates an email alert channel.
var emailChannel = new NewRelic.AlertChannel("email_channel", new()
{
Name = "bar",
Type = "email",
Config = new NewRelic.Inputs.AlertChannelConfigArgs
{
Recipients = "foo@example.com",
IncludeJsonAttachment = "1",
},
});
// Creates a Slack alert channel.
var slackChannel = new NewRelic.AlertChannel("slack_channel", new()
{
Name = "slack-channel-example",
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 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) {
// Fetches the data for this policy from your New Relic account
// and is referenced in the newrelic_alert_policy_channel block below.
final var examplePolicy = NewrelicFunctions.getAlertPolicy(GetAlertPolicyArgs.builder()
.name("my-alert-policy")
.build());
// Creates an email alert channel.
var emailChannel = new AlertChannel("emailChannel", AlertChannelArgs.builder()
.name("bar")
.type("email")
.config(AlertChannelConfigArgs.builder()
.recipients("foo@example.com")
.includeJsonAttachment("1")
.build())
.build());
// Creates a Slack alert channel.
var slackChannel = new AlertChannel("slackChannel", AlertChannelArgs.builder()
.name("slack-channel-example")
.type("slack")
.config(AlertChannelConfigArgs.builder()
.channel("#example-channel")
.url("http://example-org.slack.com")
.build())
.build());
// Applies the created channels above to the alert policy
// referenced at the top of the config.
var foo = new AlertPolicyChannel("foo", AlertPolicyChannelArgs.builder()
.policyId(examplePolicy.applyValue(getAlertPolicyResult -> getAlertPolicyResult.id()))
.channelIds(
emailChannel.id(),
slackChannel.id())
.build());
}
}
resources:
# Creates an email alert channel.
emailChannel:
type: newrelic:AlertChannel
name: email_channel
properties:
name: bar
type: email
config:
recipients: foo@example.com
includeJsonAttachment: '1'
# Creates a Slack alert channel.
slackChannel:
type: newrelic:AlertChannel
name: slack_channel
properties:
name: slack-channel-example
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:
# Fetches the data for this policy from your New Relic account
# and is referenced in the newrelic_alert_policy_channel block below.
examplePolicy:
fn::invoke:
Function: newrelic:getAlertPolicy
Arguments:
name: my-alert-policy
Create AlertPolicyChannel Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new AlertPolicyChannel(name: string, args: AlertPolicyChannelArgs, opts?: CustomResourceOptions);
@overload
def AlertPolicyChannel(resource_name: str,
args: AlertPolicyChannelArgs,
opts: Optional[ResourceOptions] = None)
@overload
def AlertPolicyChannel(resource_name: str,
opts: Optional[ResourceOptions] = None,
channel_ids: Optional[Sequence[str]] = None,
policy_id: Optional[str] = None,
account_id: Optional[str] = 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.
Parameters
- 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.
Constructor example
The following reference example uses placeholder values for all input properties.
var alertPolicyChannelResource = new NewRelic.AlertPolicyChannel("alertPolicyChannelResource", new()
{
ChannelIds = new[]
{
"string",
},
PolicyId = "string",
AccountId = "string",
});
example, err := newrelic.NewAlertPolicyChannel(ctx, "alertPolicyChannelResource", &newrelic.AlertPolicyChannelArgs{
ChannelIds: pulumi.StringArray{
pulumi.String("string"),
},
PolicyId: pulumi.String("string"),
AccountId: pulumi.String("string"),
})
var alertPolicyChannelResource = new AlertPolicyChannel("alertPolicyChannelResource", AlertPolicyChannelArgs.builder()
.channelIds("string")
.policyId("string")
.accountId("string")
.build());
alert_policy_channel_resource = newrelic.AlertPolicyChannel("alertPolicyChannelResource",
channel_ids=["string"],
policy_id="string",
account_id="string")
const alertPolicyChannelResource = new newrelic.AlertPolicyChannel("alertPolicyChannelResource", {
channelIds: ["string"],
policyId: "string",
accountId: "string",
});
type: newrelic:AlertPolicyChannel
properties:
accountId: string
channelIds:
- string
policyId: string
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:
- Channel
Ids List<string> - 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 string - The ID of the policy.
- Account
Id string - 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 []string - 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 string - The ID of the policy.
- Account
Id string - 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 List<String> - 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 String - The ID of the policy.
- account
Id String - 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 string[] - 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 string - The ID of the policy.
- account
Id string - 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[str] - 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 str - The ID of the policy.
- account_
id str - 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 List<String> - 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 String - The ID of the policy.
- account
Id String - 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[str] = None,
channel_ids: Optional[Sequence[str]] = None,
policy_id: Optional[str] = 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.
- Account
Id string - 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 List<string> - 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 string - The ID of the policy.
- Account
Id string - 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 []string - 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 string - The ID of the policy.
- account
Id String - 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 List<String> - 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 String - The ID of the policy.
- account
Id string - 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 string[] - 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 string - The ID of the policy.
- account_
id str - 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[str] - 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 str - The ID of the policy.
- account
Id String - 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 List<String> - 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 String - 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.
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- New Relic pulumi/pulumi-newrelic
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
newrelic
Terraform Provider.