Skip to content

Commit

Permalink
feat: dropping the notifications from the module and using an optiona…
Browse files Browse the repository at this point in the history
…l sns topic
  • Loading branch information
gambol99 committed Jan 28, 2025
1 parent 092e0aa commit e729a8a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 51 deletions.
4 changes: 1 addition & 3 deletions modules/budgets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ The `terraform-docs` utility is used to generate this README. Follow the below s

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_notifications"></a> [notifications](#input\_notifications) | The configuration as to how the budget notifications should be sent | <pre>object({<br/> email = optional(object({<br/> addresses = list(string)<br/> }), null)<br/> slack = optional(object({<br/> lambda_name = optional(string, "budget-notifications")<br/> secret_name = optional(string, null)<br/> webhook_url = optional(string, null)<br/> }), null)<br/> teams = optional(object({<br/> webhook_url = string<br/> }), null)<br/> })</pre> | n/a | yes |
| <a name="input_notifications"></a> [notifications](#input\_notifications) | The configuration as to how the budget notifications should be sent | <pre>object({<br/> email = optional(object({<br/> addresses = list(string)<br/> }), null)<br/> sns = optional(object({<br/> topic_arn = string<br/> }), null)<br/> })</pre> | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes |
| <a name="input_budgets"></a> [budgets](#input\_budgets) | A collection of budgets to provision | <pre>list(object({<br/> name = string<br/> budget_type = optional(string, "COST")<br/> limit_amount = optional(string, "100.0")<br/> limit_unit = optional(string, "PERCENTAGE")<br/> time_unit = optional(string, "MONTHLY")<br/><br/> notification = optional(object({<br/> comparison_operator = string<br/> threshold = number<br/> threshold_type = string<br/> notification_type = string<br/> }), null)<br/><br/> auto_adjust_data = optional(list(object({<br/> auto_adjust_type = string<br/> })), [])<br/><br/> cost_filter = optional(map(object({<br/> values = list(string)<br/> })), {})<br/><br/> cost_types = optional(object({<br/> include_credit = optional(bool, false)<br/> include_discount = optional(bool, false)<br/> include_other_subscription = optional(bool, false)<br/> include_recurring = optional(bool, false)<br/> include_refund = optional(bool, false)<br/> include_subscription = optional(bool, false)<br/> include_support = optional(bool, false)<br/> include_tax = optional(bool, false)<br/> include_upfront = optional(bool, false)<br/> use_blended = optional(bool, false)<br/> }), {<br/> include_credit = false<br/> include_discount = false<br/> include_other_subscription = false<br/> include_recurring = false<br/> include_refund = false<br/> include_subscription = true<br/> include_support = false<br/> include_tax = false<br/> include_upfront = false<br/> use_blended = false<br/> })<br/><br/> tags = optional(map(string), {})<br/> }))</pre> | `[]` | no |
| <a name="input_create_sns_topic"></a> [create\_sns\_topic](#input\_create\_sns\_topic) | A flag to determine if the SNS topic should be created | `bool` | `true` | no |
| <a name="input_sns_topic_name"></a> [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create for budget notifications | `string` | `"budget-notifications"` | no |

## Outputs

Expand Down
12 changes: 0 additions & 12 deletions modules/budgets/locals.tf

This file was deleted.

18 changes: 1 addition & 17 deletions modules/budgets/main.tf
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 2 additions & 19 deletions modules/budgets/variables.tf
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit e729a8a

Please sign in to comment.