I am trying to create Azure resources like key vault using bicep and bicep parameter files. I am using DevOps Pipeline for deployment. I am reading a few parameters from variable/ variable groups in .yml, which is used as param in bip file. However, I want to read array and bicep objects from DevOps variable. Is there any way to achieve this?
Below is code snippet from .bicep file:
@description('Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge.')
param secretsPermissions array
resource keyvault 'Microsoft.KeyVault/vaults@2022-07-01' = {
---extra code---
accessPolicies: {
--extra code--
permissions: {
secrets: secretsPermissions
}
}
}
below is code from .parameters.json file:
"parameters": {
"secretsPermissions": {
"value": ["get","list"] //will prefer to get this from DevOps variable group
}
below is code from yml:
overrideParameters: -<parameter_in_bicep> "$(<variable_in_variable group>)"
i want to read these variables as bicep object and array, currently I am only able to readall values as string only. even if i write them as array or object format.
The variables under pipeline concept only have one type - 'string'.
No other types, so you need to design code by yourself.I write a python script demo in pipeline to help you get the content, add the item, update the content, remove the items of specific route in json file.
For getting and changing data from YAML file, it is similar, or you can convert the YAML to JSON and then use above code.
This python code can convert yml file to json:
Original yml file:
After processed: