-
Notifications
You must be signed in to change notification settings - Fork 731
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:
|
@alex-frankel +1. This is a frequent use case for us. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+100 from my company |
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. |
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? |
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: