Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cloudflare R2 billing alerts to email and discord channel #80

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions deployment/modules/cloudflare/account/alerts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
data "onepassword_vault" "opentofu_vault" {
name = "OpenTofu"
}

data "onepassword_item" "discord_leadership_alerts" {
title = "discord-leadership-alerts-webhook"
vault = data.onepassword_vault.opentofu_vault.name
}

locals {
alerts_email = "[email protected]"
}

resource "cloudflare_notification_policy" "r2_storage_usage_alert" {
account_id = var.cloudflare_account_id
name = "R2 storage usage billing alert"
description = "R2 storage usage exceeded set billing limit"
enabled = true
alert_type = "billing_usage_alert"

filters {
limit = ["8000000000"]
product = ["r2_storage"]
}

email_integration {
id = local.alerts_email
}

webhooks_integration {
id = cloudflare_notification_policy_webhooks.discord_leadership_alerts.id
}
}

resource "cloudflare_notification_policy" "r2_class_a_operations_alert" {
account_id = var.cloudflare_account_id
name = "R2 class A operation usage billing alert"
description = "R2 class A operation usage exceeded set billing limit"
enabled = true
alert_type = "billing_usage_alert"

filters {
limit = ["500000"]
product = ["r2_class_a_operations"]
}

email_integration {
id = local.alerts_email
}

webhooks_integration {
id = cloudflare_notification_policy_webhooks.discord_leadership_alerts.id
}
}

resource "cloudflare_notification_policy" "r2_class_b_operations_alert" {
account_id = var.cloudflare_account_id
name = "R2 class B operation usage billing alert"
description = "R2 class B operation usage exceeded set billing limit"
enabled = true
alert_type = "billing_usage_alert"

filters {
limit = ["5000000"]
product = ["r2_class_b_operations"]
}

email_integration {
id = local.alerts_email
}

webhooks_integration {
id = cloudflare_notification_policy_webhooks.discord_leadership_alerts.id
}
}

resource "cloudflare_notification_policy_webhooks" "discord_leadership_alerts" {
account_id = var.cloudflare_account_id
name = "Webhooks destination"
url = data.onepassword_item.discord_leadership_alerts.credential
secret = ""
}
Loading