Azure PostgreSQL Flexible Server using Bicep

In this blog post I show you how to create a new Azure PostgreSQL Flexible server using Bicep, the single server will be no longer at the start of 2024 so many of you will need to migrate to the flexible offering.

Azure PostgreSQL Flexible Server is a fully managed, cloud-based PostgreSQL database service that provides the ability to scale compute and storage resources independently, making it more flexible and cost-effective than other Azure PostgreSQL offerings.

As always I try to make use of the following GitHub repository this is where I go to make use of the hundreds of already written Bicep scripts which I can make use of very quickly.

I start by cloning the repository then lifting the files I need to make what ever I need to deploy work, in this case I want the following folder(s)

I store the files in a modules folder.

// Azure PostgreSQL Server details

param administratorLogin string = 'postgresqladmin'
param skuName string = 'Standard_D4s_v3'
param tier string = 'GeneralPurpose'
param availabilityZonestring string = '1'
param backupRetentionDays int = 20
param geoRedundantBackup string = 'Enabled'
param highAvailability string = 'SameZone'
param storageSizeGB int = 1024
param version string = '14'
param servername string = 'gregorspostgresql'

@description('Deploy an Azure PostgreSQL Server')
module createPostgresFlexibleServer 'modules/psqlflexibleServer_modules/deploy.bicep' = {
  scope: resourceGroup(dataTierRg)
  name: 'createPostgresFlexibleServer'
  params: {
    administratorLogin: administratorLogin
    administratorLoginPassword: administratorLoginPassword
    name: servername
    skuName: skuName 
    tier: tier 
    location: location
    availabilityZone: availabilityZonestring 
    backupRetentionDays: backupRetentionDays 
    geoRedundantBackup: geoRedundantBackup
    highAvailability: highAvailability
    storageSizeGB: storageSizeGB 
    version: version 

To run this I run a very small PowerShell script, that contains the following:-
$deploymentID = (New-Guid).Guid
$location = 'westeurope'

az deployment sub create `
        --name $deploymentID `
        --location $location `
        --template-file ./main-deployment-1.bicep `
        --parameters location=$location  `
        --confirm-with-what-if `
        --output none

And this will deploy an Azure PostgreSQL Flexible server and you can change the parameters as you like.

If you have questions reach out to me here in the comments below or on twitter.

Don’t forget to subscribe to myYouTube Channel.