Dynamic loop to create a kv-access policy #2728
-
Consider the following template where I create two web apps with a system managed identity.
Now I would like to reference the
So I can rewrite it to the following, which works, but is static.
Is there a more dynamic way to create the access policy? Edit:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It appears that you cannot iterate over the object itself, however you can still iterate of the array of Then reference the other array app object via the index. resource kv 'Microsoft.KeyVault/vaults@2019-09-01' = {
name: 'kv-bicep-dev'
location: location
properties: {
tenantId: tenantId
sku: {
name: 'standard'
family: 'A'
}
accessPolicies: [for (app, i) in names : {
tenantId: tenantId
objectId: apps[i].identity.principalId
permissions: {
secrets: [
'all'
]
}
}]
}
} or adding more info to the array to make it an object... just for demonstration. notice
param names array = [
{
name: 'app-bicep-dev0'
secrets: [
'all'
]
}
{
name: 'app-bicep-dev1'
secrets: [
'all'
]
}
]
resource apps 'Microsoft.Web/sites@2020-12-01' = [for name in names: {
name: name.name
location: location
kind: 'app,linux,container'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: plan.id
}
}]
resource kv 'Microsoft.KeyVault/vaults@2019-09-01' = {
name: 'kv-bicep-dev'
location: location
properties: {
tenantId: tenantId
sku: {
name: 'standard'
family: 'A'
}
accessPolicies: [for (app, i) in names: {
tenantId: tenantId
objectId: apps[i].identity.principalId
permissions: {
secrets: app.secrets
}
}]
}
} |
Beta Was this translation helpful? Give feedback.
It appears that you cannot iterate over the object itself, however you can still iterate of the array of
names
that you used to create apps.Then reference the other array app object via the index.
or adding more info to the array to make it an object... just for demon…