Skip to content

Commit

Permalink
fix(infra): ensure we set az for primary in postgresql (#1973)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

We had an issue where we added HA for `prod`, but the bicep deployment
didn't go through because we need to set the primary az. Setting the
primary az to the one that it was added to when created.

## Related Issue(s)

- #164

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)
  • Loading branch information
arealmaas authored Feb 27, 2025
1 parent e6d3f2e commit b4fd665
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ 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
}

import { Sku as ServiceBusSku } from '../modules/serviceBus/main.bicep'
Expand Down Expand Up @@ -216,8 +218,9 @@ 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
}
}
Expand Down
6 changes: 5 additions & 1 deletion .azure/infrastructure/prod.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ param postgresConfiguration = {
}
enableIndexTuning: false
enableQueryPerformanceInsight: false
enableHighAvailability: true
highAvailability: {
mode: 'ZoneRedundant'
standbyAvailabilityZone: '2'
}
backupRetentionDays: 32
availabilityZone: '3'
}

param redisSku = {
Expand Down
2 changes: 1 addition & 1 deletion .azure/infrastructure/staging.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ param postgresConfiguration = {
}
enableIndexTuning: true
enableQueryPerformanceInsight: true
enableHighAvailability: false
backupRetentionDays: 7
availabilityZone: '2'
}

param redisSku = {
Expand Down
2 changes: 1 addition & 1 deletion .azure/infrastructure/test.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ param postgresConfiguration = {
}
enableIndexTuning: false
enableQueryPerformanceInsight: true
enableHighAvailability: false
backupRetentionDays: 7
availabilityZone: '1'
}

param redisSku = {
Expand Down
2 changes: 1 addition & 1 deletion .azure/infrastructure/yt01.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ param postgresConfiguration = {
}
enableIndexTuning: true
enableQueryPerformanceInsight: true
enableHighAvailability: false
backupRetentionDays: 7
availabilityZone: '1'
}

param redisSku = {
Expand Down
23 changes: 14 additions & 9 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,19 @@ 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' | 'SameZone' | 'Disabled'
standbyAvailabilityZone: string
}

@description('High availability configuration for the PostgreSQL server')
param highAvailability HighAvailabilityConfiguration?

@description('The number of days to retain backups. If not specified, the default value of 7 days will be used.')
@description('The availability zone for the PostgreSQL primary server')
param availabilityZone string

@description('The number of days to retain backups.')
@minValue(7)
@maxValue(35)
param backupRetentionDays int
Expand Down Expand Up @@ -94,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
Expand All @@ -123,7 +127,8 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2024-08-01' = {
delegatedSubnetResourceId: subnetId
privateDnsZoneArmResourceId: privateDnsZone.outputs.id
}
highAvailability: highAvailabilityConfig
availabilityZone: availabilityZone
highAvailability: highAvailability
}
sku: sku
resource database 'databases' = {
Expand Down

0 comments on commit b4fd665

Please sign in to comment.