Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.24k stars 748 forks source link

for each file in a directory #3607

Open skyaddict opened 3 years ago

skyaddict commented 3 years ago

With the creation of https://github.com/Azure/bicep/issues/471 there will be the ability to load content from a file. The next logical step would be to allow for each file in a folder. The file object returned should include FullName, BaseName, parent dir. Wildcarding would also be helpful. .xls, .liquid, etc.

Potentially something like Get_ChildItem from PowerShell.

foreach ($file in Get-ChildItem '$(Pipeline.Workspace)/Infrastructure/Schemas')

Example: I create an integration account and then need to load the Maps and schemas into this integration account. I could see something like

module map 'IntegrationAccount/IntegrationAccountMap.bicep' = [for file in getFiles('integrationAccount/maps'): {  
  scope: resourceGroup()
  name: file.BaseName
  params: {
    integrationAccountName: IntegrationAccount.outputs.name
    mapName: file.BaseName
    filePath: file.FullName
    mapType: 'Liquid'
  }
}]

Today an object with each file path and name listed does the trick, however having this be more dynamic would be excellent. and avoid missing things when they get added.

scott1138 commented 3 years ago

This has a lot of use cases as parameter files can become very clunky after a few hundred lines. Our App Gateway parameters are very unwieldy so I am moving the config to Bicep and storing each application configuration in it's own json file. Then I am loading that file in the main.bicep and passing the appropriate config to the required module. It would be extremely helpful to not have 20 load statements and to continuing adding them with every new config

kamilzzz commented 7 months ago

This would be really useful in some scenarios, although one would need to be careful to not exceed the ARM deployment engine size limit when loading bunch of files from directory.

Scenarios:

mindingdata commented 6 months ago

+1 for this as it's a scenario we are also finding.

We are utilizing APIM with several different APIs and Endpoints. We currently have a Swagger + Policy file for each API, and this is loaded by using the file load capability that is now in Bicep. However, when new APIs are added, we would like to rely on folder conventions to simply load in the API as it's added, essentially removing the need for someone to edit the main bicep file each time.

nayanshah commented 6 months ago

I hit the same problem while generating AppInsights alerts using json config files. My workaround is to generate a .bicep file before the compilation step that references all the config files in the alerts directory.

Example: https://gist.github.com/nayanshah/7c86cfe6c9882c9e8133cee6ce17c9bb