简体   繁体   中英

Changing Azure PostgreSQL flexible server configuration with Bicep

Because of our app's requirements, we want to increase the PostgreSQL database property max_connections to allow for more connections. We are using Azure Bicep for deployment.

resource dbServer 'Microsoft.DBforPostgreSQL/flexibleServers@2021-06-01' = {
  name: serverName
  location: location
  sku: {
    name: 'Standard_B1ms'
    tier: 'Burstable'
  }
  properties: {
    createMode: 'Default'
    version: '13'
    administratorLogin: administratorLogin
    administratorLoginPassword: administratorLoginPassword
    storage: {
      storageSizeGB: 32
    }
    backup: {
      backupRetentionDays: 7
      geoRedundantBackup: 'Disabled'
    }
  }

  resource allowAzureAccess 'firewallRules' = {
    name: 'AllowAccessFromAzure'
    properties: {
      startIpAddress: '0.0.0.0'
      endIpAddress: '0.0.0.0'
    }
  }
}

resource dbServerMaxConnections 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2021-06-01' = {
  parent: dbServer
  name: 'max_connections'
  properties: {
    value: '100'
    source: 'user-override'
  }
}

This deployment sometimes works but often fails in the configuration step complaining about a conflict.

失败

Without the configuration step, deployment always succeeds. Any idea what the problem could be?

I was able to reproduce but the error message wasn't really helpful.

Both AllowAccessFromAzure and max_connections resources have an implicit dependency on the server creation. Once the server is created, these resources creation/update will be triggered in parallel and will try to update the server at the same time hence the error.

By adding an explicit dependsOn on the max_connections resource, it will force the creation/update to be done sequentially:

resource dbServer 'Microsoft.DBforPostgreSQL/flexibleServers@2021-06-01' = {
  name: serverName
  ...

  resource allowAzureAccess 'firewallRules' = {
    name: 'AllowAccessFromAzure'
    properties: {
      startIpAddress: '0.0.0.0'
      endIpAddress: '0.0.0.0'
    }
  }

  resource dbServerMaxConnections 'configurations' = {
    name: 'max_connections'
    properties: {
      value: '100'
      source: 'user-override'
    }
    dependsOn:[
      allowAzureAccess
    ]
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM