Skip to content

Commit

Permalink
Notifications Variable Name (#4)
Browse files Browse the repository at this point in the history
* fix: adjusting the variable name for consistency purposes

* chore: adding the ability to pass the secret name
  • Loading branch information
gambol99 authored Apr 27, 2024
1 parent d5ea69c commit af8fefb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/budgets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module "budgets" {
source = "../../modules/budgets"

budgets = var.budgets
notification = {
notifications = {
email = {
addresses = var.notification_emails
}
Expand Down
11 changes: 6 additions & 5 deletions modules/budgets/locals.tf
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion modules/budgets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions modules/budgets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af8fefb

Please sign in to comment.