The following CLI code will not deploy. AI says it's out of date for Azure and everything I have tried to fix it is not working. I can't complete this Bicep lesson if it won't deploy. This comes from - https://learn.microsoft.com/en-us/training/modules/build-flexible-bicep-files-conditions-loops/ - Here is the code that Learn says is correct :
@description('The Azure region into which the resources should be deployed.')
param location string
@secure()
@description('The administrator login username for the SQL server.')
param sqlServerAdministratorLogin string
@secure()
@description('The administrator login password for the SQL server.')
param sqlServerAdministratorLoginPassword string
@description('The name and tier of the SQL database SKU.')
param sqlDatabaseSku object = {
name: 'Standard'
tier: 'Standard'
}
@description('The name of the environment. This must be Development or Production.')
@allowed([
'Development'
'Production'
])
param environmentName string = 'Development'
@description('The name of the audit storage account SKU.')
param auditStorageAccountSkuName string = 'Standard_LRS'
var sqlServerName = 'teddy${location}${uniqueString(resourceGroup().id)}'
var sqlDatabaseName = 'TeddyBear'
var auditingEnabled = environmentName == 'Production'
var auditStorageAccountName = take('bearaudit${location}${uniqueString(resourceGroup().id)}', 24)
resource sqlServer 'Microsoft.Sql/servers@2024-05-01-preview' = {
name: sqlServerName
location: location
properties: {
administratorLogin: sqlServerAdministratorLogin
administratorLoginPassword: sqlServerAdministratorLoginPassword
}
}
resource sqlDatabase 'Microsoft.Sql/servers/databases@2024-05-01-preview' = {
parent: sqlServer
name: sqlDatabaseName
location: location
sku: sqlDatabaseSku
}
resource auditStorageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = if (auditingEnabled) {
name: auditStorageAccountName
location: location
sku: {
name: auditStorageAccountSkuName
}
kind: 'StorageV2'
}
resource sqlServerAudit 'Microsoft.Sql/servers/auditingSettings@2024-05-01-preview' = if (auditingEnabled) {
parent: sqlServer
name: 'default'
properties: {
state: 'Enabled'
storageEndpoint: environmentName == 'Production' ? auditStorageAccount.properties.primaryEndpoints.blob : ''
storageAccountAccessKey: environmentName == 'Production' ? auditStorageAccount.listKeys().keys[0].value : ''
}
}
Here are the 2 error codes I'm getting which won't allow it to deploy:
- The value of type "Microsoft.Storage/storageAccounts | null" may be null at the start of the deployment, which would cause this access expression (and the overall deployment with it) to fail.
- A resource of type "Microsoft.Storage/storageAccounts | null" may or may not exist when this function is called, which could cause the deployment to fail.
I have included a screen shot of where VS Code says the errors lie. AI gave me several 'fixes' which just lead to more and different error codes that still wouldn't deploy. Screenshot from 2026-05-20 12-54-26.png - Here's what I need help with:
- Is it out of date? I'm thinking so because it won't deploy and AI says it is. If not, then what am I doing wrong?
- How do I fix it if it is? AI had me running in circles, including adding ! and ?, as well as adding modules as workarounds.
- Has anyone else had the issue of Learn lessons being out of date? Is this common? I'm new to this.
Thanks in advance for any advice you can give.
This question is related to the following Learning Module