From 02a885190cda5e9ef4de77e678407778135a0148 Mon Sep 17 00:00:00 2001 From: Patrick de Ruiter Date: Sat, 1 Nov 2025 10:43:43 +0100 Subject: [PATCH] Initial commit with README and module files --- .gitignore | 9 + .terraform.lock.hcl | 117 ++++++++ README.md | 168 +++++++++++ main.tf | 55 ++++ outputs.tf | 16 + queries.tf | 14 + rds_dashboard.tf | 705 ++++++++++++++++++++++++++++++++++++++++++++ variables.tf | 150 ++++++++++ versions.tf | 18 ++ 9 files changed, 1252 insertions(+) create mode 100755 .gitignore create mode 100755 .terraform.lock.hcl create mode 100644 README.md create mode 100755 main.tf create mode 100755 outputs.tf create mode 100755 queries.tf create mode 100755 rds_dashboard.tf create mode 100755 variables.tf create mode 100755 versions.tf diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..1565be3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.tfstate +*.tfstate.backup +.terraform +provider.tf +*.tfvars +**/*.tfvars +provider.tf +.github +.circleci diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100755 index 0000000..e99dc12 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,117 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/datadog/datadog" { + version = "3.1.2" + constraints = ">= 2.12.0, >= 2.13.0" + hashes = [ + "h1:lG4q9P7EMfrsCq/28SOac51iG2v/ZWSDsndtjeVyShQ=", + "zh:206a91983c7bd4ff3c1036d03608965037d6813122bc7b308a8c5bce1a0e868c", + "zh:355f88c1e3a383538d5713844f7829d78595789416d3abdf54da28c11e5ec386", + "zh:5d6980b8a2b983337e84cae494f88fd4eef6fc28376ff942f2fd4ceb163fd2b9", + "zh:63b36609bc5f574ceced3a311aed1141d9a6202e7f80fcd301b0db918e7e71c3", + "zh:83c6c3fa1c1b95dd2f20511bdd785ec41feb33bdbf1b73f34f8e8fba53b8bf41", + "zh:8eb74bfbe3b03fe6edb2b3d99306479344f3dbbf37d776b773ca3eed18b3557b", + "zh:9523fef89c62e4e5c207593f16a054bb378729760b777282f80af66f64290afc", + "zh:a4b25aa3d174062f6bcf12da2a9b749af4aa1474cdd88b1d42fd64575fe35536", + "zh:aa9486e8256f83a0a22c636ac1e8f677dcbcb2017a7a399da601cb8eff9ac49a", + "zh:c2cc7a5f29aadf27fcf42b9ad410b838a8259e803a6e82eccf5087744bcbdc04", + "zh:e21631e8b139b7e9632e1107a0db9ea8364a0fdfdb72b1d7d2e14148d1de57e8", + "zh:f7dba38c2fb09676a2a5f444b1e251349d0c060d837cf8e1f3e1046947effb4a", + "zh:f820dd9e935bf28e7f4b1c96a236175990d478d5f48c43ea344d574340b16b07", + ] +} + +provider "registry.terraform.io/hashicorp/archive" { + version = "2.2.0" + constraints = ">= 2.2.0" + hashes = [ + "h1:2K5LQkuWRS2YN1/YoNaHn9MAzjuTX8Gaqy6i8Mbfv8Y=", + "zh:06bd875932288f235c16e2237142b493c2c2b6aba0e82e8c85068332a8d2a29e", + "zh:0c681b481372afcaefddacc7ccdf1d3bb3a0c0d4678a526bc8b02d0c331479bc", + "zh:100fc5b3fc01ea463533d7bbfb01cb7113947a969a4ec12e27f5b2be49884d6c", + "zh:55c0d7ddddbd0a46d57c51fcfa9b91f14eed081a45101dbfc7fd9d2278aa1403", + "zh:73a5dd68379119167934c48afa1101b09abad2deb436cd5c446733e705869d6b", + "zh:841fc4ac6dc3479981330974d44ad2341deada8a5ff9e3b1b4510702dfbdbed9", + "zh:91be62c9b41edb137f7f835491183628d484e9d6efa82fcb75cfa538c92791c5", + "zh:acd5f442bd88d67eb948b18dc2ed421c6c3faee62d3a12200e442bfff0aa7d8b", + "zh:ad5720da5524641ad718a565694821be5f61f68f1c3c5d2cfa24426b8e774bef", + "zh:e63f12ea938520b3f83634fc29da28d92eed5cfbc5cc8ca08281a6a9c36cca65", + "zh:f6542918faa115df46474a36aabb4c3899650bea036b5f8a5e296be6f8f25767", + ] +} + +provider "registry.terraform.io/hashicorp/aws" { + version = "3.48.0" + constraints = ">= 2.0.0" + hashes = [ + "h1:HY/knz06L5OaxmLsuOevFA6PgF7eJKoQSZLlX2IqubU=", + "zh:1de9f52bc5c254fc021a4fdb285fca5cf7665e9eda890ac24aa7af8469654cc9", + "zh:2faf10c36dfaf6a97fb6a4c877ae9be61cb6bb81ee666f3455f156116b20c7a4", + "zh:3dad064853e24c0854c3e47c67f9e77c11319e52f0f3525a2583db13a272af6d", + "zh:56e9363542b5c745110b83f3904524669bb801f62db928d42860202ba3f48b51", + "zh:591088a86f9c9826d1b6918964386ca04b3d4e521efea9a5f00152d134162664", + "zh:baf5afc4b38b4bc9010123b1251fd7af8b68828fda22b67bd4e4f631bd19671a", + "zh:d3963400ef625433ea7d1fbabb564ac0aafaabb67c138f4a2954f05813f4cbd5", + "zh:d67856355bc746924bbdfcd4709afe9ebf8ccd5092fb10d6cb5fa1f19e6c2f43", + "zh:db99519a33a12b4f5965bf7127ed92759242e694b5ab1680aab6345d0102a200", + "zh:e44aea91718a15b96d903f60ac8cf5f913c6828c860035993c9bd1b872d84159", + "zh:fc25605dafb055d9138d90a837f5ae9ee96bcd4f8a2a89c4180573f6ea8fda66", + ] +} + +provider "registry.terraform.io/hashicorp/external" { + version = "2.1.0" + constraints = ">= 1.2.0" + hashes = [ + "h1:LTl5CGW8wiIEe16AC4MtXN/95xWWNDbap70zJsBTk0w=", + "zh:0d83ffb72fbd08986378204a7373d8c43b127049096eaf2765bfdd6b00ad9853", + "zh:7577d6edc67b1e8c2cf62fe6501192df1231d74125d90e51d570d586d95269c5", + "zh:9c669ded5d5affa4b2544952c4b6588dfed55260147d24ced02dca3a2829f328", + "zh:a404d46f2831f90633947ab5d57e19dbfe35b3704104ba6ec80bcf50b058acfd", + "zh:ae1caea1c936d459ceadf287bb5c5bd67b5e2a7819df6f5c4114b7305df7f822", + "zh:afb4f805477694a4b9dde86b268d2c0821711c8aab1c6088f5f992228c4c06fb", + "zh:b993b4a1de8a462643e78f4786789e44ce5064b332fee1cb0d6250ed085561b8", + "zh:c84b2c13fa3ea2c0aa7291243006d560ce480a5591294b9001ce3742fc9c5791", + "zh:c8966f69b7eccccb771704fd5335923692eccc9e0e90cb95d14538fe2e92a3b8", + "zh:d5fe68850d449b811e633a300b114d0617df6d450305e8251643b4d143dc855b", + "zh:ddebfd1e674ba336df09b1f27bbaa0e036c25b7a7087dc8081443f6e5954028b", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.1.0" + constraints = ">= 1.3.0" + hashes = [ + "h1:KfieWtVyGWwplSoLIB5usKAUnrIkDQBkWaR5TI+4WYg=", + "zh:0f1ec65101fa35050978d483d6e8916664b7556800348456ff3d09454ac1eae2", + "zh:36e42ac19f5d68467aacf07e6adcf83c7486f2e5b5f4339e9671f68525fc87ab", + "zh:6db9db2a1819e77b1642ec3b5e95042b202aee8151a0256d289f2e141bf3ceb3", + "zh:719dfd97bb9ddce99f7d741260b8ece2682b363735c764cac83303f02386075a", + "zh:7598bb86e0378fd97eaa04638c1a4c75f960f62f69d3662e6d80ffa5a89847fe", + "zh:ad0a188b52517fec9eca393f1e2c9daea362b33ae2eb38a857b6b09949a727c1", + "zh:c46846c8df66a13fee6eff7dc5d528a7f868ae0dcf92d79deaac73cc297ed20c", + "zh:dc1a20a2eec12095d04bf6da5321f535351a594a636912361db20eb2a707ccc4", + "zh:e57ab4771a9d999401f6badd8b018558357d3cbdf3d33cc0c4f83e818ca8e94b", + "zh:ebdcde208072b4b0f8d305ebf2bfdc62c926e0717599dcf8ec2fd8c5845031c3", + "zh:ef34c52b68933bedd0868a13ccfd59ff1c820f299760b3c02e008dc95e2ece91", + ] +} + +provider "registry.terraform.io/hashicorp/template" { + version = "2.2.0" + constraints = ">= 2.0.0" + hashes = [ + "h1:0wlehNaxBX7GJQnPfQwTNvvAf38Jm0Nv7ssKGMaG6Og=", + "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", + "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", + "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", + "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", + "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", + "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", + "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", + "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", + "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", + "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", + ] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..d272795 --- /dev/null +++ b/README.md @@ -0,0 +1,168 @@ +# Terraform Datadog Belgie (RDS Dashboard) Module + +## Overview + +This Terraform module creates an AWS RDS database monitoring dashboard in Datadog with comprehensive metrics for performance, storage, connections, and replication lag. Designed specifically for Belgian/EU deployments with pre-configured alert recipients and monitoring thresholds. + +## Features + +- **Comprehensive RDS Metrics**: CPU, memory, connections, storage, disk queue, latency +- **Dynamic Dashboard**: 25+ preconfigured widgets with automatic metric visualization +- **Flexible Alerting**: Configurable alert recipients for different severity levels +- **CloudWatch Integration**: Leverages AWS RDS CloudWatch metrics +- **Customizable Monitors**: Map-based monitor configuration for easy customization + +## Resources Created + +- `datadog_dashboard`: RDS Database Dashboard with 25+ widgets including: + - Query value widgets for read/write latency and IOPS + - Timeseries for replication lag, connections, CPU, memory, disk metrics + - Toplist widgets for metric ranking + - Note widgets for dashboard organization + +## Dashboard Widgets + +The dashboard includes comprehensive monitoring for: +- Read/Write Latency (query value widgets) +- Replication Lag (timeseries) +- Database Connections (timeseries) +- CPU Utilization (timeseries + toplist) +- Read/Write Operations (timeseries) +- Freeable Memory (timeseries + toplist) +- Disk Queue Depth (timeseries) +- Free Storage Space (timeseries + toplist) + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12 | +| datadog | >= 3.1.2 | +| aws | >= 2.0 | + +## Usage + +```hcl +module "rds_dashboard" { + source = "./terraform-datadog-belgie" + + region = "eu-west-1" + api_key = var.datadog_api_key + app_key = var.datadog_app_key + datadog_site = "https://api.datadoghq.eu/" + aws_profile = "production" + cfa_slug = "my-cfa" + team = "platform-team" + application = "myapp" + stage = "prd" + + alert_recipients = ["team@example.com"] + recipients = ["team@example.com"] + warning_recipients = ["team@example.com"] + + dd_rds_monitors = { + cpu = { + enabled = true + warning = 75 + critical = 90 + name = "RDS CPU High" + } + # ... additional monitors + } +} +``` + +## Inputs + +| Name | Description | Type | Required | Default | +|------|-------------|------|----------|---------| +| `region` | AWS region for resources | `string` | yes | - | +| `api_key` | Datadog API key | `string` | yes | - | +| `app_key` | Datadog APP key | `string` | yes | - | +| `datadog_site` | Datadog site (EU or US) | `string` | no | `"https://api.datadoghq.eu/"` | +| `aws_profile` | AWS account this integration belongs to | `string` | yes | - | +| `cfa_slug` | CFA this integration belongs to | `string` | yes | - | +| `team` | Team this integration belongs to | `string` | yes | - | +| `application` | Application name | `string` | yes | - | +| `stage` | Stage (dev, tst, acc, prd) | `string` | yes | - | +| `alert_recipients` | Alert notification recipients | `list(string)` | no | `["patrick.de.ruiter@sanoma.com"]` | +| `recipients` | General notification recipients | `list(string)` | no | `["patrick.de.ruiter@sanoma.com"]` | +| `warning_recipients` | Warning notification recipients | `list(string)` | no | `["patrick.de.ruiter@sanoma.com"]` | +| `dd_rds_monitors` | RDS monitor configuration map | `map(any)` | no | See variables.tf | + +## RDS Monitors Configuration + +The `dd_rds_monitors` variable accepts a map with the following monitor types: +- `cpu`: CPU utilization monitoring +- `memory`: Freeable memory monitoring +- `connections`: Database connections monitoring +- `storage`: Free storage space monitoring +- `disk_queue`: Disk queue depth monitoring +- `read_latency`: Read latency monitoring +- `write_latency`: Write latency monitoring +- `replication_lag`: Replication lag monitoring + +Each monitor can be configured with: +```hcl +{ + enabled = bool # Enable/disable the monitor + warning = number # Warning threshold + critical = number # Critical threshold + name = string # Monitor name +} +``` + +## Outputs + +Currently, this module does not export any outputs (outputs are commented out). + +## Local Values + +The module uses several local values for dynamic configuration: +- `dbidentifier`: Formatted as `{application}-{stage}` +- `rdsgraphs`: Map of 8 RDS metric queries +- `full_message`: Constructed alert message with links +- `tags`: Standard tags (team, stage, application) + +## RDS Metrics Monitored + +| Metric | CloudWatch Metric Name | Description | +|--------|----------------------|-------------| +| CPU | `aws.rds.cpuutilization` | CPU utilization percentage | +| Memory | `aws.rds.freeable_memory` | Freeable memory in bytes | +| Connections | `aws.rds.database_connections` | Number of database connections | +| Storage | `aws.rds.free_storage_space` | Free storage space in bytes | +| Read Latency | `aws.rds.read_latency` | Read operation latency | +| Write Latency | `aws.rds.write_latency` | Write operation latency | +| Disk Queue | `aws.rds.disk_queue_depth` | Disk queue depth | +| Replication Lag | `aws.rds.replica_lag` | Replication lag in seconds | + +## Dashboard Layout + +- **Layout Type**: Free layout (allows custom positioning) +- **Read-Only**: No (allows modifications in UI) +- **Widget Organization**: Sections with note widgets as headers +- **Conditional Formatting**: Metric values color-coded based on thresholds + +## Tagging Strategy + +All resources are tagged with: +- `team:{team}` +- `stage:{stage}` +- `application:{application}` + +## Notes + +- Default Datadog site is EU (GDPR compliance) +- Dashboard uses free layout for flexible widget positioning +- Metrics are sourced from AWS RDS CloudWatch integration +- Database identifier is auto-generated from application and stage variables +- Alert messages include links to related monitors + +## License + +Internal use only - Sanoma/WeBuildYourCloud + +## Authors + +Created and maintained by the Platform Engineering team. diff --git a/main.tf b/main.tf new file mode 100755 index 0000000..27b1ba6 --- /dev/null +++ b/main.tf @@ -0,0 +1,55 @@ +locals { + recipients_message = "${length(var.recipients) > 0 ? " @" : ""}${join(" @", var.recipients)}" + alert_message = length(var.alert_recipients) > 0 ? "{{#is_alert}} @${join(" @", var.alert_recipients)}{{/is_alert}}" : "" + alert_recovery_message = length(var.alert_recipients) > 0 ? "{{#is_alert_recovery}} @${join(" @", var.alert_recipients)}{{/is_alert_recovery}}" : "" + warning_message = length(var.warning_recipients) > 0 ? "{{#is_warning}} @${join(" @", var.warning_recipients)}{{/is_warning}}" : "" + warning_recovery_message = length(var.warning_recipients) > 0 ? "{{#is_warning_recovery}} @${join(" @", var.warning_recipients)}{{/is_warning_recovery}}" : "" + + #full_message = <