Azure / bicep

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

loadTextContent() - support variable or parameter as input #3816

Open slavizh opened 3 years ago

slavizh commented 3 years ago

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.

var alertRules = {
  memoryLow: {
    description: empty(bastionHostMonitoring.alertRules.memoryLow.descriptionFilePath) ? loadTextContent('alert-descriptions/memory-low.txt') : loadTextContent(bastionHostMonitoring.alertRules.memoryLow.descriptionFilePath)
  }
}
nayanshah commented 5 months ago

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 currently supported way for making this work involves duplicating loadTextContent calls which gets annoying if additional logic is needed like in #10112. This violates Goal-4 i.e. "Code re-use should not require any 'copy/paste'-ing".

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

woeterman94 commented 3 months ago

Any update on this? I'd love to be able to do: value: loadTextContent('policies/${environmentName}.xml')

corwestermaniddink commented 2 months ago

+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)

bpwc commented 2 months ago

+1 seriously? this is a deal breaking limitation