Skip to content
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

Create Extendable Bicep Params File Article #14865

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Requires `extensibility` to be enabled. If enabled, users are able to fetch the
The provider definitions also support aliasing via `bicepconfig.json` similar to [`moduleAliases`](https://learn.microsoft.com/azure/azure-resource-manager/bicep/bicep-config-modules#aliases-for-modules). For example `provider 'br/public:[email protected]' as az`.

### `extendableParamFiles`
Enables the ability to extend bicepparam files from other bicepparam files.
Enables the ability to extend bicepparam files from other bicepparam files. For more information, see [Extendable Bicep Params Files](./experimental/extendable-param-files.md).

### `extensibility`
Allows Bicep to use a provider model to deploy non-ARM resources. Currently, we support Kubernetes provider ([Bicep extensibility Kubernetes provider](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-extensibility-kubernetes-provider)) and Microsoft Graph provider ([Bicep templates for Microsoft Graph](https://aka.ms/graphbicep)).
Expand Down
90 changes: 90 additions & 0 deletions docs/experimental/extendable-param-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Using the Extendable Bicep Parameters Feature (Experimental!)
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved

## What is it?

Extendable Bicep Parameter Files is a feature that allows you to extend `.bicepparam` files from another `.bicepparam` file in order to reuse parameters across multiple deployments.
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved

When using extendable bicep parameter files, you will have a main `.bicepparam` file that can be consumed by multiple extended `.bicepparam` files.

## Using
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved

`main.bicep` This is your main bicep file, which will define your parameters for deployment.

```bicep
param namePrefix string
param location string
param symbolicName string
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved
```

`root.bicepparam` This is your main bicepparam file, which can be reused by multiple extended .bicepparam files and in multiple deployments.
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am the only one, but to me root.bicepparam file is the one being extended, not leaf.bicepparam. So when we say "can be reused by multiple extended .bicepparam files", I get confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the way I see it is that the root connects to multiple leaves - so the root can be reused multiple times into several different leaf files, which I think is also how Engin views it - should we ask the team?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I'm the only one with this perspective, it's fine to leave it as is


```bicep
using none

param namePrefix = 'share'
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved
param location = 'westus'
```

`leaf.bicepparam` This is your extended bicepparam file, which will refer to one main.bicep file and one main .bicepparam file. Any parameter value in this file will override all previous values.

```bicep
using 'main.bicep'

extends 'root.bicepparam'

param namePrefix = 'extend'
param symbolicName = 'test'
```

Resolved Values
| Param | Value |
| -- | -- |
| namePrefix | `'extend'` |
| location | `'westus'` |
| symbolicName | `'test'` |

**Note**: As `foo` is defined in both `root.bicepparam` and `leaf.bicepparam` files, any parameter values in the **`leaf.bicepparam`** file will override the values of the parameter in **both** the `main.bicep` and `root.bicepparam` files.
stephaniezyen marked this conversation as resolved.
Show resolved Hide resolved

alex-frankel marked this conversation as resolved.
Show resolved Hide resolved
## Limitations

We do not have support for:

* variables: we will not have variable support in the `root.bicepparam` file to be able to read and override values in other files
```bicep
var namePrefix = 'share'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little odd to have such specific code samples for features that don't work. I think it's ok just to describe the limitation in words.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Anthony had requested I add an explanation and example for each of these bullet points - I'll follow up with him to see if this is what he is looking for or if just a quick description is good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anthony said the examples should be helpful for users - would you be okay if I kept them in?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - fine with me

```
* import function: you will not be able to import a parameter from another file
* ```bicep
import {bar} from 'main.bicep'
```
* Multiple extends statements
```bicep
using 'main.bicep'

extends 'root1.bicepparam'
extends 'root2.biepparam'
extends 'root3.bicepparam'
```
* Ability to merge (union) parameters of type object and array
```bicep
param loc1 string = [
'westus'
'westus2'
]

param loc2 string = [
'eastus'
'eastus2'
]

union(loc1, loc2)
```
* user-defined functions and user-defined types
```bicep
type namePrefix = 'extend'
func outputName(name string) => 'Hi ${name}!'
```

## Raising bugs or feature requests

Please raise bug reports or feature requests under [Bicep Issues](https://github.com/Azure/bicep/issues) as usual.
Loading