From 956bc09bec4fb72b74a5d6f236711050786fb550 Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:31:45 +0100 Subject: [PATCH] doc e refactor --- kubernetes_cluster_udr/README.md | 2 +- postgres_flexible_server_replica/01_main.tf | 6 +- .../02_monitor_flexible.tf | 9 +- .../04_variables.tf | 32 +-- postgres_flexible_server_replica/README.md | 207 ++++-------------- 5 files changed, 76 insertions(+), 180 deletions(-) diff --git a/kubernetes_cluster_udr/README.md b/kubernetes_cluster_udr/README.md index df736351..08a72fc9 100644 --- a/kubernetes_cluster_udr/README.md +++ b/kubernetes_cluster_udr/README.md @@ -694,6 +694,7 @@ No modules. | [automatic\_channel\_upgrade](#input\_automatic\_channel\_upgrade) | (Optional) The upgrade channel for this Kubernetes Cluster. Possible values are patch, rapid, node-image and stable. Omitting this field sets this value to none. | `string` | `null` | no | | [custom\_metric\_alerts](#input\_custom\_metric\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
metric_name = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string

dimension = list(object(
{
name = string
operator = string
values = list(string)
}
))
}))
| `{}` | no | | [default\_metric\_alerts](#input\_default\_metric\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
metric_name = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string

dimension = list(object(
{
name = string
operator = string
values = list(string)
}
))
}))
|
{
"container_cpu": {
"aggregation": "Average",
"dimension": [
{
"name": "kubernetes namespace",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "controllerName",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "cpuExceededPercentage",
"metric_namespace": "Insights.Container/containers",
"operator": "GreaterThan",
"threshold": 95,
"window_size": "PT30M"
},
"container_memory": {
"aggregation": "Average",
"dimension": [
{
"name": "kubernetes namespace",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "controllerName",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "memoryWorkingSetExceededPercentage",
"metric_namespace": "Insights.Container/containers",
"operator": "GreaterThan",
"threshold": 95,
"window_size": "PT30M"
},
"container_oom": {
"aggregation": "Average",
"dimension": [
{
"name": "kubernetes namespace",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "controllerName",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "oomKilledContainerCount",
"metric_namespace": "Insights.Container/pods",
"operator": "GreaterThan",
"threshold": 0,
"window_size": "PT30M"
},
"container_restart": {
"aggregation": "Average",
"dimension": [
{
"name": "kubernetes namespace",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "controllerName",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "restartingContainerCount",
"metric_namespace": "Insights.Container/pods",
"operator": "GreaterThan",
"threshold": 0,
"window_size": "PT30M"
},
"node_cpu": {
"aggregation": "Average",
"dimension": [
{
"name": "host",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "cpuUsagePercentage",
"metric_namespace": "Insights.Container/nodes",
"operator": "GreaterThan",
"threshold": 80,
"window_size": "PT30M"
},
"node_disk": {
"aggregation": "Average",
"dimension": [
{
"name": "host",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "device",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "DiskUsedPercentage",
"metric_namespace": "Insights.Container/nodes",
"operator": "GreaterThan",
"threshold": 80,
"window_size": "PT30M"
},
"node_memory": {
"aggregation": "Average",
"dimension": [
{
"name": "host",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "memoryWorkingSetPercentage",
"metric_namespace": "Insights.Container/nodes",
"operator": "GreaterThan",
"threshold": 80,
"window_size": "PT30M"
},
"node_not_ready": {
"aggregation": "Average",
"dimension": [
{
"name": "status",
"operator": "Include",
"values": [
"NotReady"
]
}
],
"frequency": "PT5M",
"metric_name": "nodesCount",
"metric_namespace": "Insights.Container/nodes",
"operator": "GreaterThan",
"threshold": 0,
"window_size": "PT30M"
},
"pods_failed": {
"aggregation": "Average",
"dimension": [
{
"name": "phase",
"operator": "Include",
"values": [
"Failed"
]
}
],
"frequency": "PT5M",
"metric_name": "podCount",
"metric_namespace": "Insights.Container/pods",
"operator": "GreaterThan",
"threshold": 0,
"window_size": "PT30M"
},
"pods_ready": {
"aggregation": "Average",
"dimension": [
{
"name": "kubernetes namespace",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "controllerName",
"operator": "Include",
"values": [
"*"
]
}
],
"frequency": "PT5M",
"metric_name": "PodReadyPercentage",
"metric_namespace": "Insights.Container/pods",
"operator": "LessThan",
"threshold": 80,
"window_size": "PT30M"
}
}
| no | +| [disk\_encryption\_set\_id](#input\_disk\_encryption\_set\_id) | ID of the disk EncryptionSet . | `string` | `null` | no | | [dns\_prefix](#input\_dns\_prefix) | (Required) DNS prefix specified when creating the managed cluster. Changing this forces a new resource to be created. | `string` | n/a | yes | | [dns\_prefix\_private\_cluster](#input\_dns\_prefix\_private\_cluster) | Specifies the DNS prefix to use with private clusters. Changing this forces a new resource to be created. | `string` | `null` | no | | [kubernetes\_version](#input\_kubernetes\_version) | (Required) Version of Kubernetes specified when creating the AKS managed cluster. | `string` | n/a | yes | @@ -750,7 +751,6 @@ No modules. | [id](#output\_id) | n/a | | [identity\_principal\_id](#output\_identity\_principal\_id) | The Principal ID associated with this Managed Service Identity. | | [kubelet\_identity\_id](#output\_kubelet\_identity\_id) | The Object ID of the user-defined Managed Identity assigned to the Kubelets.If not specified a Managed Identity is created automatically. Changing this forces a new resource to be created. | -| [managed\_resource\_group\_id](#output\_managed\_resource\_group\_id) | The ID of the Resource Group containing the resources for this Managed Kubernetes Cluster. | | [managed\_resource\_group\_name](#output\_managed\_resource\_group\_name) | The auto-generated Resource Group which contains the resources for this Managed Kubernetes Cluster. | | [name](#output\_name) | n/a | | [private\_fqdn](#output\_private\_fqdn) | The FQDN for the Kubernetes Cluster when private link has been enabled, which is only resolvable inside the Virtual Network used by the Kubernetes Cluster. | diff --git a/postgres_flexible_server_replica/01_main.tf b/postgres_flexible_server_replica/01_main.tf index e13f78cd..75cf80cc 100644 --- a/postgres_flexible_server_replica/01_main.tf +++ b/postgres_flexible_server_replica/01_main.tf @@ -12,15 +12,15 @@ resource "azurerm_postgresql_flexible_server" "this" { location = var.location resource_group_name = var.resource_group_name - create_mode = "Replica" - zone = var.zone + create_mode = "Replica" + zone = var.zone # The provided subnet should not have any other resource deployed in it and this subnet will be delegated to the PostgreSQL Flexible Server, if not already delegated. delegated_subnet_id = var.private_endpoint_enabled ? var.delegated_subnet_id : null # private_dns_zobe_id will be required when setting a delegated_subnet_id private_dns_zone_id = var.private_endpoint_enabled ? var.private_dns_zone_id : null - sku_name = var.sku_name + sku_name = var.sku_name source_server_id = var.source_server_id diff --git a/postgres_flexible_server_replica/02_monitor_flexible.tf b/postgres_flexible_server_replica/02_monitor_flexible.tf index ed2743b1..4f6b922a 100644 --- a/postgres_flexible_server_replica/02_monitor_flexible.tf +++ b/postgres_flexible_server_replica/02_monitor_flexible.tf @@ -1,8 +1,13 @@ # # Monitor Metrics # +locals { + replica_metrics = merge(local.default_replica_server_metrics, var.replica_server_metric_alerts) + main_metrics = merge(local.default_main_server_metrics, var.main_server_additional_alerts) +} + resource "azurerm_monitor_metric_alert" "replica_alerts" { - for_each = var.replica_server_metric_alerts + for_each = var.replica_metrics enabled = var.alerts_enabled name = "${var.name}-${upper(each.key)}" @@ -32,7 +37,7 @@ resource "azurerm_monitor_metric_alert" "replica_alerts" { } resource "azurerm_monitor_metric_alert" "main_server_alerts" { - for_each = var.main_server_additional_alerts + for_each = var.main_metrics enabled = var.alerts_enabled name = "${var.name}-${upper(each.key)}" diff --git a/postgres_flexible_server_replica/04_variables.tf b/postgres_flexible_server_replica/04_variables.tf index 6ab12c0e..ebf9691e 100644 --- a/postgres_flexible_server_replica/04_variables.tf +++ b/postgres_flexible_server_replica/04_variables.tf @@ -119,19 +119,8 @@ variable "replica_server_metric_alerts" { # severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3. severity = number })) + default = {} - default = { - replica_lag = { - frequency = "PT5M" - window_size = "PT30M" - metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers" - aggregation = "Average" - metric_name = "physical_replication_delay_in_seconds" - operator = "GreaterThanOrEqual" - threshold = 240 - severity = 2 - } - } } @@ -157,8 +146,11 @@ variable "main_server_additional_alerts" { # severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3. severity = number })) + default = {} +} - default = { +locals { + default_main_server_metrics = { replication_delay_bytes = { frequency = "PT5M" window_size = "PT30M" @@ -170,6 +162,18 @@ variable "main_server_additional_alerts" { severity = 2 } } + default_replica_server_metrics = { + replica_lag = { + frequency = "PT5M" + window_size = "PT30M" + metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers" + aggregation = "Average" + metric_name = "physical_replication_delay_in_seconds" + operator = "GreaterThanOrEqual" + threshold = 240 + severity = 2 + } + } } variable "alerts_enabled" { @@ -208,7 +212,7 @@ variable "diagnostic_setting_destination_storage_id" { } variable "source_server_id" { - type = string + type = string description = "(Required) Id of the source server to be replicated" } diff --git a/postgres_flexible_server_replica/README.md b/postgres_flexible_server_replica/README.md index e8665c52..0e00e232 100644 --- a/postgres_flexible_server_replica/README.md +++ b/postgres_flexible_server_replica/README.md @@ -1,14 +1,12 @@ -# Postgres Flexible Server +# Postgres Flexible Server Replica -Module that allows the creation of a postgres flexible. +Module that allows the creation of a postgres flexible replica ## Production Ready > See how to use in production: -## Architecture -![architecture](./docs/module-arch.drawio.png) ## Connection to DB @@ -18,20 +16,13 @@ Module that allows the creation of a postgres flexible. * **HA** and **pg bouncer** is not avaible for `B series` machines -## Customer managed key - -It's now possible to use a `Customer managed key`. To achieve this result you need to set: -``` -customer_managed_key_enabled = true (default = false) -``` -Please have a look at the example in the `tests` folder to understand how to proceed and see a working example. ## Metrics -By default the module has his own metrics, but if you want to override it you can use the parameter `custom_metric_alerts` with this example structure: - +By default the module has his own metrics (replica lag in bytes and in seconds), but if you want to add your own metrics you can use the parameters `main_server_additional_alerts` and `replica_server_metric_alerts` with this example structure: +They will be added to the already provided metrics ```ts -variable "pgflex_public_metric_alerts" { +variable "main_server_additional_alerts" { description = < [administrator\_login](#input\_administrator\_login) | Flexible PostgreSql server administrator\_login | `string` | n/a | yes | -| [administrator\_password](#input\_administrator\_password) | Flexible PostgreSql server administrator\_password | `string` | n/a | yes | | [alert\_action](#input\_alert\_action) | The ID of the Action Group and optional map of custom string properties to include with the post webhook operation. |
set(object(
{
action_group_id = string
webhook_properties = map(string)
}
))
| `[]` | no | | [alerts\_enabled](#input\_alerts\_enabled) | Should Metrics Alert be enabled? | `bool` | `true` | no | -| [backup\_retention\_days](#input\_backup\_retention\_days) | (Optional) The backup retention days for the PostgreSQL Flexible Server. Possible values are between 7 and 35 days. | `number` | `7` | no | -| [create\_mode](#input\_create\_mode) | (Optional) The creation mode. Can be used to restore or replicate existing servers. Possible values are Default, Replica, GeoRestore, and PointInTimeRestore | `string` | `"Default"` | no | -| [custom\_metric\_alerts](#input\_custom\_metric\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
metric_name = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string
# severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.
severity = number
}))
| `null` | no | -| [customer\_managed\_key\_enabled](#input\_customer\_managed\_key\_enabled) | enable customer\_managed\_key | `bool` | `"false"` | no | -| [customer\_managed\_key\_kv\_key\_id](#input\_customer\_managed\_key\_kv\_key\_id) | The ID of the Key Vault Key | `string` | `null` | no | -| [db\_version](#input\_db\_version) | (Required) The version of PostgreSQL Flexible Server to use. Possible values are 11,12 and 13. Required when create\_mode is Default | `number` | n/a | yes | -| [default\_metric\_alerts](#input\_default\_metric\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
metric_name = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string
# severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.
severity = number
}))
|
{
"active_connections": {
"aggregation": "Average",
"frequency": "PT5M",
"metric_name": "active_connections",
"metric_namespace": "Microsoft.DBforPostgreSQL/flexibleServers",
"operator": "GreaterThan",
"severity": 2,
"threshold": 80,
"window_size": "PT30M"
},
"connections_failed": {
"aggregation": "Total",
"frequency": "PT5M",
"metric_name": "connections_failed",
"metric_namespace": "Microsoft.DBforPostgreSQL/flexibleServers",
"operator": "GreaterThan",
"severity": 2,
"threshold": 80,
"window_size": "PT30M"
},
"cpu_percent": {
"aggregation": "Average",
"frequency": "PT5M",
"metric_name": "cpu_percent",
"metric_namespace": "Microsoft.DBforPostgreSQL/flexibleServers",
"operator": "GreaterThan",
"severity": 2,
"threshold": 80,
"window_size": "PT30M"
},
"memory_percent": {
"aggregation": "Average",
"frequency": "PT5M",
"metric_name": "memory_percent",
"metric_namespace": "Microsoft.DBforPostgreSQL/flexibleServers",
"operator": "GreaterThan",
"severity": 2,
"threshold": 80,
"window_size": "PT30M"
},
"storage_percent": {
"aggregation": "Average",
"frequency": "PT5M",
"metric_name": "storage_percent",
"metric_namespace": "Microsoft.DBforPostgreSQL/flexibleServers",
"operator": "GreaterThan",
"severity": 2,
"threshold": 80,
"window_size": "PT30M"
}
}
| no | | [delegated\_subnet\_id](#input\_delegated\_subnet\_id) | (Optional) The ID of the virtual network subnet to create the PostgreSQL Flexible Server. The provided subnet should not have any other resource deployed in it and this subnet will be delegated to the PostgreSQL Flexible Server, if not already delegated. | `string` | `null` | no | | [diagnostic\_setting\_destination\_storage\_id](#input\_diagnostic\_setting\_destination\_storage\_id) | (Optional) The ID of the Storage Account where logs should be sent. Changing this forces a new resource to be created. | `string` | `null` | no | | [diagnostic\_settings\_enabled](#input\_diagnostic\_settings\_enabled) | Is diagnostic settings enabled? | `bool` | `true` | no | -| [geo\_redundant\_backup\_enabled](#input\_geo\_redundant\_backup\_enabled) | (Optional) Is Geo-Redundant backup enabled on the PostgreSQL Flexible Server. Defaults to false | `bool` | `false` | no | | [high\_availability\_enabled](#input\_high\_availability\_enabled) | (Required) Is the High Availability Enabled | `bool` | n/a | yes | | [location](#input\_location) | (Required) The Azure Region where the PostgreSQL Flexible Server should exist. | `string` | n/a | yes | | [log\_analytics\_workspace\_id](#input\_log\_analytics\_workspace\_id) | (Optional) Specifies the ID of a Log Analytics Workspace where Diagnostics Data should be sent. | `string` | `null` | no | +| [main\_server\_additional\_alerts](#input\_main\_server\_additional\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
metric_name = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string
# severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.
severity = number
}))
| n/a | yes | | [maintenance\_window\_config](#input\_maintenance\_window\_config) | (Optional) Allows the configuration of the maintenance window, if not configured default is Wednesday@2.00am |
object({
day_of_week = number
start_hour = number
start_minute = number
})
|
{
"day_of_week": 3,
"start_hour": 2,
"start_minute": 0
}
| no | | [name](#input\_name) | (Required) The name which should be used for this PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created. | `string` | n/a | yes | | [pgbouncer\_enabled](#input\_pgbouncer\_enabled) | Is PgBouncer enabled into configurations? | `bool` | `true` | no | -| [primary\_user\_assigned\_identity\_id](#input\_primary\_user\_assigned\_identity\_id) | Manages a User Assigned Identity | `string` | `null` | no | | [private\_dns\_zone\_id](#input\_private\_dns\_zone\_id) | (Optional) The ID of the private dns zone to create the PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created. | `string` | `null` | no | | [private\_endpoint\_enabled](#input\_private\_endpoint\_enabled) | Is this instance private only? | `bool` | n/a | yes | +| [replica\_server\_metric\_alerts](#input\_replica\_server\_metric\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
metric_name = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string
# severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.
severity = number
}))
| n/a | yes | | [resource\_group\_name](#input\_resource\_group\_name) | (Required) The name of the Resource Group where the PostgreSQL Flexible Server should exist. | `string` | n/a | yes | | [sku\_name](#input\_sku\_name) | The SKU Name for the PostgreSQL Flexible Server. The name of the SKU, follows the tier + name pattern (e.g. B\_Standard\_B1ms, GP\_Standard\_D2s\_v3, MO\_Standard\_E4s\_v3). | `string` | n/a | yes | +| [source\_server\_id](#input\_source\_server\_id) | (Required) Id of the source server to be replicated | `string` | n/a | yes | | [standby\_availability\_zone](#input\_standby\_availability\_zone) | (Optional) Specifies the Availability Zone in which the standby Flexible Server should be located. | `number` | `null` | no | -| [storage\_mb](#input\_storage\_mb) | The max storage allowed for the PostgreSQL Flexible Server. Possible values are 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, and 33554432. | `number` | `null` | no | | [tags](#input\_tags) | n/a | `map(any)` | n/a | yes | | [zone](#input\_zone) | (Optional) Specifies the Availability Zone in which the PostgreSQL Flexible Server should be located. | `number` | `null` | no | @@ -308,8 +197,6 @@ No modules. | Name | Description | |------|-------------| -| [administrator\_login](#output\_administrator\_login) | n/a | -| [administrator\_password](#output\_administrator\_password) | n/a | | [connection\_port](#output\_connection\_port) | n/a | | [fqdn](#output\_fqdn) | n/a | | [id](#output\_id) | n/a |