Skip to content

Commit 3be1819

Browse files
authored
feat: discord webhooks to o11y vaults for alerting (#1849)
Signed-off-by: Devin Buhl <devin@buhl.casa>
1 parent 42b8fb8 commit 3be1819

4 files changed

Lines changed: 70 additions & 5 deletions

File tree

tf/deployment/modules/scoped/discord/community/channels.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ locals {
5555
"yucca_off_topic",
5656
"yucca_focus_topic",
5757
"yucca_alerts",
58-
"yucca_alerts_testing",
58+
"yucca_alerts_staging",
5959
"yucca_alerts_dev",
6060
]
6161
# Leadership
@@ -333,7 +333,7 @@ module "team_channels_write" {
333333
yucca_off_topic = discord_text_channel.yucca_off_topic.id
334334
yucca_focus_topic = discord_forum_channel.yucca_focus_topic.id
335335
yucca_alerts = discord_text_channel.yucca_alerts.id
336-
yucca_alerts_testing = discord_text_channel.yucca_alerts_testing.id
336+
yucca_alerts_staging = discord_text_channel.yucca_alerts_staging.id
337337
yucca_alerts_dev = discord_text_channel.yucca_alerts_dev.id
338338
yucca_voice = discord_voice_channel.yucca_voice.id
339339
}
@@ -796,9 +796,9 @@ resource "discord_text_channel" "yucca_alerts" {
796796
}
797797
}
798798

799-
resource "discord_text_channel" "yucca_alerts_testing" {
800-
name = "yucca-alerts-testing"
801-
position = index(local.channel_order.yucca, "yucca_alerts_testing")
799+
resource "discord_text_channel" "yucca_alerts_staging" {
800+
name = "yucca-alerts-staging"
801+
position = index(local.channel_order.yucca, "yucca_alerts_staging")
802802
server_id = discord_server.server.id
803803
category = discord_category_channel.yucca.id
804804
sync_perms_with_category = false

tf/deployment/modules/scoped/discord/community/providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ provider "onepassword" {
66
url = var.op_connect_url
77
token = var.op_connect_token
88
}
9+
10+
provider "onepassword" {
11+
alias = "futo"
12+
service_account_token = var.futo_op_service_account_token
13+
}

tf/deployment/modules/scoped/discord/community/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ variable "op_connect_token" {
77

88
variable "discord_token" {}
99

10+
variable "futo_op_service_account_token" {
11+
description = "1Password service-account token for the FUTO account, used to write the webhook URLs into the yucca/o11y vaults"
12+
sensitive = true
13+
}
14+
1015
variable "discord_server_id" {}
1116

1217
variable "env" {}

tf/deployment/modules/scoped/discord/community/webhooks.tf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,61 @@ output "team_alerts_grafana_webhook_url" {
2020
sensitive = true
2121
}
2222

23+
resource "discord_webhook" "yucca_alerts_grafana" {
24+
name = "Grafana"
25+
channel_id = discord_text_channel.yucca_alerts.id
26+
avatar_data_uri = local.image_data_uris["grafana_128_128.webp"]
27+
}
28+
29+
output "yucca_alerts_grafana_webhook_url" {
30+
value = discord_webhook.yucca_alerts_grafana.url
31+
sensitive = true
32+
}
33+
34+
resource "discord_webhook" "yucca_alerts_staging_grafana" {
35+
name = "Grafana Staging"
36+
channel_id = discord_text_channel.yucca_alerts_staging.id
37+
avatar_data_uri = local.image_data_uris["grafana_128_128.webp"]
38+
}
39+
40+
output "yucca_alerts_staging_grafana_webhook_url" {
41+
value = discord_webhook.yucca_alerts_staging_grafana.url
42+
sensitive = true
43+
}
44+
45+
# Publish each cluster's yucca-alerts Grafana webhook URL into its FUTO o11y vault
46+
# (o11y_tf_<env>) so the o11y stack can consume it. The o11y_tf_* vaults live in the
47+
# FUTO 1Password account, which the default (immich Connect) provider cannot reach —
48+
# hence provider = onepassword.futo.
49+
#
50+
# All three yucca-alerts channels live on the community server, which only the prod
51+
# discord apply manages — the dev apply targets the test server and would clobber the
52+
# vault items with test-server URLs on every run (its service account may not have o11y
53+
# vault access either, and data sources execute during every plan). Hence the for_each
54+
# collapses to an empty map outside prod.
55+
locals {
56+
o11y_grafana_discord_webhooks = {
57+
prod = discord_webhook.yucca_alerts_grafana.url
58+
staging = discord_webhook.yucca_alerts_staging_grafana.url
59+
dev = discord_webhook.yucca_alerts_dev_grafana.url
60+
}
61+
}
62+
63+
data "onepassword_vault" "o11y_tf" {
64+
for_each = { for env, url in local.o11y_grafana_discord_webhooks : env => url if var.env == "prod" }
65+
provider = onepassword.futo
66+
name = "o11y_tf_${each.key}"
67+
}
68+
69+
resource "onepassword_item" "o11y_grafana_discord_webhook" {
70+
for_each = { for env, url in local.o11y_grafana_discord_webhooks : env => url if var.env == "prod" }
71+
provider = onepassword.futo
72+
vault = data.onepassword_vault.o11y_tf[each.key].uuid
73+
title = "GRAFANA_DISCORD_WEBHOOK"
74+
category = "password"
75+
password = each.value
76+
}
77+
2378
resource "discord_webhook" "yucca_alerts_dev_grafana" {
2479
name = "Grafana Dev"
2580
channel_id = discord_text_channel.yucca_alerts_dev.id

0 commit comments

Comments
 (0)