Parameterized Bicep variables imports #15404
-
In Bicep, variables can be defined as result of parameters param connector string
param maxReplicas int
var resourceNames = [for i in range(1, maxReplicas): 'resource-${connector}-${i}']
Bicep also supports // main.bicep
import * as vars from './variables' with {
suffix: connector
count: maxReplicas
}
param maxReplicas int
param string connector
resource myFoo 'My.Namespace/resource@2023-11-01' = [for name in vars.resourceNames: {
name: name
properties: {}
}] The variables file could be defined as // We use a new proposed keyword `input` since this is a compile time feature
input number = 1
input suffix
@export()
var resourceNames = [for i in range(1, maxReplicas): 'resource-${connector}-${i}'] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Personally I feel it would needlessly complicate compile time imports with little added value. Maybe it's just that the example is too simple but from what I see, user defined functions already fill that gap and this example is the equivalent of doing: imported file: @export()
func getResourceNames(maxReplicas int, connector string) array => map(range(1, maxReplicas), i => 'resource-${connector}-${i}') main.bicep: import * as vars from './variables.bicep'
param maxReplicas int
param connector string
resource myFoo 'My.Namespace/resource@2023-11-01' = [for name in vars.getResourceNames(maxReplicas, connector): {
name: name
properties: {}
}] |
Beta Was this translation helpful? Give feedback.
Personally I feel it would needlessly complicate compile time imports with little added value.
Maybe it's just that the example is too simple but from what I see, user defined functions already fill that gap and this example is the equivalent of doing:
imported file:
main.bicep: