-
Notifications
You must be signed in to change notification settings - Fork 756
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
Shared Variables for Bicep Files #893
Comments
Makes sense. Not the same, but related to #471 |
What kind of feedback are you looking for? |
I actually had this same thought initially as it's what Terraform has; however, the more I thought about it the more I struggled to find a solution where this would adhere to best practice. What I mean by that is what would be put in a variable file that wouldn't normally (should) be passed in as a paramter via a deployment process? Tags was the only thought that came to mind as there is a strong use case to reuse tags across all modules and components being created but again that is something that could be passed in at deployment. However to optimize a module for reuse most of the specifics could be passed in at deployment or defined in the main.bicep file. If using static variable reference I'd argue first why use a file vs the build in variable declaration process? Also defining variables inside the .bicep file provides for more flexibility to dynamically assign values based on coditions/concatenation. |
I like this suggestion. I have come across a situation where this would be helpful - when deploying an APIM instance into a VNet, there are a lot of NSG rules that need to be set up to keep APIM happy. It would be really good to have these declared as a variable in another file to keep them together, and then my main NSG template would refer to that plus add any custom rules I need as well. |
Linking to related discussion #1601. |
Similarly, while I do appreciate the defined "contracts" that modules provide, I have a lot of boilerplate in my main bicep that looks like this like I have in terraform as well.
This is not a major deal, but maybe a module property "inherit: true" that would match up variables to same-named parameters would be great to cut down on the boilerplate. |
The concept of shared variables or Global variables where we can define something once is indeed very much needed. Just take the simple case of a name prefix that you use for your resources or Tags. I hate having to define them over and over again. Having the ability to declare a global variable, define it once and reference wherever needed is priceless. |
@glloyd2010f By this you would be building templates with embeded variables, right? @alex-frankel Is there any way to actually compose and build parameter files, so that the templates stay simle and flexible? Example:
Is it something like this currently possible for parameter files? Or am I missing something here? We have fairly complex deployments and with json you cannot simply achieve this without building another templating layer. I was considering to use something like jsonnet or yaml and build the final parameter file. But since yaml is not native to powershell it both feels kinda wrong. Honestly this is even bigger pain than writting the tamplates in json, any cure for that? |
@johnymachine I think a similar comparison would be to the usage hiera within puppet. It would act as an imported file that can be referenced for standardized information. This way you can just grab pre-approved information and allow development teams to be more autonomous. Does that make sense? |
Not exactly, because you still can't "splat" those into modules, you still have to match parameter to parameter. |
That should be covered in #1121 right? |
@brwilkinson is this json(loadTextContent('../bicepconfig.json) updated in the Azure Bicep Documentation!? |
It's not there yet, but we are adding it shortly cc @tfitzmac / @stephaniezyen Tom, we should make sure to cover the use case of combining |
docs for loadTextContent has been published and includes an example of using json() with loadTextContent(). |
What I would like to see is following:shared.json: {
"VNetName": "${project}-${env}-vnet"
} main.bicep:
Or alternative approachshared.bicep:
main.bicep:
this is much more complicated and probably does not make any sense because of the working module system. |
Update two: I tried to offload my shared variable file generation outside of bicep: my pipeline knows what kind of replacement to do: Failed try number 1: generated one single file containing resource names for all environments: {
"test": {
"SQLServer": "xxx-test-sqlserver",
"SQLDatabase": "db1"
},
"prod": {
"SQLServer": "xxx-prod-sqlserver",
"SQLDatabase": "db1",
"VPNVNet": "xxx-vpn-prod-vnet"
},
"dev": {
"SQLServer": "xxx-dev-sqlserver",
"SQLDatabase": "db1"
}
} failed because:
intellisense on names will work only with the highest level of nesting. Nothing is suggested after typing failed number 2: I generated environment specific files containing resource naming for one environment {
"SQLServer": "xxx-prod-sqlserver",
"SQLDatabase": "db1",
"VPNVNet": "xxx-vpn-prod-vnet"
} with
failed with TLDR: Looks like all workaroundd for dynamic shared variables seems to be more or flawed or lack of features like fully working IntelliSense. Using precompiled to make try 2 might be one solution but is really hacky solution. Am I missing something or is this really this difficult to achieve? |
True. I had an issue with my local file. But sadly using dot notation for property access is effective hardcoding. Following should be used to pick up the correct set of names on deployment:
and this definitely is not resolved by IntelliSense. I did not test if this really works. Summary for this now: Pros:
Cons:
Not sure if I'm just wasting my time with experimenting workarounds. Calculating RoI for the final attempt with this kind of approach: https://dev.to/zakhenry/ensuring-accuracy-of-readme-code-snippets-525p
pros:
cons:
|
Hi glloyd2010f, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! 😄 🦾 |
Within Azure DevOps we leverage variable files so that they can shared between many pipelines/workstreams. Will Bicep have the concept of a shared variables file so that teams can just import them? Would this be just another bicep module?
An ideal solution would be a common variables setup so that we don't require a linked template or bicep module with outputs that need to be referenced. This would be extremely valuable for easy re-use. This would be in addition to any inline variables.
Rough Example...
main.bicep
var inlineVariable = 'varValue'
var sharedVariables = './fileName.bicepVars'
The text was updated successfully, but these errors were encountered: