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}'] |
Answered by
GABRIELNGBTUC
Oct 28, 2024
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: {}
}] |
0 replies
Answer selected by
nonsocode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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:
main.bicep: