Edgar Peixoto
07/14/2025, 3:36 PMresource "signoz_notification_channel" "email_channel" {
name = "Email Channel"
type = "email"
receivers {
email_config {
to = ["alerts@example.com"]
}
}
}
But the provider doc does not show the signoz_notification_channel resource.
Is there a doc for resource signoz_notification_channel?Nagesh Bansal
07/14/2025, 4:35 PMEdgar Peixoto
07/14/2025, 5:03 PMAshwini Manoj
08/26/2025, 2:53 PMEdgar Peixoto
08/26/2025, 6:03 PMterraform {
required_providers {
null = {
source = "hashicorp/null"
version = "~> 3.0"
}
}
}
resource "null_resource" "slack_notification_channel" {
triggers = {
name = var.name
slack_webhook_url = var.slack_webhook_url
slack_channel = var.slack_channel
send_resolved = var.send_resolved
signoz_endpoint = var.signoz_endpoint
signoz_api_token = var.signoz_api_token
title = var.title
text = var.description
}
provisioner "local-exec" {
command = <<-EOT
# First, check if the channel already exists
echo "Checking if channel '${var.name}' exists..."
CHANNELS_RESPONSE=$(curl -s -X GET ${var.signoz_endpoint}/api/v1/channels \
-H "SIGNOZ-API-KEY: ${var.signoz_api_token}" \
-H "Accept: application/json")
CHANNEL_ID=$(echo "$CHANNELS_RESPONSE" | jq -r '.data[]? | select(.name == "${var.name}") | .id')
if [ "$CHANNEL_ID" != "null" ] && [ "$CHANNEL_ID" != "" ]; then
# Channel exists, update it
echo "Channel '${var.name}' exists with ID: $CHANNEL_ID, updating..."
RESPONSE=$(curl -s -X PUT ${var.signoz_endpoint}/api/v1/channels/$CHANNEL_ID \
-H "SIGNOZ-API-KEY: ${var.signoz_api_token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '${jsonencode(local.slack_config)}')
echo "SigNoz API Update Response: $RESPONSE"
# Check if the update was successful
if echo "$RESPONSE" | grep -q '"status":"error"'; then
echo "Error updating channel: $RESPONSE"
exit 1
fi
echo "Channel '${var.name}' updated successfully"
else
# Channel doesn't exist, create it
echo "Channel '${var.name}' doesn't exist, creating..."
RESPONSE=$(curl -s -X POST ${var.signoz_endpoint}/api/v1/channels \
-H "SIGNOZ-API-KEY: ${var.signoz_api_token}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '${jsonencode(local.slack_config)}')
echo "SigNoz API Create Response: $RESPONSE"
# Check if the response contains the duplicate name error
if echo "$RESPONSE" | grep -q "alertmanager_config_conflict"; then
echo "Channel '${var.name}' already exists, skipping creation"
exit 0
fi
# Check if the response indicates success (no "error" field)
if echo "$RESPONSE" | grep -q '"status":"error"'; then
echo "Error creating channel: $RESPONSE"
exit 1
fi
echo "Channel '${var.name}' created successfully"
fi
EOT
}
provisioner "local-exec" {
when = destroy
command = <<-EOT
# Get the channel ID first
CHANNEL_ID=$(curl -s -X GET ${self.triggers.signoz_endpoint}/api/v1/channels \
-H "SIGNOZ-API-KEY: ${self.triggers.signoz_api_token}" \
-H "Accept: application/json" | \
jq -r '.data[]? | select(.name == "${self.triggers.name}") | .id')
# Delete the channel if it exists
if [ "$CHANNEL_ID" != "null" ] && [ "$CHANNEL_ID" != "" ]; then
echo "Deleting channel '${self.triggers.name}' with ID: $CHANNEL_ID"
curl -s -X DELETE ${self.triggers.signoz_endpoint}/api/v1/channels/$CHANNEL_ID \
-H "SIGNOZ-API-KEY: ${self.triggers.signoz_api_token}" \
-H "Accept: application/json"
echo "Channel '${self.triggers.name}' deleted successfully"
else
echo "Channel '${self.triggers.name}' not found, nothing to delete"
fi
EOT
}
}Ashwini Manoj
08/27/2025, 5:25 AM