How can I use the property nextVersion
from resource mlEnvironment
from my template below:
@description('The list of Azure ML workspace names to deploy environments to.')
param workspaceName string
@description('The list of environments to create. Each object should have: environmentName, environmentVersion.')
param environments array
resource mlWorkspace 'Microsoft.MachineLearningServices/workspaces@2025-06-01' existing = {
name: workspaceName
}
resource mlEnvironment 'Microsoft.MachineLearningServices/workspaces/environments@2025-07-01-preview' = [
for env in environments: if(length(environments)>0) {
parent: mlWorkspace
name: env.environmentName
properties: {
isArchived: false
}
}]
resource mlEnvironmentVersion 'Microsoft.MachineLearningServices/workspaces/environments/versions@2025-07-01-preview' = [
for (env, i) in environments: if(length(environments)>0) {
parent: mlEnvironment[i]
name: mlEnvironment[i].properties.nextVersion
properties: {
description: env.environmentDescription
condaFile: env.condaFile
osType: env.osType
isAnonymous: false
isArchived: false
image: (empty(env.environmentImage) ? null : env.environmentImage)
}
}]
If I do name: mlEnvironment[i].properties.nextVersion
from template above, I get this error:
This expression is being used in an assignment to the "name" property of the "Microsoft.MachineLearningServices/workspaces/environments/versions" type, which requires a value that can be calculated at the start of the deployment. Properties of mlEnvironment which can be calculated at the start include "apiVersion", "id", "name", "type".bicepBCP120
The value of type "Microsoft.MachineLearningServices/workspaces/environments | null" may be null at the start of the deployment, which would cause this access expression (and the overall deployment with it) to fail.bicepBCP318
I tried using user defined functions but also didn't work.
You have to use modules to achieve that. It is not possible without using modules.
main.bicep
@description('The list of Azure ML workspace names to deploy environments to.')
param workspaceName string
@description('The list of environments to create. Each object should have: environmentName, environmentVersion.')
param environments array
resource mlWorkspace 'Microsoft.MachineLearningServices/workspaces@2025-06-01' existing = {
name: workspaceName
}
resource mlEnvironment 'Microsoft.MachineLearningServices/workspaces/environments@2025-07-01-preview' = [
for env in environments: if(length(environments)>0) {
parent: mlWorkspace
name: env.environmentName
properties: {
isArchived: false
}
}]
module versions 'versions.bicep' = [for (env, i) in environments: if(length(environments)>0) {
name: 'version-${env.environmentName}-${i}'
params: {
env: env
workspaceName: workspaceName
nextVersion: mlEnvironment[i].properties.nextVersion
}
}]
versions.bicep
param env object
param workspaceName string
param nextVersion string
resource mlWorkspace 'Microsoft.MachineLearningServices/workspaces@2025-06-01' existing = {
name: workspaceName
}
resource mlEnvironment 'Microsoft.MachineLearningServices/workspaces/environments@2025-07-01-preview' = {
parent: mlWorkspace
name: env.environmentName
properties: {
isArchived: false
}
}
resource mlEnvironmentVersion 'Microsoft.MachineLearningServices/workspaces/environments/versions@2025-07-01-preview' = {
parent: mlEnvironment
name: nextVersion
properties: {
description: env.environmentDescription
condaFile: env.condaFile
osType: env.osType
isAnonymous: false
isArchived: false
image: (empty(env.environmentImage) ? null : env.environmentImage)
}
}