Reduction in custom formulaic complexity #13987
Replies: 2 comments 1 reply
-
Well, it depends on how dynamic you want/need it I suppose. Having a local.bicepparam for working locally and having test.bicepparam, prod.bicepparam, etc. where you just switch in the pipeline gets me far for things that aren't truly dynamic. For something like a bicepconfig.json where I need a container registry unique pr environment (and you can only have one config file hence needing runtime fixing) I just put a placeholder value $ACR and execute sed pointing to a variable injected from AzDO/GH. Since Bicep works better with json you can of course wrap things accordingly (also works when using output from PowerShell/CLI):
Your yaml is possibly just a different wrapper for the same? |
Beta Was this translation helpful? Give feedback.
-
type macros = {
azureAppClientId: string
loginEndpoint: string
azureAppTenantId: string
grafanaRootUrl: string
databaseHost: string
databaseName: string
databaseUser: string
}
var replacementValues = {
azureAppClientId: azureAppClientId
loginEndpoint: environment().authentication.loginEndpoint
azureAppTenantId: azureAppTenantId
grafanaRootUrl: 'https://${containerAppName}.${appEnvironmentDefaultDomain}'
databaseHost: '${postgresServerFqdn}:5432'
databaseName: grafanaDatabaseName
databaseUser: sqlAdminUsername
}
var grafanaIni = loadYamlContent('./grafana-ini.yml')
var grafanaConfigurationItems = items(grafanaIni)
func getReplacementValue(inputString string, macros macros) string => reduce(
items(macros),
{},
(cur,macro) => union(
cur, empty(
cur
)
? {
key: inputString
value: replace(inputString, '{{${macro.key}}}', macro.value)
}
: {
key: inputString
value: replace(cur.value, '{{${macro.key}}}', macro.value)
}
)
).value
var grafanaEnvVariables = [for item in grafanaConfigurationItems: map(items(item.value), configEntry => {
name: 'GF_${toUpper(item.key)}_${toUpper(configEntry.key)}'
value: getReplacementValue(configEntry.value, replacementValues)
})] |
Beta Was this translation helpful? Give feedback.
-
So maybe I'm going about this in an entirely backwards way, which would explain why I'm finding this so challenging, but I'm trying to provide a custom yml file at the root of my repo that I then dynamically populate and provide to the container app as environment variables during deployment. Truth of the matter is this all works, I'm just trying to think outloud for potential alternatives.
The main concern I have is:
replace(replace(replace(replace(replace(replace(replace(
which... is less than optimal. Is there, perhaps, another route I'm missing?grafana-ini.yml
grafana.bicep
And variables implemented later in file:
Just brainstorming at this point. Really wish custom functions could include local variables or read in outside parameters/variables, but I know that's probably stretching Bicep beyond it's intended target.
Beta Was this translation helpful? Give feedback.
All reactions