Skip to content

Commit 2f2f9f2

Browse files
akshat-goyal-harnessHarness
authored andcommitted
feat: [PL-65024]: Adding examples for platform service entites (#1289)
* b31725 Merge remote-tracking branch 'origin/PL-65024' into PL-65024 * 05e59d #platform-core-framework-exmaples * efc434 #platform-core-framework-exmaples
1 parent bfbb393 commit 2f2f9f2

File tree

9 files changed

+141
-0
lines changed

9 files changed

+141
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example of fetching a notification channel by identifier
2+
data "harness_central_notification_channel" "example" {
3+
identifier = "email_channel"
4+
org_id = "my_org"
5+
project_id = "my_project"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example of fetching a notification rule by identifier
2+
data "harness_central_notification_rule" "example" {
3+
identifier = "high_severity_rule"
4+
org_id = "my_org"
5+
project_id = "my_project"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example of fetching the default notification template set
2+
data "harness_default_notification_template_set" "example" {
3+
identifier = "default"
4+
org_id = "my_org"
5+
project_id = "my_project"
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Import account level Central Notification Channel
2+
terraform import harness_central_notification_channel.example <central_notification_channel_id>
3+
4+
# Import org level Central Notification Channel
5+
terraform import harness_central_notification_channel.example <ord_id>/<central_notification_channel_id>
6+
7+
# Import project level Central Notification Channel
8+
terraform import harness_central_notification_channel.example <org_id>/<project_id>/<central_notification_channel_id>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "harness_central_notification_channel" "email_channel" {
2+
name = "Email Notification Channel"
3+
identifier = "email_notification_channel"
4+
description = "Email channel for critical alerts"
5+
org_id = "my_org"
6+
project_id = "my_project"
7+
8+
# Email channel configuration
9+
email_config {
10+
11+
subject = "[ALERT] Harness Notification"
12+
send_to_all_admins = false
13+
}
14+
15+
# Notification preferences
16+
notification_method = "EMAIL"
17+
enabled = true
18+
19+
tags = {
20+
environment = "production"
21+
team = "devops"
22+
}
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Import account level Central Notification Rule
2+
terraform import harness_central_notification_rule.example <harness_central_notification_rule_id>
3+
4+
# Import org level Central Notification Rule
5+
terraform import harness_central_notification_rule.example <ord_id>/<harness_central_notification_rule_id>
6+
7+
# Import project level Central Notification Rule
8+
terraform import harness_central_notification_rule.example <org_id>/<project_id>/<harness_central_notification_rule_id>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "harness_central_notification_rule" "high_severity_rule" {
2+
name = "High Severity Alerts Rule"
3+
identifier = "high_severity_alerts_rule"
4+
description = "Rule for high severity alerts notification"
5+
org_id = "my_org"
6+
project_id = "my_project"
7+
8+
# Rule conditions
9+
conditions {
10+
type = "PIPELINE"
11+
event = "PIPELINE_START"
12+
13+
# Filter for high severity events
14+
filter {
15+
type = "severity"
16+
value = "HIGH"
17+
}
18+
}
19+
20+
# Notification channels to notify
21+
notification_channels = [
22+
"email_notification_channel"
23+
]
24+
25+
# Execution settings
26+
enabled = true
27+
28+
tags = {
29+
environment = "production"
30+
team = "devops"
31+
}
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Import account level Default Notification Template Set
2+
terraform import harness_default_notification_template_set.example <harness_default_notification_template_set>
3+
4+
# Import org level Default Notification Template Set
5+
terraform import harness_default_notification_template_set.example <ord_id>/<harness_default_notification_template_set>
6+
7+
# Import project level Default Notification Template Set
8+
terraform import harness_default_notification_template_set.example <org_id>/<project_id>/<harness_default_notification_template_set>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
resource "harness_default_notification_template_set" "default_set" {
2+
name = "Default Template Set"
3+
identifier = "default_template_set"
4+
description = "Default notification templates for all events"
5+
org_id = "my_org"
6+
project_id = "my_project"
7+
8+
# Email template configuration
9+
email_templates {
10+
type = "PIPELINE_START"
11+
subject = "[${var.env}] Pipeline Started: ${pipeline.name}"
12+
body = <<-EOT
13+
<!DOCTYPE html>
14+
<html>
15+
<body>
16+
<h2>Pipeline Started</h2>
17+
<p><strong>Pipeline:</strong> ${pipeline.name}</p>
18+
<p><strong>Triggered by:</strong> ${pipeline.triggered_by}</p>
19+
<p><strong>Start Time:</strong> ${pipeline.start_time}</p>
20+
<p>View details: <a href="${pipeline.execution_url}">${pipeline.execution_url}</a></p>
21+
</body>
22+
</html>
23+
EOT
24+
}
25+
26+
# Slack template configuration
27+
slack_templates {
28+
type = "PIPELINE_SUCCESS"
29+
message = "✅ *${pipeline.name}* succeeded!\n*Environment*: ${env.name}\n*Duration*: ${pipeline.duration}\n<${pipeline.execution_url}|View Details>"
30+
}
31+
32+
# Default settings
33+
is_default = true
34+
35+
tags = {
36+
environment = "production"
37+
team = "devops"
38+
}
39+
}
40+
41+
# Output the created template set details
42+
output "created_template_set" {
43+
value = harness_default_notification_template_set.default_set
44+
}

0 commit comments

Comments
 (0)