-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loadTextContent() - support variable or parameter as input #3816
Comments
We cannot do this with a In theory, this should be possible with variables, but my understanding is it requires more of #444 implemented |
Very interested in this thread. The ability to load another file inside a var would open a load of options around not hardcoded 10s or 100s are variables to reference existing file to load data var manifest = json(loadTextContent('./data/manifest.json'))
var itemsArray = [ for item in manifest : {
data: json(loadTextContent('./data/${item.dataFile}'))
parameters: json(loadTextContent('./data/${item.parametersFile}'))
} In theory, this should all be available at compile time as all files are static and nothing is dynamically generated. |
I removed the string interpellation and just put the file path in the manifest file and it worked. So, I then assumed it is the interpellation causing the compile time error. But then, after three or four runs in my test environment, it’s back to the compile time error “The value must be a compile-time constant. bicep(BCP032)”
|
Interesting. No errors if there is only a single element in the manifest.json. Add additional elements and back to failure. |
Hi, I have the same error when providing more than one file location getting the "The value must be a compile-time constant." error.Please let us know how to fix this issue var stringArray = [ var policies = [for i in range(0, length(stringArray)): json(loadTextContent(stringArray[i]))] |
Repro for triage: works: var stringArray = [
'./policies/policy_1.json'
]
var policies = [for i in range(0, length(stringArray)): json(loadTextContent(stringArray[i]))] doesn't work: var stringArray = [
'./policies/policy_1.json'
'./policies/policy_2.json'
]
var policies = [for i in range(0, length(stringArray)): json(loadTextContent(stringArray[i]))] |
The reason this works is because the type of a single-item string array gets simplified down to a string literal, which the function can handle. It's not something we intentionally designed and in fact we should probably block this scenario. We are going to take a look at validating this better. |
@miqm will break out this last comment and track the fix with a separate issue |
Anyway, back to the original proposal - using parameters as arguments for loadTextContent is not possible. Parameters are evaluated during the deployment (runtime), while file loading in loadTextContent is done during compilation ( The only way I can think of to provide this functionality is to introduce a compile-time parameters (similar to C# symbols - https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation). |
Hello, would be great if we would support this and make it more general. So it will also support similar functions like loadFileAsBase64. |
Would having function that loads json from file be a solution? Mind, that vars can be runtime values, while load* functions can accept only compile-time values as arguments. |
We have the same requirement\need, we are creating role definitions and looking to pass in the json file containing the permissions. |
+1 to this. Have the same need for populating permissions from json. |
Hello @leechan-bicep , @alex-frankel A workaround for this :
May be : var policies = [for i in range(0, length(stringArray)): json(stringArray[i])] |
hey, I tried @charotAmine code, but it didn't worked for me. But I created a similar way to solve this:
|
+1 for using this to load local files for openapi specs |
I have a similar situation which appears to be a cross between this issue and #3607. In my case, I am looking to load multiple "resource configuration" files. These files may vary from deployment to deployment but will be re-usable. Depending on the specific scenario, I would like to point my Bicep configuration at a single JSON file containing a list of required "resource configuration" files, and then loop over that to load in the "resource configuration" files. I will always know the location of the first file, and the point of this is to abstract the list of other sources from the template to simplify code maintenance and D.R.Y. Take an example such as the following:
|
Adding comment for support.
I currently pull in 3 files with Global or Regional metadata.
# Read in the Rolegroups Lookup.
$RolesGroupsLookup = Get-Content -Path $Artifacts/tenants/$App/Global-Config.json | ConvertFrom-Json -Depth 10 | ForEach-Object RolesGroupsLookup
$Global.Add('RolesGroupsLookup', ($RolesGroupsLookup | ConvertTo-Json -Compress -Depth 10)) I would like to move this into the Bicep template file itself. param App string = 'LAB'
var computeGlobal = json(loadTextContent('../tenants/${App}/Global-Config.json')) Since the project can deploy to multiple subscriptions, I need to pass in the
The deployment script that I currently use for ALL deployments. Examples of the metadata files that I have-to pass in at runtime (per tenant/App) in the above script.
|
+1 please |
+1 |
This will be really a value addition! |
This is something Terraform supports so Bicep should too. It is not possible to download and deploy a certificate resource unless the path is known at deploy time. Only workaround is using a keyvault instead. Terraform:
Bicep:
|
An additional comment on this... If you test out bicepparam you can create a parameter that uses |
Good to know. I dont think a parameter file will work in my case because I want to download a secure file from Azure DevOps and read the contents in. |
@jamesSampica Bicep functions are supported in bicepparam. |
Still exploring I like that you can reference other parameters in using '../../bicep/00-ALL-SUB.bicep'
param Global = union(
loadJsonContent('Global-${Prefix}.json'), // Can reference this file based on the region I am in... clone the file, update the Prefix
loadJsonContent('Global-Global.json'),
loadJsonContent('Global-Config.json')
)
param Prefix = 'AWU3'
param Environment = 'P'
param DeploymentID = '0' I haven't completed testing all scenarios, however I believe this covers my needs from my previous comment in this thread, where I achieved the above union with PowerShell custom code. |
+1 |
+1 param aksClusterGroup string
param aksClusterName string
param aosmParametersLocation string
param aosmSchemaLocation string
param aosmSetSetFilesParametersLocation string
param artifactManifestName string
param artifactStore string
param cgsName string
param cgvName string
param cnfName string
param helmPackageName string
param helmPackageVersion string
param helmReleaseName string
param location string = resourceGroup().location
param nfdgroupName string
param nfdvNfName string
param nfdversion string
param nsdGroup string
param nsdvName string
param publisherName string
param releaseNamespace string
param resourceExists bool = false
param siteName string
param snsName string
param valuesLocation string
param valuesParam object
param yamlLocation string
//********************************************
//LOADING ALL VALUES ON allTogether
//********************************************
//var mval = loadYamlContent(valuesLocation'/'cnfName'-values.yaml') //parameters passed to helm chart
//var svals = loadJsonContent(aosmSetSetFilesParametersLocation'/'cnfName'_nf_deployment_set_parameters.json') //file with --set parameters for helm
var mval = loadYamlContent('../values.final/my_cnf-values.yaml') //parameters passed to helm chart
var svals = loadJsonContent('../aosmSetSetFilesParameters.final/my_cnf_nf_deployment_set_parameters.json') //file with --set parameters for helm
var allTogether= union(mval, svals) //joining parameters. change order of list to use correct precedence. |
I am facing the same issue while loading a script for deploymentscript bicep module. |
same here |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
Running into the error
when trying to import an API into Azure API Management based on the OpenAPI specification.
|
The currently supported way for making this work involves duplicating P.S: my workaround for this issue is generating a .bicep file before compilation which isn't ideal but gets the job done - Example: https://gist.github.com/nayanshah/7c86cfe6c9882c9e8133cee6ce17c9bb |
Any update on this? |
+3 .. really Microsoft, fix this. Almost can't believe I ran into this limitation. It's really a bugger, because this means redundancy in my Bicep modules. Bicepparam is also not working for my use-case. The use-case based upon Microsoft his own example for Azure Search setup, found here: https://github.com/Azure-Samples/azure-search-deployment-template/blob/main/bicep/setup-search-service.bicep (row 50) |
+1 |
Please lets get bicep finally mature and workable, this is one of the many things IaC like bicep should support. And while at it, make sure to get it working in bicep and bicep param files. The thing is, this has been asked three years ago. Sometimes I wonder how big the team of bicep is. Very big shortcomings like this, or the extend param feature that has been butchered or even creating a static var is not supported. We're talking about Microsoft, we're talking about bicep. Does Microsoft even care about proper DevOps? Im sure the few people working in the bicep team care a lot, but it's just insane how bad Bicep still is after all these years. the progress is so slow, and what has been put out isn't even the biggest issues we DevOps engineers face. |
The reality is the team is relatively small and age of an issue is not determinant of what gets prioritized. We would love to be able to do every feature request that has been accepted once enough time has progressed, but we don't have that luxury. I know these are not the answers people want to hear, but always want to be as transparent with you all as possible.
If we are getting our priorities wrong, we want to know that as that's what we have the power to change. Is there something we are working on now that you feel should be de-prioritized? On our Community Call tomorrow, we will be discussing what our plans are for the remainder of the semester (through 3/31). That will be a great forum to share these concerns. Regarding bicepparam, have you filed an issue to help us understand what has been "buchered"? We would definitely want to understand that better. I imagine @stephaniezyen / @polatengin would also be happy to jump on a call as they were researching the work remaining for bicepparam that must be urgently completed. |
Hi Alex, There was a bit frustration in my message after trying for days to get something simple working in bicep (just a constant value to be shared across bicepparam files). With every possible solution we come across Open reports in GitHub that have been reported years ago. This is one of them, #14656 is another regarding extended bicepparams,. In relation we have #14135 although not open for long. I did comment on the pr's we saw on extended and others as well, and seeying what was actually released felt more like a hello world example that missed the biggest requests we had with it. But not being able to actually UDT is the biggest, this is something we should be using as much as possible as it prevents run time errors. Bicep has been out for a long time. If it was a small shop that tried something new, it would have been understandable. But it just amazes me that the company who created the best developer environment with visual studio and c#/.Net, bicep seems to not get that much love. Its a shame because there is real potential, but to be honest. The more I use it the more I question if its really a smart move regarding getting a stable production ready IaC. The features like sharing vars across bicepparam files, or declaring statics, even updating keys in keyvaults Azure/bicep-types-az#1906 should be long hanging fruit. Some functions are possible in bicep files, some in bicepparam files, but to be honest why not both? For example why can i not do read environment var in bicep files but i can in bicepparam files? I'm always eagerly awaiting the community calls because i do care, but to be honest, for two years we see the date being pushed back for alpha release. Eveyr time i ask myself, what the new release date? That does make you wonder. Nothing but the best towards the team and you guys, like I said, they must care. But Microsoft also needs to start caring more about this. I'll have a look at your referred page regarding features for the community call. |
@mennolaan would you be up for having an extended call with the product group? I think you are touching on a lot of good points that we'd love to unpack with you further. Then, if you think it's a good idea, we can share the notes and any action items from the call with the community. If you're interested, send me an email at [email protected] and we will set it up. |
Is your feature request related to a problem? Please describe.
I would like for loadTextContent() to support variable or parameter as input parameter. What I would like to offer is for the end user to specify text from file or to use the default file available. Currently if I use the below syntax I get error:
The value must be a compile-time constant.bicep(BCP032)
I know that function is being used at compile time so this will probably require some other approach and even changes in template spec for supporting it there as well.
The text was updated successfully, but these errors were encountered: