From af8fefb1bbe0cd507bf99e4a16f612d561f8ead1 Mon Sep 17 00:00:00 2001 From: Rohith Jayawardene Date: Sat, 27 Apr 2024 08:30:12 +0100 Subject: [PATCH] Notifications Variable Name (#4) * fix: adjusting the variable name for consistency purposes * chore: adding the ability to pass the secret name --- examples/budgets/main.tf | 2 +- modules/budgets/locals.tf | 11 ++++++----- modules/budgets/main.tf | 2 +- modules/budgets/variables.tf | 8 +++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/budgets/main.tf b/examples/budgets/main.tf index 88ab1c8..1394c1c 100644 --- a/examples/budgets/main.tf +++ b/examples/budgets/main.tf @@ -18,7 +18,7 @@ module "budgets" { source = "../../modules/budgets" budgets = var.budgets - notification = { + notifications = { email = { addresses = var.notification_emails } diff --git a/modules/budgets/locals.tf b/modules/budgets/locals.tf index 13e517c..6caaab6 100644 --- a/modules/budgets/locals.tf +++ b/modules/budgets/locals.tf @@ -1,13 +1,14 @@ locals { ## Indicates if the slack notification is enabled - enable_slack = var.notification.slack != null + enable_slack = var.notifications.slack != null ## If enabled, this will be the configuration for the slack notification slack_configuration = local.enable_slack ? { - channel = var.notification.slack.channel - lambda_name = var.notification.slack.lambda_name - slack_username = ":aws: Budgets" - webhook_url = var.notification.slack.webhook_url + channel = var.notifications.slack.channel + lambda_name = var.notifications.slack.lambda_name + secret_name = var.notifications.slack.secret_name + username = var.notifications.slack.username + webhook_url = var.notifications.slack.webhook_url } : null } diff --git a/modules/budgets/main.tf b/modules/budgets/main.tf index 28e4456..db9f6d7 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -65,7 +65,7 @@ resource "aws_budgets_budget" "this" { notification { comparison_operator = each.value.notification.comparison_operator notification_type = each.value.notification.notification_type - subscriber_email_addresses = var.notification.email != null ? var.notification.email.addresses : null + subscriber_email_addresses = var.notifications.email != null ? var.notifications.email.addresses : null subscriber_sns_topic_arns = [module.notifications.sns_topic_arn] threshold = each.value.notification.threshold threshold_type = each.value.notification.threshold_type diff --git a/modules/budgets/variables.tf b/modules/budgets/variables.tf index 3a04b89..cb83588 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -63,16 +63,18 @@ variable "budgets" { default = [] } -variable "notification" { +variable "notifications" { description = "The configuration as to how the budget notifications should be sent" type = object({ email = optional(object({ addresses = list(string) }), null) slack = optional(object({ - channel = string + channel = optional(string, null) lambda_name = optional(string, "budget-notifications") - webhook_url = string + secret_name = optional(string, null) + username = optional(string, ":aws: AWS Budgets") + webhook_url = optional(string, null) }), null) teams = optional(object({ webhook_url = string