Skip to content
Open
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
3 changes: 3 additions & 0 deletions aws/telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ module "telemetry" {
| <a name="input_alert_resolve_timeout"></a> [alert\_resolve\_timeout](#input\_alert\_resolve\_timeout) | Time after which alerts without an end time after resolved | `string` | `null` | no |
| <a name="input_alert_severities"></a> [alert\_severities](#input\_alert\_severities) | List of alert priorities for AlertManager | `list(string)` | <pre>[<br> "warning",<br> "ticket",<br> "page"<br>]</pre> | no |
| <a name="input_alert_subject_template"></a> [alert\_subject\_template](#input\_alert\_subject\_template) | Template used for AlertManager alert subjects | `string` | `null` | no |
| <a name="input_alertmanager_config_enabled"></a> [alertmanager\_config\_enabled](#input\_alertmanager\_config\_enabled) | Enable alertmanager configs for the Prometheus workspace | `bool` | `true` | no |
| <a name="input_grafana_role_name"></a> [grafana\_role\_name](#input\_grafana\_role\_name) | Name of the IAM role created for Grafana | `string` | `"grafana"` | no |
| <a name="input_grafana_workspace_name"></a> [grafana\_workspace\_name](#input\_grafana\_workspace\_name) | Name of the Grafana workspace which will use telemetry resources | `string` | `"Grafana"` | no |
| <a name="input_kms_alias_name"></a> [kms\_alias\_name](#input\_kms\_alias\_name) | KMS alias name for SNS topics | `string` | `"alias/sns-alarm-topics"` | no |
| <a name="input_log_group_arn"></a> [log\_group\_arn](#input\_log\_group\_arn) | ARN for the CW log group | `list(string)` | `[]` | no |
| <a name="input_monitoring_account_ids"></a> [monitoring\_account\_ids](#input\_monitoring\_account\_ids) | AWS account IDs in which Grafana will run | `list(string)` | `null` | no |
| <a name="input_prometheus_workspace_name"></a> [prometheus\_workspace\_name](#input\_prometheus\_workspace\_name) | Name of the AWS Managed Prometheus workspace | `string` | n/a | yes |
| <a name="input_sns_topic_name_suffix"></a> [sns\_topic\_name\_suffix](#input\_sns\_topic\_name\_suffix) | Suffix for SNS topic names | `string` | `""` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to created resources | `map(string)` | `{}` | no |

## Outputs
Expand Down
20 changes: 11 additions & 9 deletions aws/telemetry/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module "sns_topics" {
for source in ["alertmanager", "cloudwatch-alarms", "cloudwatch-logs"] :
[
for severity in var.alert_severities :
"${source}-${severity}"
"${source}-${severity}${var.sns_topic_name_suffix}"
]
])

Expand All @@ -18,21 +18,23 @@ module "sns_topics" {
module "prometheus_workspace" {
source = "./modules/prometheus-workspace"

alert_group_by = var.alert_group_by
alert_message_template = var.alert_message_template
alert_resolve_timeout = var.alert_resolve_timeout
alert_subject_template = var.alert_subject_template
name = var.prometheus_workspace_name
tags = var.tags
alert_group_by = var.alert_group_by
alert_message_template = var.alert_message_template
alert_resolve_timeout = var.alert_resolve_timeout
alert_subject_template = var.alert_subject_template
alertmanager_config_enabled = var.alertmanager_config_enabled
log_group_arn = var.log_group_arn
name = var.prometheus_workspace_name
tags = var.tags

sns_receivers = merge({
default = module.sns_topics.arns["alertmanager-${var.alert_default_severity}"]
default = module.sns_topics.arns["alertmanager-${var.alert_default_severity}${var.sns_topic_name_suffix}"]
},
zipmap(
var.alert_severities,
[
for severity in var.alert_severities :
module.sns_topics.arns["alertmanager-${severity}"]
module.sns_topics.arns["alertmanager-${severity}${var.sns_topic_name_suffix}"]
]
)
)
Expand Down
2 changes: 2 additions & 0 deletions aws/telemetry/modules/prometheus-workspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ write to the workspace.
| <a name="input_alert_message_template"></a> [alert\_message\_template](#input\_alert\_message\_template) | Template used for AlertManager messages | `string` | `null` | no |
| <a name="input_alert_resolve_timeout"></a> [alert\_resolve\_timeout](#input\_alert\_resolve\_timeout) | Time after which alerts without an end time after resolved | `string` | `null` | no |
| <a name="input_alert_subject_template"></a> [alert\_subject\_template](#input\_alert\_subject\_template) | Template used for AlertManager alert subjects | `string` | `null` | no |
| <a name="input_alertmanager_config_enabled"></a> [alertmanager\_config\_enabled](#input\_alertmanager\_config\_enabled) | Enable alertmanager configs for the Prometheus workspace | `bool` | `true` | no |
| <a name="input_log_group_arn"></a> [log\_group\_arn](#input\_log\_group\_arn) | ARN for the CW log group | `list(string)` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | Name for this Prometheus workspace | `string` | n/a | yes |
| <a name="input_sns_receivers"></a> [sns\_receivers](#input\_sns\_receivers) | Map of alert priorities to SNS topics for AlertManager | `map(string)` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to created resources | `map(string)` | `{}` | no |
Expand Down
8 changes: 8 additions & 0 deletions aws/telemetry/modules/prometheus-workspace/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
resource "aws_prometheus_workspace" "this" {
alias = var.name
tags = var.tags

dynamic logging_configuration {
for_each = var.log_group_arn
content {
log_group_arn = logging_configuration.value
}
}
}

resource "aws_iam_role" "ingestion" {
Expand Down Expand Up @@ -51,6 +58,7 @@ data "aws_iam_policy_document" "ingestion_assume_role" {
}

resource "aws_prometheus_alert_manager_definition" "this" {
count = var.alertmanager_config_enabled ? 1 : 0
definition = yamlencode(local.alert_manager_definition)
workspace_id = aws_prometheus_workspace.this.id
}
Expand Down
12 changes: 12 additions & 0 deletions aws/telemetry/modules/prometheus-workspace/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ variable "alert_subject_template" {
default = null
}

variable "alertmanager_config_enabled" {
description = "Enable alertmanager configs for the Prometheus workspace"
type = bool
default = true
}

variable "log_group_arn" {
description = "ARN for the CW log group"
type = list(string)
default = []
}

variable "name" {
description = "Name for this Prometheus workspace"
type = string
Expand Down
18 changes: 18 additions & 0 deletions aws/telemetry/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ variable "alert_default_severity" {
default = "warning"
}

variable "alertmanager_config_enabled" {
description = "Enable alertmanager configs for the Prometheus workspace"
type = bool
default = true
}

variable "log_group_arn" {
description = "ARN for the CW log group"
type = list(string)
default = []
}

variable "grafana_role_name" {
description = "Name of the IAM role created for Grafana"
type = string
Expand All @@ -63,6 +75,12 @@ variable "prometheus_workspace_name" {
type = string
}

variable "sns_topic_name_suffix" {
description = "Suffix for SNS topic names"
type = string
default = ""
}

variable "tags" {
description = "Tags to be applied to created resources"
type = map(string)
Expand Down
Loading