From 43930ed7758d2514e2e1777c164a6ff0c378f2f4 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 26 Feb 2025 23:15:30 +0100 Subject: [PATCH 1/4] fix(infra): ensure we set az for primary in postgresql --- .azure/infrastructure/main.bicep | 2 ++ .azure/infrastructure/prod.bicepparam | 1 + .azure/infrastructure/staging.bicepparam | 1 + .azure/infrastructure/test.bicepparam | 1 + .azure/infrastructure/yt01.bicepparam | 1 + .azure/modules/postgreSql/create.bicep | 4 ++++ 6 files changed, 10 insertions(+) diff --git a/.azure/infrastructure/main.bicep b/.azure/infrastructure/main.bicep index 096748627..8cde5aeaf 100644 --- a/.azure/infrastructure/main.bicep +++ b/.azure/infrastructure/main.bicep @@ -64,6 +64,7 @@ param postgresConfiguration { enableQueryPerformanceInsight: bool enableHighAvailability: bool backupRetentionDays: int + availabilityZone: string } import { Sku as ServiceBusSku } from '../modules/serviceBus/main.bicep' @@ -218,6 +219,7 @@ module postgresql '../modules/postgreSql/create.bicep' = { vnetId: vnet.outputs.virtualNetworkId enableHighAvailability: postgresConfiguration.enableHighAvailability backupRetentionDays: postgresConfiguration.backupRetentionDays + availabilityZone: postgresConfiguration.availabilityZone tags: tags } } diff --git a/.azure/infrastructure/prod.bicepparam b/.azure/infrastructure/prod.bicepparam index 07815201c..34d294539 100644 --- a/.azure/infrastructure/prod.bicepparam +++ b/.azure/infrastructure/prod.bicepparam @@ -38,6 +38,7 @@ param postgresConfiguration = { enableQueryPerformanceInsight: false enableHighAvailability: true backupRetentionDays: 32 + availabilityZone: '3' } param redisSku = { diff --git a/.azure/infrastructure/staging.bicepparam b/.azure/infrastructure/staging.bicepparam index b26f4e734..77d375906 100644 --- a/.azure/infrastructure/staging.bicepparam +++ b/.azure/infrastructure/staging.bicepparam @@ -38,6 +38,7 @@ param postgresConfiguration = { enableQueryPerformanceInsight: true enableHighAvailability: false backupRetentionDays: 7 + availabilityZone: '2' } param redisSku = { diff --git a/.azure/infrastructure/test.bicepparam b/.azure/infrastructure/test.bicepparam index e10879b2a..05a5c8e1f 100644 --- a/.azure/infrastructure/test.bicepparam +++ b/.azure/infrastructure/test.bicepparam @@ -38,6 +38,7 @@ param postgresConfiguration = { enableQueryPerformanceInsight: true enableHighAvailability: false backupRetentionDays: 7 + availabilityZone: '1' } param redisSku = { diff --git a/.azure/infrastructure/yt01.bicepparam b/.azure/infrastructure/yt01.bicepparam index d6ff89c22..d4c879356 100644 --- a/.azure/infrastructure/yt01.bicepparam +++ b/.azure/infrastructure/yt01.bicepparam @@ -40,6 +40,7 @@ param postgresConfiguration = { enableQueryPerformanceInsight: true enableHighAvailability: false backupRetentionDays: 7 + availabilityZone: '1' } param redisSku = { diff --git a/.azure/modules/postgreSql/create.bicep b/.azure/modules/postgreSql/create.bicep index 6da40a10f..ccfa598c9 100644 --- a/.azure/modules/postgreSql/create.bicep +++ b/.azure/modules/postgreSql/create.bicep @@ -55,6 +55,9 @@ param appInsightWorkspaceName string @description('Enable high availability') param enableHighAvailability bool +@description('The availability zone for the PostgreSQL primary server') +param availabilityZone string + @description('The number of days to retain backups. If not specified, the default value of 7 days will be used.') @minValue(7) @maxValue(35) @@ -123,6 +126,7 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2024-08-01' = { delegatedSubnetResourceId: subnetId privateDnsZoneArmResourceId: privateDnsZone.outputs.id } + availabilityZone: availabilityZone highAvailability: highAvailabilityConfig } sku: sku From f22f90f88ccf936f3942d2cb471f5de4888ab9ea Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Thu, 27 Feb 2025 11:20:04 +0100 Subject: [PATCH 2/4] cleanup --- .azure/infrastructure/main.bicep | 5 +++-- .azure/infrastructure/prod.bicepparam | 5 ++++- .azure/infrastructure/staging.bicepparam | 1 - .azure/infrastructure/test.bicepparam | 1 - .azure/infrastructure/yt01.bicepparam | 1 - .azure/modules/postgreSql/create.bicep | 17 +++++++++-------- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.azure/infrastructure/main.bicep b/.azure/infrastructure/main.bicep index 8cde5aeaf..0f42fed81 100644 --- a/.azure/infrastructure/main.bicep +++ b/.azure/infrastructure/main.bicep @@ -56,13 +56,14 @@ param appInsightsSku AppInsightsSku import { Sku as PostgresSku } from '../modules/postgreSql/create.bicep' import { StorageConfiguration as PostgresStorageConfig } from '../modules/postgreSql/create.bicep' +import { HighAvailabilityConfiguration as PostgresHighAvailabilityConfig } from '../modules/postgreSql/create.bicep' param postgresConfiguration { sku: PostgresSku storage: PostgresStorageConfig enableIndexTuning: bool enableQueryPerformanceInsight: bool - enableHighAvailability: bool + highAvailability: PostgresHighAvailabilityConfig? backupRetentionDays: int availabilityZone: string } @@ -217,7 +218,7 @@ module postgresql '../modules/postgreSql/create.bicep' = { enableQueryPerformanceInsight: postgresConfiguration.enableQueryPerformanceInsight subnetId: vnet.outputs.postgresqlSubnetId vnetId: vnet.outputs.virtualNetworkId - enableHighAvailability: postgresConfiguration.enableHighAvailability + highAvailability: postgresConfiguration.?highAvailability backupRetentionDays: postgresConfiguration.backupRetentionDays availabilityZone: postgresConfiguration.availabilityZone tags: tags diff --git a/.azure/infrastructure/prod.bicepparam b/.azure/infrastructure/prod.bicepparam index 34d294539..67ebdd2ed 100644 --- a/.azure/infrastructure/prod.bicepparam +++ b/.azure/infrastructure/prod.bicepparam @@ -36,7 +36,10 @@ param postgresConfiguration = { } enableIndexTuning: false enableQueryPerformanceInsight: false - enableHighAvailability: true + highAvailability: { + mode: 'ZoneRedundant' + standbyAvailabilityZone: '2' + } backupRetentionDays: 32 availabilityZone: '3' } diff --git a/.azure/infrastructure/staging.bicepparam b/.azure/infrastructure/staging.bicepparam index 77d375906..74354ccf5 100644 --- a/.azure/infrastructure/staging.bicepparam +++ b/.azure/infrastructure/staging.bicepparam @@ -36,7 +36,6 @@ param postgresConfiguration = { } enableIndexTuning: true enableQueryPerformanceInsight: true - enableHighAvailability: false backupRetentionDays: 7 availabilityZone: '2' } diff --git a/.azure/infrastructure/test.bicepparam b/.azure/infrastructure/test.bicepparam index 05a5c8e1f..0dd913c06 100644 --- a/.azure/infrastructure/test.bicepparam +++ b/.azure/infrastructure/test.bicepparam @@ -36,7 +36,6 @@ param postgresConfiguration = { } enableIndexTuning: false enableQueryPerformanceInsight: true - enableHighAvailability: false backupRetentionDays: 7 availabilityZone: '1' } diff --git a/.azure/infrastructure/yt01.bicepparam b/.azure/infrastructure/yt01.bicepparam index d4c879356..1ce85effc 100644 --- a/.azure/infrastructure/yt01.bicepparam +++ b/.azure/infrastructure/yt01.bicepparam @@ -38,7 +38,6 @@ param postgresConfiguration = { } enableIndexTuning: true enableQueryPerformanceInsight: true - enableHighAvailability: false backupRetentionDays: 7 availabilityZone: '1' } diff --git a/.azure/modules/postgreSql/create.bicep b/.azure/modules/postgreSql/create.bicep index ccfa598c9..3d415976e 100644 --- a/.azure/modules/postgreSql/create.bicep +++ b/.azure/modules/postgreSql/create.bicep @@ -52,8 +52,14 @@ param enableIndexTuning bool @description('The name of the Application Insights workspace') param appInsightWorkspaceName string -@description('Enable high availability') -param enableHighAvailability bool +@export() +type HighAvailabilityConfiguration = { + mode: 'ZoneRedundant' + standbyAvailabilityZone: string +} + +@description('High availability configuration for the PostgreSQL server') +param highAvailability HighAvailabilityConfiguration? @description('The availability zone for the PostgreSQL primary server') param availabilityZone string @@ -97,11 +103,6 @@ module privateDnsZone '../privateDnsZone/main.bicep' = { } } -var highAvailabilityConfig = enableHighAvailability ? { - mode: 'ZoneRedundant' - standbyAvailabilityZone: '2' -} : null - resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2024-08-01' = { name: postgresServerName location: location @@ -127,7 +128,7 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2024-08-01' = { privateDnsZoneArmResourceId: privateDnsZone.outputs.id } availabilityZone: availabilityZone - highAvailability: highAvailabilityConfig + highAvailability: highAvailability } sku: sku resource database 'databases' = { From 7105eba44efe933b98e872bac66b6e1c7611aefd Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Thu, 27 Feb 2025 11:20:23 +0100 Subject: [PATCH 3/4] cleanup --- .azure/modules/postgreSql/create.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/modules/postgreSql/create.bicep b/.azure/modules/postgreSql/create.bicep index 3d415976e..2be06cce7 100644 --- a/.azure/modules/postgreSql/create.bicep +++ b/.azure/modules/postgreSql/create.bicep @@ -64,7 +64,7 @@ param highAvailability HighAvailabilityConfiguration? @description('The availability zone for the PostgreSQL primary server') param availabilityZone string -@description('The number of days to retain backups. If not specified, the default value of 7 days will be used.') +@description('The number of days to retain backups.') @minValue(7) @maxValue(35) param backupRetentionDays int From 7342992b9e545d3c495ff631218db533539c2221 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Thu, 27 Feb 2025 11:21:44 +0100 Subject: [PATCH 4/4] cleanup --- .azure/modules/postgreSql/create.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/modules/postgreSql/create.bicep b/.azure/modules/postgreSql/create.bicep index 2be06cce7..4730bc0e9 100644 --- a/.azure/modules/postgreSql/create.bicep +++ b/.azure/modules/postgreSql/create.bicep @@ -54,7 +54,7 @@ param appInsightWorkspaceName string @export() type HighAvailabilityConfiguration = { - mode: 'ZoneRedundant' + mode: 'ZoneRedundant' | 'SameZone' | 'Disabled' standbyAvailabilityZone: string }