Azure / bicep

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

Bicep Build should not include unused linked templates #3838

Open dciborow opened 3 years ago

dciborow commented 3 years ago

We have a very large collection of bicep modules. In some cases, we have hard coded variables set to false, which are then based as input parameters to modules. Within that module, we will have a resource creation conditional on the variable. (Other deployment scripts may use this, as we share these resources across many solutions.

Currently, when we run "bicep build", sections are included even when they are unreachable because of hard coded variables.

Describe the solution you'd like During the build process, if variables can be determined at build time, and are found to be false, the linked arm templates that would go unused should be dropped from the arm.template.

This way, only resources that are going to be deployed are included, simplifying the final template.

dciborow commented 3 years ago

image

image

in this example, the workspace_config has provided a hard coded false for the creation of the search service. Perhaps it makes sense to include in the bicep visualization, but it should not be included in the final arm template. Now I have an additional service showing up, which is never accessible or used.

miqm commented 3 years ago

I don’t think we should remove any code even if it’s inaccessible at this point. Some users may want to edit ARM later (even you can do this via portal when re-running deployment) and there switch false to true.

maybe we could have some optimisation level flag that would remove inaccessible parts of code, but a prerequisite is #444

dciborow commented 3 years ago

@miqm this is a side effect of using a collection of common bicep templates to produce our service arm templates.

The value in the bicep template for our recommenser for example that is being compiled has constant variables, such as "include_search: false"

We do not want users to every change this value, as our recommender doesn't use search (our knowledge miner does though)

So now I have a recommender arm template, and unaccesbile sections in my arm template. When I submit my ARM to the Managed Apps team, they have rejected my submission and requested I remove all the unreachable code.

Can provide example if helpful.