From 6d95c03191b5159e1d860fd4177e89a693079b71 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:38:09 +0100 Subject: [PATCH 1/6] feat: bumping to use new notifications module --- README.md | 5 +++-- locals.tf | 2 -- main.tf | 6 +++++- variables.tf | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bffa58a..8cd15fc 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | Name | Source | Version | |------|--------|---------| -| [notifications](#module\_notifications) | appvia/notifications/aws | 0.1.7 | +| [notifications](#module\_notifications) | appvia/notifications/aws | 1.0.1 | ## Resources @@ -68,8 +68,9 @@ 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 | | [monitors](#input\_monitors) | A collection of cost anomaly monitors to create |
list(object({
name = string
# The name of the monitor
monitor_type = optional(string, "DIMENSIONAL")
# The type of monitor to create
monitor_dimension = optional(string, "DIMENSIONAL")
# The dimension to monitor
monitor_specification = optional(string, null)
# The specification to monitor
notify = optional(object({
frequency = string
# The frequency of notifications
threshold_expression = optional(any, null)
# The threshold expression to use for notifications
}), {
frequency = "DAILY"
})
}))
| n/a | yes | -| [notifications](#input\_notifications) | The configuration of the notification |
object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
channel = optional(string, null)
# The channel name for notifications, required if secret_name is not provided
secret_name = optional(string, null)
# An optional secret name in the AWS Secrets Manager, containing this information
lambda_name = optional(string, "cost-anomaly-notification")
# The name of the Lambda function to use for notifications
username = optional(string, "AWS Cost Anomaly Detection")
# The username to use for notifications
webhook_url = optional(string, null)
# The URL of the Slack webhook to use for notifications, required if secret_name is not provided
}), null)
})
| n/a | yes | +| [notifications](#input\_notifications) | The configuration of the notification |
object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
secret_name = optional(string, null)
# An optional secret name in the AWS Secrets Manager, containing this information
lambda_name = optional(string, "cost-anomaly-notification")
# The name of the Lambda function to use for notifications
webhook_url = optional(string, null)
# The URL of the Slack webhook to use for notifications, required if secret_name is not provided
}), null)
})
| n/a | yes | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes | | [enable\_notification\_creation](#input\_enable\_notification\_creation) | Indicates whether to create a notification lambda stack, default is true, but useful to toggle if using existing resources | `bool` | `true` | no | | [enable\_sns\_topic\_creation](#input\_enable\_sns\_topic\_creation) | Indicates whether to create an SNS topic within this module | `bool` | `true` | no | diff --git a/locals.tf b/locals.tf index bd48ee8..62eb47b 100644 --- a/locals.tf +++ b/locals.tf @@ -18,10 +18,8 @@ locals { ## The configuration for slack notifications if enabled slack = 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/main.tf b/main.tf index 2369359..e862fab 100644 --- a/main.tf +++ b/main.tf @@ -3,14 +3,18 @@ module "notifications" { count = var.enable_notification_creation ? 1 : 0 source = "appvia/notifications/aws" - version = "0.1.7" + version = "1.0.1" allowed_aws_services = ["budgets.amazonaws.com", "costalerts.amazonaws.com", "lambda.amazonaws.com"] create_sns_topic = local.enable_sns_topic_creation email = local.email + enable_slack = local.enable_slack slack = local.slack sns_topic_name = var.sns_topic_name tags = var.tags + accounts_id_to_name = { + "536471746696" = "mgmt" + } } ## Provision the cost anomaly detection for services diff --git a/variables.tf b/variables.tf index b41a12f..f11df3e 100644 --- a/variables.tf +++ b/variables.tf @@ -40,14 +40,10 @@ variable "notifications" { addresses = list(string) }), null) slack = optional(object({ - channel = optional(string, null) - # The channel name for notifications, required if secret_name is not provided secret_name = optional(string, null) # An optional secret name in the AWS Secrets Manager, containing this information lambda_name = optional(string, "cost-anomaly-notification") # The name of the Lambda function to use for notifications - username = optional(string, "AWS Cost Anomaly Detection") - # The username to use for notifications webhook_url = optional(string, null) # The URL of the Slack webhook to use for notifications, required if secret_name is not provided }), null) @@ -70,3 +66,8 @@ variable "tags" { description = "A map of tags to add to all resources" type = map(string) } + +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 b3e65dd983a952c23d5b3dac71f00cb12a6cf2ad Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:39:32 +0100 Subject: [PATCH 2/6] chore: upgrading lock file --- .terraform.lock.hcl | 74 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 9d9276a..0475b4b 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -2,45 +2,53 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "5.65.0" + version = "5.66.0" constraints = ">= 4.8.0, >= 4.9.0, >= 5.0.0, >= 5.25.0" hashes = [ - "h1:OG8xMZjGZL/OtEV9OwX0CTPcUzvSfcfiB0X9lcs2joY=", - "zh:036f8557c8c9b58656e1ec08ed5702e44bd338fda17dc4b2add40b234102e29a", - "zh:0ba0708ece98735540070899a916b7a90c5c887be31ffd693ee1359e40245978", - "zh:12d82a82ae0e3bc580f2be961078e89d129e12df7dd82a6ec610a2b945bba1a4", - "zh:1ed0ee17df8807aef64976e2a4276d2a3e1d54efeae2a86f596d12eccb94dc83", - "zh:36b7c61a83d24f612156b4648027ba8bd5727f0ed57183cbad0e6c93b7503aa2", - "zh:496d06a089b1bc8d60995e8dddfe1d87c605a208f377a60b17987e89381dafda", - "zh:4e9aba435994589befe4279927c71a461a52e6cd96b8f0437295c18c50f6baff", - "zh:71134031288a312db1804d4798b10f106a843c36aafd7b8fe8f4859156d7df93", - "zh:748d0dbdfbe8df4b516a09b23b3981c19cef9a255c1ca0187e84ab424e6bd845", - "zh:783541ff77f4e7c74c817e0e2989ebdb45dd6e2c9853a8cccbcf5f1976736a76", + "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:af3f080975d5ed79917b8238cc0ae3150da688bc89e12dcc3ee85134b29857d0", - "zh:ec542372c3ffbfc3df6966f77357f8af7319d4bd956ff8e9fde0bbd124352e34", - "zh:f3dc7b2b5b55173207c2fd35ed6bb8cc66b06af777e221060ca2f0c0afdecbb5", - "zh:f9631ecc21d6e5cf82ef6ef8d14c39e1dfb2a52cc8f0abb684311885ffdb79a1", + "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:8mByRL3zDm50yiEXMrKtWC2FaLwuvvyjKI+eWuD1dn0=", + "h1:U6W8rgrdmR2pZ2cicFoGOSQ4GXuIf/4EK7s0vTJN7is=", + "h1:XWkRZOLKMjci9/JAtE8X8fWOt7A4u+9mgXSUjc4Wuyo=", + "h1:cCabxnWQ5fX1lS7ZqgUzsvWmKZw9FA7NRxAZ94vcTcc=", + "h1:fjJwsIgh+BJEy8FsSt6HD0rKgA9iDCC+Rkv7IGNdNxc=", + "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", ] } @@ -49,6 +57,10 @@ provider "registry.terraform.io/hashicorp/local" { constraints = ">= 1.0.0" hashes = [ "h1:/GAVA/xheGQcbOZEq0qxANOg+KVLCA7Wv8qluxhTjhU=", + "h1:8oTPe2VUL6E2d3OcrvqyjI4Nn/Y/UEQN26WLk5O/B0g=", + "h1:Np4kERf9SMrqUi7DJ1rK3soMK14k49nfgE7l/ipQ5xw=", + "h1:fm2EuMlsdPTuv2tKwx3PMJzWJUh7aMtU9Eky7t4fMys=", + "h1:tjcGlQAFA0kmQ4vKkIPPUC4it1UYxLbg4YvHOWRAJHA=", "zh:0af29ce2b7b5712319bf6424cb58d13b852bf9a777011a545fac99c7fdcdf561", "zh:126063ea0d79dad1f68fa4e4d556793c0108ce278034f101d1dbbb2463924561", "zh:196bfb49086f22fd4db46033e01655b0e5e036a5582d250412cc690fa7995de5", @@ -68,7 +80,11 @@ provider "registry.terraform.io/hashicorp/null" { version = "3.2.2" constraints = ">= 2.0.0" hashes = [ + "h1:Gef5VGfobY5uokA5nV/zFvWeMNR2Pmq79DH94QnNZPM=", "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", + "h1:m467k2tZ9cdFFgHW7LPBK2GLPH43LC6wc3ppxr8yvoE=", + "h1:vWAsYRd7MjYr3adj8BVKRohVfHpWQdvkIwUQ2Jf5FVM=", + "h1:zT1ZbegaAYHwQa+QwIFugArWikRJI9dqohj8xb0GY88=", "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", From 32318c1a303afbc345c88c499b952552095dd692 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 09:43:32 +0100 Subject: [PATCH 3/6] chore: renaming the mgmt account to root --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index e862fab..ba1bbb1 100644 --- a/main.tf +++ b/main.tf @@ -13,7 +13,7 @@ module "notifications" { sns_topic_name = var.sns_topic_name tags = var.tags accounts_id_to_name = { - "536471746696" = "mgmt" + "536471746696" = "root" } } From 79cb30c2a9b92ae97dfed3b1ff87edc032f0c7ed Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 10:00:48 +0100 Subject: [PATCH 4/6] chore: tidying up variables --- variables.tf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/variables.tf b/variables.tf index f11df3e..a49d165 100644 --- a/variables.tf +++ b/variables.tf @@ -66,8 +66,3 @@ variable "tags" { description = "A map of tags to add to all resources" type = map(string) } - -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 29098486f0d5d53778aba280538142dcae3324f2 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 10:01:24 +0100 Subject: [PATCH 5/6] chore: updated README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8cd15fc..62dbc88 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,6 @@ 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 | | [monitors](#input\_monitors) | A collection of cost anomaly monitors to create |
list(object({
name = string
# The name of the monitor
monitor_type = optional(string, "DIMENSIONAL")
# The type of monitor to create
monitor_dimension = optional(string, "DIMENSIONAL")
# The dimension to monitor
monitor_specification = optional(string, null)
# The specification to monitor
notify = optional(object({
frequency = string
# The frequency of notifications
threshold_expression = optional(any, null)
# The threshold expression to use for notifications
}), {
frequency = "DAILY"
})
}))
| n/a | yes | | [notifications](#input\_notifications) | The configuration of the notification |
object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
secret_name = optional(string, null)
# An optional secret name in the AWS Secrets Manager, containing this information
lambda_name = optional(string, "cost-anomaly-notification")
# The name of the Lambda function to use for notifications
webhook_url = optional(string, null)
# The URL of the Slack webhook to use for notifications, required if secret_name is not provided
}), null)
})
| n/a | yes | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes | From ec9e8547fbdce5978a8a5047347690df6ba3a3a4 Mon Sep 17 00:00:00 2001 From: Warren Ayling Date: Wed, 11 Sep 2024 10:37:09 +0100 Subject: [PATCH 6/6] chore: this is a module so mapping of ids pass be passed as variable --- README.md | 1 + examples/basic/main.tf | 3 +++ examples/existing_sns/README.md | 4 ++-- examples/existing_sns/main.tf | 4 ++++ main.tf | 4 +--- variables.tf | 6 ++++++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 62dbc88..cd0a476 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ The `terraform-docs` utility is used to generate this README. Follow the below s | [monitors](#input\_monitors) | A collection of cost anomaly monitors to create |
list(object({
name = string
# The name of the monitor
monitor_type = optional(string, "DIMENSIONAL")
# The type of monitor to create
monitor_dimension = optional(string, "DIMENSIONAL")
# The dimension to monitor
monitor_specification = optional(string, null)
# The specification to monitor
notify = optional(object({
frequency = string
# The frequency of notifications
threshold_expression = optional(any, null)
# The threshold expression to use for notifications
}), {
frequency = "DAILY"
})
}))
| n/a | yes | | [notifications](#input\_notifications) | The configuration of the notification |
object({
email = optional(object({
addresses = list(string)
}), null)
slack = optional(object({
secret_name = optional(string, null)
# An optional secret name in the AWS Secrets Manager, containing this information
lambda_name = optional(string, "cost-anomaly-notification")
# The name of the Lambda function to use for notifications
webhook_url = optional(string, null)
# The URL of the Slack webhook to use for notifications, required if secret_name is not provided
}), null)
})
| n/a | yes | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes | +| [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)` | `null` | no | | [enable\_notification\_creation](#input\_enable\_notification\_creation) | Indicates whether to create a notification lambda stack, default is true, but useful to toggle if using existing resources | `bool` | `true` | no | | [enable\_sns\_topic\_creation](#input\_enable\_sns\_topic\_creation) | Indicates whether to create an SNS topic within this module | `bool` | `true` | no | | [sns\_topic\_arn](#input\_sns\_topic\_arn) | The ARN of an existing SNS topic for notifications | `string` | `null` | no | diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 4021140..c141b34 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -82,4 +82,7 @@ module "cost_anomaly_detection" { } } tags = var.tags + accounts_id_to_name = { + "1234567890" = "mgmt" + } } diff --git a/examples/existing_sns/README.md b/examples/existing_sns/README.md index a3a0ab5..2851e07 100644 --- a/examples/existing_sns/README.md +++ b/examples/existing_sns/README.md @@ -11,7 +11,7 @@ | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.0.0 | +| [aws](#provider\_aws) | 5.65.0 | ## Modules @@ -30,8 +30,8 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [notification\_secret\_name](#input\_notification\_secret\_name) | The name of the secret that contains the notification configuration | `string` | n/a | yes | | [notification\_email\_addresses](#input\_notification\_email\_addresses) | The list of email addresses to notify | `list(string)` | `[]` | no | +| [notification\_secret\_name](#input\_notification\_secret\_name) | The name of the secret that contains the notification configuration | `string` | n/a | yes | | [tags](#input\_tags) | A map of tags to add to the resources | `map(string)` | `{}` | no | ## Outputs diff --git a/examples/existing_sns/main.tf b/examples/existing_sns/main.tf index d876052..cd74885 100644 --- a/examples/existing_sns/main.tf +++ b/examples/existing_sns/main.tf @@ -63,4 +63,8 @@ module "cost_anomaly_detection" { webhook_url = jsondecode(data.aws_secretsmanager_secret_version.notification.secret_string).webhook_url } } + + accounts_id_to_name = { + "1234567890" = "mgmt" + } } diff --git a/main.tf b/main.tf index ba1bbb1..ec3c0ab 100644 --- a/main.tf +++ b/main.tf @@ -12,9 +12,7 @@ module "notifications" { slack = local.slack sns_topic_name = var.sns_topic_name tags = var.tags - accounts_id_to_name = { - "536471746696" = "root" - } + accounts_id_to_name = var.accounts_id_to_name } ## Provision the cost anomaly detection for services diff --git a/variables.tf b/variables.tf index a49d165..743a801 100644 --- a/variables.tf +++ b/variables.tf @@ -66,3 +66,9 @@ variable "tags" { description = "A map of tags to add to all resources" type = map(string) } + +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) + default = null +}