Replies: 2 comments 5 replies
-
+1 on this one. Although this is possible to do now by converting the biceparam file to json and from json to PS object. The problem is that some syntax will not be converted back once you do object -> json -> biepparam. There also could be some issues in turning to object when using some of the functions in bicep like loading content, etc. |
Beta Was this translation helpful? Give feedback.
-
@brwilkinson 's previous answer mentions decompiling to JSON, then loading the resulting file. You can also skip the intermediate step and just load the parameters directly into a PowerShell object by sending the
You can then access any parameter as If you only need a single parameter, you can get it directly:
Note that |
Beta Was this translation helpful? Give feedback.
-
Is it possible to programmatically parse a bicepparam file and convert it into objects somehow. Can someone show or point me at an example? I know I can do regexp, but it is not really a "powershell" way. Point here is that if a config file contains some parameters, I want a Powershell script to be able to read it, parse it, extract some values, perform some actions, like listing some resources, and set some env vars.
AN example would be the following scenario. We have a hub resource group containing a VNET and a set of Private DNS Zones created elsewhere, so it is better not to make any assumptions on which zones area there. When we create spoke VNETs connected to the hub VNET, we need to also link all these private DNS zones. Spoke template knows nothing about hub DNS zones, and hardcoding them there as
existing
resources is not a good idea as the list might change. Current approach, perhaps, is to read the bicepparam file, which stores a name of the hub sesouce group, extract this name, let Powershell extract all DNS Zone resource IDs and pass them to the param file back through environment variables. THat makes all this more dynamic, avoiding a necessity to store whole bunch of parameters somewhere else, referencing them and so on.In general, it would be great if there were a function in bicep, which could enumerate existing resources in a resource group, filter them by a type or a name or both and return them an array. That way we can avoid hardcoding a lot of things, I believe.
Beta Was this translation helpful? Give feedback.
All reactions