From d3540ea642602ef8e28be21a37f260089f56f39e Mon Sep 17 00:00:00 2001 From: Diego Lagos <92735530+diegolagospagopa@users.noreply.github.com> Date: Tue, 17 Jan 2023 15:52:57 +0100 Subject: [PATCH] feat: Postgres flexible migration from v2 (#35) * azurerm_monitor_diagnostic_setting added all category * better doc for migration * fix migration generci and all --- docs/MIGRATION_FROM_V2.md | 21 +++++++++------ docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md | 26 +++++++++++++++++++ .../02_monitor_flexible.tf | 25 +++++++++++++++--- postgres_flexible_server/README.md | 17 +++++++++--- virtual_network/README.md | 2 +- 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/docs/MIGRATION_FROM_V2.md b/docs/MIGRATION_FROM_V2.md index 61cc8dbe..559e64e6 100644 --- a/docs/MIGRATION_FROM_V2.md +++ b/docs/MIGRATION_FROM_V2.md @@ -2,11 +2,16 @@ -| module | status | note | -|-------- |--------|-------| -| storage | ok | read migration guide | -| cosmosdb | ok | read migration guide | -| subnet | ok | read migration guide | -| vnet | ok | read migration guide | -| vpn | ok | read migration guide | -| kubernetes_cluster | ok | state import mandatory + read migration guide | +| module | status | note | +|-------- |--------|-------| +| storage-account | ok | read migration guide | +| cosmosdb | ok | read migration guide | +| subnet | ok | read migration guide | +| vnet | ok | read migration guide | +| vpn | ok | read migration guide | +| postgresql-flexible | ok | read migration guide | +| postgresql-server | ok | read migration guide | +| app-gateway | ok | read migration guide | +| cdn | ok | read migration guide | +| jwt-keys | ok | read migration guide | +| kubernetes_cluster | ok | state import mandatory + read migration guide | diff --git a/docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md b/docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md index 5f5b1a9b..73ae1b42 100644 --- a/docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md +++ b/docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md @@ -26,4 +26,30 @@ This resource will be recreated, because the azurerm_log_analytics_workspace is ### azurerm_api_management_custom_domain +Attributes changed + * `proxy` -> `gateway` + +### azurerm_monitor_diagnostic_setting + +Some time you need to re-import this kind of resource. And the import don't go well. + +Because following the import instruction, the resource ID to import is wrong. + +For example with something like this + +```ts +2021-09-08T09:50:34.362+0200 [WARN] ValidateProviderConfig from "provider[\"registry.terraform.io/hashicorp/azurerm\"]" changed the config value, but that value is unused +azurerm_monitor_diagnostic_setting.resource_health_alert: Importing from ID "subscriptions/************************/providers/microsoft.insights/diagnosticSettings/Resource health diagnostics develop"... +azurerm_monitor_diagnostic_setting.resource_health_alert: Import prepared! + Prepared azurerm_monitor_diagnostic_setting for import +azurerm_monitor_diagnostic_setting.resource_health_alert: Refreshing state... [id=subscriptions/************************/providers/microsoft.insights/diagnosticSettings/Resource health diagnostics develop] +╷ +│ Error: Expected the Monitor Diagnostics ID to be in the format `{resourceId}|{name}` but got 1 segments +``` + +The correct id is like this `{resourceId}|{name}` for example `/subscriptions/ac17914c-79bf-48fa-831e-1359ef74c1d5/resourceGroups/dvopla-d-postgres-dbs-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/dvopla-d-public-pgflex|LogSecurity` + +```sh +sh terraform.sh import dev 'module.postgres_flexible_server_public[0].azurerm_monitor_diagnostic_setting.this[0]' '/subscriptions/ac17914c-79bf-48fa-831e-1359ef74c1d5/resourceGroups/dvopla-d-postgres-dbs-rg/providers/Microsoft.DBforPostgreSQL/flexibleServers/dvopla-d-public-pgflex|LogSecurity' +``` diff --git a/postgres_flexible_server/02_monitor_flexible.tf b/postgres_flexible_server/02_monitor_flexible.tf index 7a3d2c84..ca6bbd23 100644 --- a/postgres_flexible_server/02_monitor_flexible.tf +++ b/postgres_flexible_server/02_monitor_flexible.tf @@ -46,9 +46,28 @@ resource "azurerm_monitor_diagnostic_setting" "this" { enabled = true retention_policy { - enabled = true - days = 365 - } + days = 365 + enabled = true + } + } + + log { + category = "FSPGPGBouncer" + enabled = false + + retention_policy { + days = 0 + enabled = false + } + } + log { + category = "PiiOBpgbouncerlog" + enabled = false + + retention_policy { + days = 0 + enabled = false + } } metric { diff --git a/postgres_flexible_server/README.md b/postgres_flexible_server/README.md index 4b23288b..94372758 100644 --- a/postgres_flexible_server/README.md +++ b/postgres_flexible_server/README.md @@ -16,7 +16,7 @@ Module that allows the creation of a postgres flexible. ## Limits and constraints -* **HA** and **pg bouncer** is not avaible for B series machines +* **HA** and **pg bouncer** is not avaible for `B series` machines ## Metrics @@ -186,7 +186,7 @@ pgflex_public_ha_config = { high_availability_enabled = false standby_availability_zone = 3 } -```` +``` ### Module definition (Public Mode) @@ -375,7 +375,6 @@ data "azurerm_key_vault_secret" "pgres_flex_admin_pwd" { key_vault_id = data.azurerm_key_vault.kv.id } -#------------------------------------------------- resource "azurerm_resource_group" "postgres_dbs" { name = "${local.project}-postgres-dbs-rg" location = var.location @@ -480,6 +479,18 @@ module "postgres_flexible_server_private" { } ``` +## Migration from v2 + +### 🔥 re-import the resource azurerm_monitor_diagnostic_setting + +Is possible that you need to re-import this resource + +```ts +module.postgres_flexible_server_public[0].azurerm_monitor_diagnostic_setting.this[0] +``` + +See [Generic resorce migration](../docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md) + ## Requirements diff --git a/virtual_network/README.md b/virtual_network/README.md index 4b1621e7..943bdaab 100644 --- a/virtual_network/README.md +++ b/virtual_network/README.md @@ -17,7 +17,7 @@ module "vnet" { } ``` -## How to migrate from v2 +## Migration from v2 Due to possible drift in state is possible that you need to delete the state for this resource and re-import