From 54672cdff8d46f4cf59503b9f39cc335e5397c86 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Tue, 10 Sep 2024 16:04:49 +0100 Subject: [PATCH 1/7] feat: notifications sa-251 teams and sa-228 enrichmenbt --- examples/budgets/main.tf | 1 - modules/budgets/README.md | 7 +++---- modules/budgets/locals.tf | 2 -- modules/budgets/main.tf | 2 +- modules/budgets/variables.tf | 2 -- modules/team-budgets/README.md | 6 +++--- modules/team-budgets/main.tf | 10 +++++----- modules/team-budgets/variables.tf | 1 - tests/module.tftest.hcl | 1 - 9 files changed, 12 insertions(+), 20 deletions(-) diff --git a/examples/budgets/main.tf b/examples/budgets/main.tf index 1394c1c..c75c84d 100644 --- a/examples/budgets/main.tf +++ b/examples/budgets/main.tf @@ -23,7 +23,6 @@ module "budgets" { addresses = var.notification_emails } slack = { - channel = jsondecode(data.aws_secretsmanager_secret_version.notification.secret_string).channel webhook_url = jsondecode(data.aws_secretsmanager_secret_version.notification.secret_string).webhook_url } } diff --git a/modules/budgets/README.md b/modules/budgets/README.md index 094a8fe..4c044aa 100644 --- a/modules/budgets/README.md +++ b/modules/budgets/README.md @@ -71,7 +71,6 @@ module "budgets" { addresses = var.notification_emails }, slack = { - channel = jsondecode(data.aws_secretsmanager_secret_version.slack.secret_string).channel webhook_url = jsondecode(data.aws_secretsmanager_secret_version.slack.secret_string).webhook_url } } @@ -99,13 +98,13 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | Name | Version | |------|---------| -| [aws](#provider\_aws) | ~> 5.0 | +| [aws](#provider\_aws) | 5.39.1 | ## Modules | Name | Source | Version | |------|--------|---------| -| [notifications](#module\_notifications) | appvia/notifications/aws | 0.1.4 | +| [notifications](#module\_notifications) | appvia/notifications/aws | 1.0.1 | ## Resources @@ -117,9 +116,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({
channel = optional(string, null)
lambda_name = optional(string, "budget-notifications")
secret_name = optional(string, null)
username = optional(string, ":aws: AWS Budgets")
webhook_url = optional(string, null)
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
| 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(list(object({
name = string
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
})
}))
| `[]` | no | | [create\_sns\_topic](#input\_create\_sns\_topic) | A flag to determine if the SNS topic should be created | `bool` | `true` | no | +| [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 | | [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create for budget notifications | `string` | `"budget-notifications"` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | diff --git a/modules/budgets/locals.tf b/modules/budgets/locals.tf index 6caaab6..426a9de 100644 --- a/modules/budgets/locals.tf +++ b/modules/budgets/locals.tf @@ -5,10 +5,8 @@ locals { ## If enabled, this will be the configuration for the slack notification slack_configuration = local.enable_slack ? { - 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 46b2bfd..b1cae58 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -2,7 +2,7 @@ ## Provision the SNS topic for the budgets if required and notifications module "notifications" { source = "appvia/notifications/aws" - version = "0.1.4" + version = "1.0.1" allowed_aws_services = [ "budgets.amazonaws.com", diff --git a/modules/budgets/variables.tf b/modules/budgets/variables.tf index cb83588..b23c583 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -70,10 +70,8 @@ variable "notifications" { addresses = list(string) }), null) slack = optional(object({ - channel = optional(string, null) lambda_name = optional(string, "budget-notifications") secret_name = optional(string, null) - username = optional(string, ":aws: AWS Budgets") webhook_url = optional(string, null) }), null) teams = optional(object({ diff --git a/modules/team-budgets/README.md b/modules/team-budgets/README.md index 081bf09..d8fa81d 100644 --- a/modules/team-budgets/README.md +++ b/modules/team-budgets/README.md @@ -10,13 +10,13 @@ | Name | Version | |------|---------| -| [aws](#provider\_aws) | ~> 5.0 | +| [aws](#provider\_aws) | 5.39.1 | ## Modules | Name | Source | Version | |------|--------|---------| -| [slack\_notfications](#module\_slack\_notfications) | terraform-aws-modules/notify-slack/aws | 6.1.1 | +| [slack\_notfications](#module\_slack\_notfications) | appvia/notifications/aws | 1.0.1 | | [sns](#module\_sns) | terraform-aws-modules/sns/aws | v6.0.1 | ## Resources @@ -30,7 +30,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [budgets](#input\_budgets) | A collection of product or team budgets |
list(object({
amount = number
name = string
notification_type = optional(string, "ACTUAL")
threshold = optional(number, 100)
threshold_type = optional(string, "PERCENTAGE")
time_unit = optional(string, "MONTHLY")

cost_filter = optional(list(object({
name = string
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 = false
include_support = false
include_tax = false
include_upfront = false
use_blended = false
})

notification = object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
channel = string
webhook_url = string
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
}))
| `[]` | no | +| [budgets](#input\_budgets) | A collection of product or team budgets |
list(object({
amount = number
name = string
notification_type = optional(string, "ACTUAL")
threshold = optional(number, 100)
threshold_type = optional(string, "PERCENTAGE")
time_unit = optional(string, "MONTHLY")

cost_filter = optional(list(object({
name = string
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 = false
include_support = false
include_tax = false
include_upfront = false
use_blended = false
})

notification = object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
webhook_url = string
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
}))
| `[]` | no | | [sns\_topic\_arn](#input\_sns\_topic\_arn) | A SNS topic which all notifications are sent to | `string` | `""` | no | | [tags](#input\_tags) | A map of tags to apply to the resources | `map(string)` | `{}` | no | diff --git a/modules/team-budgets/main.tf b/modules/team-budgets/main.tf index 8eed4d0..2c28ac6 100644 --- a/modules/team-budgets/main.tf +++ b/modules/team-budgets/main.tf @@ -105,12 +105,12 @@ resource "aws_budgets_budget" "this" { module "slack_notfications" { for_each = { for budget in var.budgets : budget.name => budget if budget.slack_notification.slack != null } - source = "terraform-aws-modules/notify-slack/aws" - version = "6.1.1" + source = "appvia/notifications/aws" + version = "1.0.1" create_sns_topic = false - slack_channel = each.value.slack_notification.slack_channel - slack_username = ":aws: (#{each.key})" - slack_webhook_url = each.value.slack_notification.slack_webhook_url + slack = { + webhook_url = each.value.slack_notification.slack_webhook_url + } sns_topic_name = module.sns[each.key].topic_name } diff --git a/modules/team-budgets/variables.tf b/modules/team-budgets/variables.tf index dc63ee5..66a2a92 100644 --- a/modules/team-budgets/variables.tf +++ b/modules/team-budgets/variables.tf @@ -52,7 +52,6 @@ variable "budgets" { addresses = list(string) }), null) slack = optional(object({ - channel = string webhook_url = string }), null) teams = optional(object({ diff --git a/tests/module.tftest.hcl b/tests/module.tftest.hcl index d34dc31..aabc1da 100644 --- a/tests/module.tftest.hcl +++ b/tests/module.tftest.hcl @@ -13,7 +13,6 @@ run "basic_account_budget" { addresses = ["platform-engineering@myorg.com"] } slack = { - channel = "dev-alerts" webhook_url = "https://my-dev-alerts.slack.com" } } From 326375d9a726e74896889ac152f82cd13c6a4083 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 08:27:09 +0100 Subject: [PATCH 2/7] chore: bumping provider versions --- .terraform.lock.hcl | 88 ++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 53 deletions(-) diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 0f842e9..bc6a203 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -2,68 +2,48 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "5.52.0" - constraints = ">= 4.8.0, >= 4.9.0, ~> 5.0, >= 5.25.0" + version = "5.66.0" hashes = [ - "h1:ucZxfJtHMHBp4Amnk0K3Bdr7Umbk6he8byey/+u41Lc=", - "zh:22c4599d47cd59e5519c52afc528fa2aec43b4434f369870ee2806daa071449d", - "zh:3c2edc482662a654f84db4cd3f2cdd8f200147207d053d2e95082744b7814e6d", - "zh:57edc36f908c64de37e92a978f3d675604315a725268da936fcd1e270199db47", - "zh:79e7afd5fb161f2eb2b7f8e7fd5cbb7f56a2c64f141b56f511ec69337ad3e96b", - "zh:82c6ae9a7f971b6ee8c476b6eb7f1be9d24ddd183cbf025f52628084ddb3a5ae", - "zh:92faecc0a8f573f57f37d24415862380a40341eb13d66beb738dd0873899a58e", - "zh:963d3c0e1aa22c872cd96f04ceb41c388137b972f714efbde989221bf7f6f723", + "h1:4GInuhb6IqucmxJ0wnkU8rn9kZ59usR5KpEhxbDiFHQ=", + "h1:E3IqCLIq+m45oalIE+cJL8nhh6slVAEkTMQam5QC5Vg=", + "h1:RHs4rOiKrKJqr8UhVW7yqfoMVwaofQ+9ChP41rAzc1A=", + "h1:q04VHjxAyH71dKTfMvrUuap88czr8vpiS8MsN7mDn9A=", + "h1:yGcVdhj9IKbS/b7BSHtgGjCiFnKK+81ImkK/x7UCgEI=", + "zh:071c908eb18627f4becdaf0a9fe95d7a61f69be365080aba2ef5e24f6314392b", + "zh:3dea2a474c6ad4be5b508de4e90064ec485e3fbcebb264cb6c4dec660e3ea8b5", + "zh:56c0b81e3bbf4e9ccb2efb984f8758e2bc563ce179ff3aecc1145df268b046d1", + "zh:5f34b75a9ef69cad8c79115ecc0697427d7f673143b81a28c3cf8d5decfd7f93", + "zh:65632bc2c408775ee44cb32a72e7c48376001a9a7b3adbc2c9b4d088a7d58650", + "zh:6d0550459941dfb39582fadd20bfad8816255a827bfaafb932d51d66030fcdd5", + "zh:7f1811ef179e507fdcc9776eb8dc3d650339f8b84dd084642cf7314c5ca26745", + "zh:8a793d816d7ef57e71758fe95bf830cfca70d121df70778b65cc11065ad004fd", + "zh:8c7cda08adba01b5ae8cc4e5fbf16761451f0fab01327e5f44fc47b7248ba653", + "zh:96d855f1771342771855c0fb2d47ff6a731e8f2fa5d242b18037c751fd63e6c3", "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", - "zh:af6d3bb94aa8a84d740e3731d2379cc5e12aa48d5db0f7489c4639f3814a22d7", - "zh:b9f7aceeaf5daf71394eab9bf0f9f56fdc762cac90e4d62e63aa3fcdf6c1c127", - "zh:c3dcfc2569edae4f36b798c76da7f7633e7bf322505d447d7c370a56c2a30dd2", - "zh:c8abb21c5ceba857f0eaff9e531d781dc655f8cdfae1cf056066daae72546a7f", - "zh:d92004a6a2a770d2542fd9c01b685418ab8d7ab422cf2cdce35dde789bc8593c", - "zh:dc794660b1d6d8f26a917e0ffab1875aa75144736875efaa60f29c72bf02afbf", - "zh:df931c4905e35ae43d558f6cda15f05710a7a24ecbb94533f8822e7572126512", - ] -} - -provider "registry.terraform.io/hashicorp/awscc" { - version = "1.0.0" - constraints = ">= 0.24.0" - hashes = [ - "h1:g0T+4jtoVCh5GvGOOduTbtXiGU8lP5JmCedf0iTwprs=", - "zh:052585beadc046e357f7f3cea1f7822fcfa153acaba1e633ed54b336f918da9c", - "zh:18ad54b123c8dd6f4c04c2e25240ff96cedfd413f9af9be194a31cade89da6d1", - "zh:1fea5f694279e6e5222888149e9717184806b9e452dfd7f0050d09aab83b4f18", - "zh:2109a1243101e07e7eb95b8223c760b619f138af355f4d31c394601b85866580", - "zh:252959eeed8f0daac345cc97ecd3bdc90aa2d9d0c998bf5d237d5a20a4355ee6", - "zh:3cdc4ca9dbc3400b498b617e5d755e066c75dc0cad26dcb30af8760c3a5793c1", - "zh:7f665f299345707b2221588f9f731d42d0024724db8faeb2eed0094fce7dbf5b", - "zh:8696bf7458b2cdfb3a80f1a7d33d1f29a0ccc338b1603dfc66d6d564fb07b019", - "zh:8806a229bf32e6dd59d39b787aa85e3af5f2b00f94fdb7720e852db2323cb504", - "zh:9c1a54bbd7426b1e893056e228ec3c870833eeb2596a90d4da44283167e73fe2", - "zh:aa54e529051ff289c4e1809474bf696134bf7c2e914f3c14ee847727d545ab2c", - "zh:b1c0f7d4b99304472722861cdeaba0523c9e84da94364d4c8e0a5e7568ae9484", - "zh:d63857669d291af8e4a1912a1dbdf9cd2b3911b715f6d3cd1661369dd2d75825", - "zh:f809ab383cca0a5f83072981c64208cbd7fa67e986a86ee02dd2c82333221e32", - "zh:ffc4dc7e3d90d6fcd7798bb1564deb721fccc5af1dde4a2329d9b7d32b2c3fdd", + "zh:b2a62669b72c2471820410b58d764102b11c24e326831ddcfae85c7d20795acf", + "zh:b4a6b251ac24c8f5522581f8d55238d249d0008d36f64475beefc3791f229e1d", + "zh:ca519fa7ee1cac30439c7e2d311a0ecea6a5dae2d175fe8440f30133688b6272", + "zh:fbcd54e7d65806b0038fc8a0fbdc717e1284298ff66e22aac39dcc5a22cc99e5", ] } provider "registry.terraform.io/hashicorp/external" { - version = "2.3.3" + version = "2.3.4" constraints = ">= 1.0.0" hashes = [ - "h1:gShzO1rJtADK9tDZMvMgjciVAzsBh39LNjtThCwX1Hg=", - "zh:03d81462f9578ec91ce8e26f887e34151eda0e100f57e9772dbea86363588239", - "zh:37ec2a20f6a3ec3a0fd95d3f3de26da6cb9534b30488bc45723e118a0911c0d8", - "zh:4eb5b119179539f2749ce9de0e1b9629d025990f062f4f4dddc161562bb89d37", - "zh:5a31bb58414f41bee5e09b939012df5b88654120b0238a89dfd6691ba197619a", - "zh:6221a05e52a6a2d4f520ffe7cbc741f4f6080e0855061b0ed54e8be4a84eb9b7", + "h1:XWkRZOLKMjci9/JAtE8X8fWOt7A4u+9mgXSUjc4Wuyo=", + "zh:037fd82cd86227359bc010672cd174235e2d337601d4686f526d0f53c87447cb", + "zh:0ea1db63d6173d01f2fa8eb8989f0809a55135a0d8d424b08ba5dabad73095fa", + "zh:17a4d0a306566f2e45778fbac48744b6fd9c958aaa359e79f144c6358cb93af0", + "zh:298e5408ab17fd2e90d2cd6d406c6d02344fe610de5b7dae943a58b958e76691", + "zh:38ecfd29ee0785fd93164812dcbe0664ebbe5417473f3b2658087ca5a0286ecb", + "zh:59f6a6f31acf66f4ea3667a555a70eba5d406c6e6d93c2c641b81d63261eeace", "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:8bb068496b4679bef625e4710d9f3432e301c3a56602271f04e60eadf7f8a94c", - "zh:94742aa5378bab626ce34f79bcef6a373e4f86ea7a8b762e9f71270a899e0d00", - "zh:a485831b5a525cd8f40e8982fa37da40ff70b1ae092c8b755fcde123f0b1238d", - "zh:a647ff16d071eabcabd87ea8183eb90a775a0294ddd735d742075d62fff09193", - "zh:b74710c5954aaa3faf262c18d36a8c2407862d9f842c63e7fa92fa4de3d29df6", - "zh:fa73d83edc92af2e551857594c2232ba6a9e3603ad34b0a5940865202c08d8d7", + "zh:ad0279dfd09d713db0c18469f585e58d04748ca72d9ada83883492e0dd13bd58", + "zh:c69f66fd21f5e2c8ecf7ca68d9091c40f19ad913aef21e3ce23836e91b8cbb5f", + "zh:d4a56f8c48aa86fc8e0c233d56850f5783f322d6336f3bf1916e293246b6b5d4", + "zh:f2b394ebd4af33f343835517e80fc876f79361f4688220833bc3c77655dd2202", + "zh:f31982f29f12834e5d21e010856eddd19d59cd8f449adf470655bfd19354377e", ] } @@ -72,6 +52,7 @@ provider "registry.terraform.io/hashicorp/local" { constraints = ">= 1.0.0" hashes = [ "h1:/GAVA/xheGQcbOZEq0qxANOg+KVLCA7Wv8qluxhTjhU=", + "h1:8oTPe2VUL6E2d3OcrvqyjI4Nn/Y/UEQN26WLk5O/B0g=", "zh:0af29ce2b7b5712319bf6424cb58d13b852bf9a777011a545fac99c7fdcdf561", "zh:126063ea0d79dad1f68fa4e4d556793c0108ce278034f101d1dbbb2463924561", "zh:196bfb49086f22fd4db46033e01655b0e5e036a5582d250412cc690fa7995de5", @@ -92,6 +73,7 @@ provider "registry.terraform.io/hashicorp/null" { constraints = ">= 2.0.0" hashes = [ "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", + "h1:zT1ZbegaAYHwQa+QwIFugArWikRJI9dqohj8xb0GY88=", "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", From 1f2ae3acfd1ef928f03dc3e802878caa2201ba03 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 08:27:24 +0100 Subject: [PATCH 3/7] chore: terraform validate --- modules/team-budgets/main.tf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/team-budgets/main.tf b/modules/team-budgets/main.tf index 2c28ac6..6593044 100644 --- a/modules/team-budgets/main.tf +++ b/modules/team-budgets/main.tf @@ -108,9 +108,11 @@ module "slack_notfications" { source = "appvia/notifications/aws" version = "1.0.1" - create_sns_topic = false + create_sns_topic = false slack = { webhook_url = each.value.slack_notification.slack_webhook_url + lambda_name = format("team-budgets-notifications-%s", md5(each.value.name)) } - sns_topic_name = module.sns[each.key].topic_name + sns_topic_name = module.sns[each.key].topic_name + tags = var.tags } From 710d7244f1493b8cec839b3273c3f341452c44dd Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 08:41:11 +0100 Subject: [PATCH 4/7] feat: new notifications module requires explicit enabling of slack --- modules/budgets/main.tf | 1 + modules/budgets/variables.tf | 6 ++++++ modules/team-budgets/main.tf | 1 + modules/team-budgets/variables.tf | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/modules/budgets/main.tf b/modules/budgets/main.tf index b1cae58..5a65ad3 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -10,6 +10,7 @@ module "notifications" { ] create_sns_topic = var.create_sns_topic sns_topic_name = var.sns_topic_name + enable_slack = var.enable_slack slack = local.slack_configuration tags = var.tags } diff --git a/modules/budgets/variables.tf b/modules/budgets/variables.tf index b23c583..c33ef68 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -85,3 +85,9 @@ variable "tags" { type = map(string) default = {} } + +variable "enable_slack" { + description = "Enable/disable the posting of notifications to slack" + type = bool + default = true +} diff --git a/modules/team-budgets/main.tf b/modules/team-budgets/main.tf index 6593044..356ceb8 100644 --- a/modules/team-budgets/main.tf +++ b/modules/team-budgets/main.tf @@ -109,6 +109,7 @@ module "slack_notfications" { version = "1.0.1" create_sns_topic = false + enable_slack = var.enable_slack slack = { webhook_url = each.value.slack_notification.slack_webhook_url lambda_name = format("team-budgets-notifications-%s", md5(each.value.name)) diff --git a/modules/team-budgets/variables.tf b/modules/team-budgets/variables.tf index 66a2a92..4fb2bd6 100644 --- a/modules/team-budgets/variables.tf +++ b/modules/team-budgets/variables.tf @@ -67,3 +67,9 @@ variable "tags" { type = map(string) default = {} } + +variable "enable_slack" { + description = "Enable/disable the posting of notifications to slack" + type = bool + default = true +} From 461a47e6e378853059c250db5ecf4ef5d12332b4 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:13:09 +0100 Subject: [PATCH 5/7] feat: adding account ids to names mapping --- modules/budgets/README.md | 2 ++ modules/budgets/main.tf | 11 ++++++----- modules/budgets/variables.tf | 5 +++++ modules/team-budgets/README.md | 2 ++ modules/team-budgets/main.tf | 5 +++-- modules/team-budgets/variables.tf | 5 +++++ 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/budgets/README.md b/modules/budgets/README.md index 4c044aa..93203be 100644 --- a/modules/budgets/README.md +++ b/modules/budgets/README.md @@ -116,8 +116,10 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `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(list(object({
name = string
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
})
}))
| `[]` | no | | [create\_sns\_topic](#input\_create\_sns\_topic) | A flag to determine if the SNS topic should be created | `bool` | `true` | no | +| [enable\_slack](#input\_enable\_slack) | Enable/disable the posting of notifications to slack | `bool` | `true` | no | | [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 | | [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create for budget notifications | `string` | `"budget-notifications"` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | diff --git a/modules/budgets/main.tf b/modules/budgets/main.tf index 5a65ad3..36c30ce 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -8,11 +8,12 @@ module "notifications" { "budgets.amazonaws.com", "lambda.amazonaws.com", ] - create_sns_topic = var.create_sns_topic - sns_topic_name = var.sns_topic_name - enable_slack = var.enable_slack - slack = local.slack_configuration - tags = var.tags + create_sns_topic = var.create_sns_topic + sns_topic_name = var.sns_topic_name + enable_slack = var.enable_slack + slack = local.slack_configuration + tags = var.tags + accounts_id_to_name = var.accounts_id_to_name } ## Iterate over the budgets and provision them diff --git a/modules/budgets/variables.tf b/modules/budgets/variables.tf index c33ef68..ee47dea 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -91,3 +91,8 @@ variable "enable_slack" { type = bool default = true } + +variable "accounts_id_to_name" { + description = "A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name" + type = map(string) +} diff --git a/modules/team-budgets/README.md b/modules/team-budgets/README.md index d8fa81d..9bcd2ef 100644 --- a/modules/team-budgets/README.md +++ b/modules/team-budgets/README.md @@ -30,7 +30,9 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `map(string)` | n/a | yes | | [budgets](#input\_budgets) | A collection of product or team budgets |
list(object({
amount = number
name = string
notification_type = optional(string, "ACTUAL")
threshold = optional(number, 100)
threshold_type = optional(string, "PERCENTAGE")
time_unit = optional(string, "MONTHLY")

cost_filter = optional(list(object({
name = string
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 = false
include_support = false
include_tax = false
include_upfront = false
use_blended = false
})

notification = object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
webhook_url = string
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
}))
| `[]` | no | +| [enable\_slack](#input\_enable\_slack) | Enable/disable the posting of notifications to slack | `bool` | `true` | no | | [sns\_topic\_arn](#input\_sns\_topic\_arn) | A SNS topic which all notifications are sent to | `string` | `""` | no | | [tags](#input\_tags) | A map of tags to apply to the resources | `map(string)` | `{}` | no | diff --git a/modules/team-budgets/main.tf b/modules/team-budgets/main.tf index 356ceb8..a331277 100644 --- a/modules/team-budgets/main.tf +++ b/modules/team-budgets/main.tf @@ -114,6 +114,7 @@ module "slack_notfications" { webhook_url = each.value.slack_notification.slack_webhook_url lambda_name = format("team-budgets-notifications-%s", md5(each.value.name)) } - sns_topic_name = module.sns[each.key].topic_name - tags = var.tags + sns_topic_name = module.sns[each.key].topic_name + tags = var.tags + accounts_id_to_name = var.accounts_id_to_name } diff --git a/modules/team-budgets/variables.tf b/modules/team-budgets/variables.tf index 4fb2bd6..fa0972a 100644 --- a/modules/team-budgets/variables.tf +++ b/modules/team-budgets/variables.tf @@ -73,3 +73,8 @@ variable "enable_slack" { type = bool default = true } + +variable "accounts_id_to_name" { + description = "A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name" + type = map(string) +} From 95af81867d935d002779a9d336beaef5c79f7d15 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:29:46 +0100 Subject: [PATCH 6/7] chore: budgets already has a local.enable_slack --- modules/budgets/README.md | 1 - modules/budgets/main.tf | 2 +- modules/budgets/variables.tf | 6 ------ modules/team-budgets/README.md | 1 - modules/team-budgets/main.tf | 2 +- modules/team-budgets/variables.tf | 6 ------ 6 files changed, 2 insertions(+), 16 deletions(-) diff --git a/modules/budgets/README.md b/modules/budgets/README.md index 93203be..e7040b0 100644 --- a/modules/budgets/README.md +++ b/modules/budgets/README.md @@ -119,7 +119,6 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `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(list(object({
name = string
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
})
}))
| `[]` | no | | [create\_sns\_topic](#input\_create\_sns\_topic) | A flag to determine if the SNS topic should be created | `bool` | `true` | no | -| [enable\_slack](#input\_enable\_slack) | Enable/disable the posting of notifications to slack | `bool` | `true` | no | | [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 | | [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create for budget notifications | `string` | `"budget-notifications"` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | diff --git a/modules/budgets/main.tf b/modules/budgets/main.tf index 36c30ce..f33e386 100644 --- a/modules/budgets/main.tf +++ b/modules/budgets/main.tf @@ -10,7 +10,7 @@ module "notifications" { ] create_sns_topic = var.create_sns_topic sns_topic_name = var.sns_topic_name - enable_slack = var.enable_slack + enable_slack = local.enable_slack slack = local.slack_configuration tags = var.tags accounts_id_to_name = var.accounts_id_to_name diff --git a/modules/budgets/variables.tf b/modules/budgets/variables.tf index ee47dea..854b951 100644 --- a/modules/budgets/variables.tf +++ b/modules/budgets/variables.tf @@ -86,12 +86,6 @@ variable "tags" { default = {} } -variable "enable_slack" { - description = "Enable/disable the posting of notifications to slack" - type = bool - default = true -} - variable "accounts_id_to_name" { description = "A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name" type = map(string) diff --git a/modules/team-budgets/README.md b/modules/team-budgets/README.md index 9bcd2ef..915168b 100644 --- a/modules/team-budgets/README.md +++ b/modules/team-budgets/README.md @@ -32,7 +32,6 @@ |------|-------------|------|---------|:--------:| | [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `map(string)` | n/a | yes | | [budgets](#input\_budgets) | A collection of product or team budgets |
list(object({
amount = number
name = string
notification_type = optional(string, "ACTUAL")
threshold = optional(number, 100)
threshold_type = optional(string, "PERCENTAGE")
time_unit = optional(string, "MONTHLY")

cost_filter = optional(list(object({
name = string
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 = false
include_support = false
include_tax = false
include_upfront = false
use_blended = false
})

notification = object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
webhook_url = string
}), null)
teams = optional(object({
webhook_url = string
}), null)
})
}))
| `[]` | no | -| [enable\_slack](#input\_enable\_slack) | Enable/disable the posting of notifications to slack | `bool` | `true` | no | | [sns\_topic\_arn](#input\_sns\_topic\_arn) | A SNS topic which all notifications are sent to | `string` | `""` | no | | [tags](#input\_tags) | A map of tags to apply to the resources | `map(string)` | `{}` | no | diff --git a/modules/team-budgets/main.tf b/modules/team-budgets/main.tf index a331277..463dfba 100644 --- a/modules/team-budgets/main.tf +++ b/modules/team-budgets/main.tf @@ -109,7 +109,7 @@ module "slack_notfications" { version = "1.0.1" create_sns_topic = false - enable_slack = var.enable_slack + enable_slack = true slack = { webhook_url = each.value.slack_notification.slack_webhook_url lambda_name = format("team-budgets-notifications-%s", md5(each.value.name)) diff --git a/modules/team-budgets/variables.tf b/modules/team-budgets/variables.tf index fa0972a..e0af137 100644 --- a/modules/team-budgets/variables.tf +++ b/modules/team-budgets/variables.tf @@ -68,12 +68,6 @@ variable "tags" { default = {} } -variable "enable_slack" { - description = "Enable/disable the posting of notifications to slack" - type = bool - default = true -} - variable "accounts_id_to_name" { description = "A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name" type = map(string) From 0bb532ff93ffabbe04e531b83e4830e632914092 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:52:41 +0100 Subject: [PATCH 7/7] chore: updating example --- examples/budgets/main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/budgets/main.tf b/examples/budgets/main.tf index c75c84d..7f28825 100644 --- a/examples/budgets/main.tf +++ b/examples/budgets/main.tf @@ -27,4 +27,7 @@ module "budgets" { } } tags = var.tags + accounts_id_to_name = { + "1234567890" = "mgmt" + } }