Skip to content

Commit

Permalink
feat: Postgres flexible migration from v2 (#35)
Browse files Browse the repository at this point in the history
* azurerm_monitor_diagnostic_setting added all category

* better doc for migration

* fix migration generci and all
  • Loading branch information
diegolagospagopa authored Jan 17, 2023
1 parent 3d90769 commit d3540ea
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
21 changes: 13 additions & 8 deletions docs/MIGRATION_FROM_V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

<https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/3.0-upgrade-guide>

| 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 |
26 changes: 26 additions & 0 deletions docs/MIGRATION_GUIDE_GENERIC_RESOURCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```
25 changes: 22 additions & 3 deletions postgres_flexible_server/02_monitor_flexible.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions postgres_flexible_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -186,7 +186,7 @@ pgflex_public_ha_config = {
high_availability_enabled = false
standby_availability_zone = 3
}
````
```
### Module definition (Public Mode)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
<!-- markdownlint-disable -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
Expand Down
2 changes: 1 addition & 1 deletion virtual_network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d3540ea

Please sign in to comment.