Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/SA-251: upgrading to latest notifications module #26

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 45 additions & 29 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The `terraform-docs` utility is used to generate this README. Follow the below s

| Name | Source | Version |
|------|--------|---------|
| <a name="module_notifications"></a> [notifications](#module\_notifications) | appvia/notifications/aws | 0.1.7 |
| <a name="module_notifications"></a> [notifications](#module\_notifications) | appvia/notifications/aws | 1.0.1 |

## Resources

Expand All @@ -69,8 +69,9 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_monitors"></a> [monitors](#input\_monitors) | A collection of cost anomaly monitors to create | <pre>list(object({<br> name = string<br> # The name of the monitor <br> monitor_type = optional(string, "DIMENSIONAL")<br> # The type of monitor to create <br> monitor_dimension = optional(string, "DIMENSIONAL")<br> # The dimension to monitor<br> monitor_specification = optional(string, null)<br> # The specification to monitor <br> notify = optional(object({<br> frequency = string<br> # The frequency of notifications<br> threshold_expression = optional(any, null)<br> # The threshold expression to use for notifications<br> }), {<br> frequency = "DAILY"<br> })<br> }))</pre> | n/a | yes |
| <a name="input_notifications"></a> [notifications](#input\_notifications) | The configuration of the notification | <pre>object({<br> email = optional(object({<br> addresses = list(string)<br> }), null)<br> slack = optional(object({<br> channel = optional(string, null)<br> # The channel name for notifications, required if secret_name is not provided<br> secret_name = optional(string, null)<br> # An optional secret name in the AWS Secrets Manager, containing this information <br> lambda_name = optional(string, "cost-anomaly-notification")<br> # The name of the Lambda function to use for notifications <br> username = optional(string, "AWS Cost Anomaly Detection")<br> # The username to use for notifications<br> webhook_url = optional(string, null)<br> # The URL of the Slack webhook to use for notifications, required if secret_name is not provided<br> }), null)<br> })</pre> | n/a | yes |
| <a name="input_notifications"></a> [notifications](#input\_notifications) | The configuration of the notification | <pre>object({<br> email = optional(object({<br> addresses = list(string)<br> }), null)<br> slack = optional(object({<br> secret_name = optional(string, null)<br> # An optional secret name in the AWS Secrets Manager, containing this information <br> lambda_name = optional(string, "cost-anomaly-notification")<br> # The name of the Lambda function to use for notifications <br> webhook_url = optional(string, null)<br> # The URL of the Slack webhook to use for notifications, required if secret_name is not provided<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_accounts_id_to_name"></a> [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 |
| <a name="input_enable_notification_creation"></a> [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 |
| <a name="input_enable_sns_topic_creation"></a> [enable\_sns\_topic\_creation](#input\_enable\_sns\_topic\_creation) | Indicates whether to create an SNS topic within this module | `bool` | `true` | no |
| <a name="input_sns_topic_arn"></a> [sns\_topic\_arn](#input\_sns\_topic\_arn) | The ARN of an existing SNS topic for notifications | `string` | `null` | no |
Expand Down
3 changes: 3 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ module "cost_anomaly_detection" {
}
}
tags = var.tags
accounts_id_to_name = {
"1234567890" = "mgmt"
}
}
4 changes: 2 additions & 2 deletions examples/existing_sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.65.0 |

## Modules

Expand All @@ -30,8 +30,8 @@

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_notification_secret_name"></a> [notification\_secret\_name](#input\_notification\_secret\_name) | The name of the secret that contains the notification configuration | `string` | n/a | yes |
| <a name="input_notification_email_addresses"></a> [notification\_email\_addresses](#input\_notification\_email\_addresses) | The list of email addresses to notify | `list(string)` | `[]` | no |
| <a name="input_notification_secret_name"></a> [notification\_secret\_name](#input\_notification\_secret\_name) | The name of the secret that contains the notification configuration | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to the resources | `map(string)` | `{}` | no |

## Outputs
Expand Down
4 changes: 4 additions & 0 deletions examples/existing_sns/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 0 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
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 = var.accounts_id_to_name
}

## Provision the cost anomaly detection for services
Expand Down
10 changes: 6 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -70,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
}