From e729a8a07bab6e16954b057cd03c840af37c84de Mon Sep 17 00:00:00 2001 From: Rohith Jayawardene Date: Tue, 28 Jan 2025 06:33:17 +0000 Subject: [PATCH] feat: dropping the notifications from the module and using an optional sns topic --- modules/budgets/README.md | 4 +--- modules/budgets/locals.tf | 12 ------------ modules/budgets/main.tf | 18 +----------------- modules/budgets/variables.tf | 21 ++------------------- 4 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 modules/budgets/locals.tf diff --git a/modules/budgets/README.md b/modules/budgets/README.md index 1f44986..e087954 100644 --- a/modules/budgets/README.md +++ b/modules/budgets/README.md @@ -97,11 +97,9 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [notifications](#input\_notifications) | The configuration as to how the budget notifications should be sent |
object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
lambda_name = optional(string, "budget-notifications")
secret_name = optional(string, null)
webhook_url = optional(string, null)
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
| n/a | yes | +| [notifications](#input\_notifications) | The configuration as to how the budget notifications should be sent |
object({
email = optional(object({
addresses = list(string)
}), null)
sns = optional(object({
topic_arn = string
}), null)
})
| n/a | yes | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes | | [budgets](#input\_budgets) | A collection of budgets to provision |
list(object({
name = string
budget_type = optional(string, "COST")
limit_amount = optional(string, "100.0")
limit_unit = optional(string, "PERCENTAGE")
time_unit = optional(string, "MONTHLY")

notification = optional(object({
comparison_operator = string
threshold = number
threshold_type = string
notification_type = string
}), null)

auto_adjust_data = optional(list(object({
auto_adjust_type = string
})), [])

cost_filter = optional(map(object({
values = list(string)
})), {})

cost_types = optional(object({
include_credit = optional(bool, false)
include_discount = optional(bool, false)
include_other_subscription = optional(bool, false)
include_recurring = optional(bool, false)
include_refund = optional(bool, false)
include_subscription = optional(bool, false)
include_support = optional(bool, false)
include_tax = optional(bool, false)
include_upfront = optional(bool, false)
use_blended = optional(bool, false)
}), {
include_credit = false
include_discount = false
include_other_subscription = false
include_recurring = false
include_refund = false
include_subscription = true
include_support = false
include_tax = false
include_upfront = false
use_blended = false
})

tags = optional(map(string), {})
}))
| `[]` | no | -| [create\_sns\_topic](#input\_create\_sns\_topic) | A flag to determine if the SNS topic should be created | `bool` | `true` | no | -| [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create for budget notifications | `string` | `"budget-notifications"` | no | ## Outputs diff --git a/modules/budgets/locals.tf b/modules/budgets/locals.tf deleted file mode 100644 index 426a9de..0000000 --- a/modules/budgets/locals.tf +++ /dev/null @@ -1,12 +0,0 @@ - -locals { - ## Indicates if the slack notification is enabled - enable_slack = var.notifications.slack != null - - ## If enabled, this will be the configuration for the slack notification - slack_configuration = local.enable_slack ? { - lambda_name = var.notifications.slack.lambda_name - secret_name = var.notifications.slack.secret_name - webhook_url = var.notifications.slack.webhook_url - } : null -} diff --git a/modules/budgets/main.tf b/modules/budgets/main.tf index fde8a11..eb62eff 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -1,20 +1,4 @@ -## Provision the SNS topic for the budgets if required and notifications -module "notifications" { - source = "appvia/notifications/aws" - version = "2.0.1" - - allowed_aws_services = [ - "budgets.amazonaws.com", - "lambda.amazonaws.com", - ] - create_sns_topic = var.create_sns_topic - sns_topic_name = var.sns_topic_name - enable_slack = local.enable_slack - slack = local.slack_configuration - tags = var.tags -} - ## Iterate over the budgets and provision them resource "aws_budgets_budget" "this" { for_each = { for x in var.budgets : x.name => x } @@ -68,7 +52,7 @@ resource "aws_budgets_budget" "this" { comparison_operator = each.value.notification.comparison_operator notification_type = each.value.notification.notification_type subscriber_email_addresses = var.notifications.email != null ? var.notifications.email.addresses : null - subscriber_sns_topic_arns = [module.notifications.sns_topic_arn] + subscriber_sns_topic_arns = var.notifications.sns != null ? [var.notifications.sns.topic_arn] : null 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 6e25195..b47a115 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -1,16 +1,4 @@ -variable "sns_topic_name" { - description = "The name of the SNS topic to create for budget notifications" - type = string - default = "budget-notifications" -} - -variable "create_sns_topic" { - description = "A flag to determine if the SNS topic should be created" - type = bool - default = true -} - variable "budgets" { description = "A collection of budgets to provision" type = list(object({ @@ -70,13 +58,8 @@ variable "notifications" { email = optional(object({ addresses = list(string) }), null) - slack = optional(object({ - lambda_name = optional(string, "budget-notifications") - secret_name = optional(string, null) - webhook_url = optional(string, null) - }), null) - teams = optional(object({ - webhook_url = string + sns = optional(object({ + topic_arn = string }), null) }) }