Azure / bicep-registry-modules

Bicep registry modules
MIT License
498 stars 347 forks source link

[AVM Module Issue]: Azure SQL Server with an Elastic Pool and a Database #3547

Closed gsuttie closed 1 week ago

gsuttie commented 1 week ago

Check for previous/existing GitHub issues

Issue Type?

I'm not sure

Module Name

avm/res/sql/server

(Optional) Module Version

latest

Description

How can you define an Azure SQK Server with a secondary database and an elastic pool al lin the same block. It allows you to create databaes[] and elasticPools[], but how do you add the database to the elastic pool using just one script block?

(Optional) Correlation Id

No response

microsoft-github-policy-service[bot] commented 1 week ago

[!IMPORTANT] The "Needs: Triage :mag:" label must be removed once the triage process is complete!

[!TIP] For additional guidance on how to triage this issue/PR, see the BRM Issue Triage documentation.

avm-team-linter[bot] commented 1 week ago

@gsuttie, thanks for submitting this issue for the avm/res/sql/server module!

[!IMPORTANT] A member of the @Azure/avm-res-sql-server-module-owners-bicep or @Azure/avm-res-sql-server-module-contributors-bicep team will review it soon!

peterbud commented 1 week ago

Hi @gsuttie , have you checked the README file, specifically at the large parameter set example: https://github.com/Azure/bicep-registry-modules/blob/main/avm/res/sql/server/README.md#example-5-using-large-parameter-set

Or do you have something else where you have an issue with? Could you provide a specific example maybe?

gsuttie commented 1 week ago

Hi @peterbud yeah that refers to elasticPoolId: '' with databases[] - whats the id of the Elastic Pool then?

peterbud commented 1 week ago

That is the resourceId of the Elastic Pool resource. Good example could be the test bicep file in the repo: https://github.com/Azure/bicep-registry-modules/blob/main/avm/res/sql/server/tests/e2e/max/main.test.bicep

First the elastic pool is defined in the server deployment:

...
    elasticPools: [
      {
        name: '${namePrefix}-${serviceShort}-ep-001'
        skuName: 'GP_Gen5'
        skuTier: 'GeneralPurpose'
        skuCapacity: 10
      }
    ]

And then at the database it is referred with the full resourceId:

...
databases: [
      {
        name: '${namePrefix}-${serviceShort}db-001'
        elasticPoolId: '${resourceGroup.id}/providers/Microsoft.Sql/servers/${namePrefix}-${serviceShort}/elasticPools/${namePrefix}-${serviceShort}-ep-001'
}]

HTH

gsuttie commented 1 week ago

How come the elasticPoolId starts with ${resourceGroup.Id} - seems a bit odd.

gsuttie commented 1 week ago

So if i only had this Bicep, I want to create a SQL Server, Database and Elastic pool in one block of code as below, is this possible?

module sqlServer 'br/public:avm/res/sql/server:0.8.0' = if (deploySQLServer) {
  scope: resourceGroup(workloadsResourceGroupArray[4].name)
  name: 'sqlServer-${environmentName}'
  params: {
    name: sqlServerName
    administratorLogin: sqlAdministratorLogin
    administratorLoginPassword: keyVault.getSecret(config.kvSQLPassword)
    managedIdentities: {
      systemAssigned: false
      userAssignedResourceIds: [
        managedIdentity.id
      ]
    }
    primaryUserAssignedIdentityId: managedIdentity.id
    location: location
    tags: tags
    databases: [
      {
        name: 'demodbserveruksouthgregor'
        maxSizeBytes: 2147483648
        skuName: 'GP_Gen5_2'
        skuTier: 'GeneralPurpose'
        skuFamily: 'Gen5'
        zoneRedundant: false
        capacity: 2
        elasticPoolName: elasticPoolName
        //elasticPoolId: '${resourceGroup.id}/providers/Microsoft.Sql/servers/${sqlServerName}/elasticPools/${elasticPoolName}-ep-001'
        elasticPoolId: '<what goes here?>
      }
    ]
    elasticPools: [
      {
        maxSizeBytes: 34359738368
        name: elasticPoolName
        perDatabaseSettings: {
            minCapacity: 0
            maxCapacity: 2
        }
        skuCapacity: 2
        skuName: 'GP_Gen5'
        skuTier: 'GeneralPurpose'
        zoneRedundant: false
        maintenanceConfigurationId: '/subscriptions/${subscriptionId}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default'
      }
    ]
  }
}
peterbud commented 1 week ago

Few observations:

peterbud commented 1 week ago

Closing now, if it's needed we can re-open.