Can I loop over existing resources and extract a property? #5009
-
Hi, I want to create an array where the values are extracted from existing resources. var envVars = [
'BASE_FRONT_END_URL'
'AZURE_VOLUME_BASE_URL'
]
resource values 'Microsoft.AppConfiguration/configurationStores/keyValues@2021-03-01-preview' existing = [for name in envVars: {
name: '${configStore}/${name}'
}]
var out= [for (env, i) in envVars: {
name: env
value: values[i].properties.value
}] fails with the error: Any ideas if/how I can accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Looks like an issue with our variable replacement logic. ARM has strict rules on when runtime values can be used in variables (and other locations), which is what you are being affected. In Bicep we do some magic to remove the variable in the generated template and "hardcode" the variable value wherever it is used. For some reason that is not happening here. @miqm / @anthony-c-martin -- can you take a look and see if we should convert this to an issue? The workaround would be to not use a variable and move this code to wherever you plan to consume the variable. For example, if I want to output this value, this seems to work: var envVars = [
'BASE_FRONT_END_URL'
'AZURE_VOLUME_BASE_URL'
]
var configStore = 'config-store-name'
resource values 'Microsoft.AppConfiguration/configurationStores/keyValues@2021-03-01-preview' existing = [for name in envVars: {
name: '${configStore}/${name}'
}]
output out array = [for (env, i) in envVars: {
name: env
value: values[i].properties.value
}] |
Beta Was this translation helpful? Give feedback.
Looks like an issue with our variable replacement logic. ARM has strict rules on when runtime values can be used in variables (and other locations), which is what you are being affected. In Bicep we do some magic to remove the variable in the generated template and "hardcode" the variable value wherever it is used. For some reason that is not happening here. @miqm / @anthony-c-martin -- can you take a look and see if we should convert this to an issue?
The workaround would be to not use a variable and move this code to wherever you plan to consume the variable. For example, if I want to output this value, this seems to work: