Azure / Azure/PSDocs.Azure

Correct way to work with default values when using PSDocs and PSRule

Open
#221 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
67
Forks
27
PR merge metrics
No merged PRs in 30d

Description

**Description of the issue**

Not sure should this be an issue on PSRule or PSDocs side but I'm testing out both PSRule and PSDocs but have come to an issue how to deal with parameter default values. I'm using Bicep with PSRule and before used in PSDocs it's built to JSON. I have a separate parameters file.

For an example I have parameter **adminUsername** which is set in the Bicep file like this:
```
@description('Username for the Virtual Machine.')
param adminUsername string = 'placeholder'
```
And in the parameters file:
```
"adminUsername": {
"value": "adminUser"
},
```
This way PSRule works ok but in the PSDocs stage this parameter is set as Optional

If I remove the default value from the Bicep and set it like this:
```
@description('Username for the Virtual Machine.')
param adminUsername string
```
The PSRule fails with error
```
##[error]Failed to expand bicep source '/home/vsts/work/1/s/main.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '/home/vsts/work/1/s/main.bicep' was not valid. An error occurred evaluating expression '[parameters('adminUsername')]' line 448. The parameter named 'adminUsername' was not set or a defaultValue was defined."
```
So what would be the correct way to set these values for both PSRule and PSDocs to work?
**To reproduce**

Steps to reproduce the issue:

- Remove default value from the Bicep template

**Expected behaviour**

- Value should be coming from the parameters file and set as required in the PSDocs.

**Error output**
```
##[error]Failed to expand bicep source '/home/vsts/work/1/s/main.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '/home/vsts/work/1/s/main.bicep' was not valid. An error occurred evaluating expression '[parameters('adminUsername')]' line 448. The parameter named 'adminUsername' was not set or a defaultValue was defined."

```

**Module in use and version:**

- Module: PSDocs.Azure
- Version: **0.3.0]**

Captured output from `$PSVersionTable`:

```text
Name Value
---- -----
PSVersion 7.2.7
PSEdition Core
GitCommitId 7.2.7
OS Linux 5.15.0-1024-azure #30-Ubuntu SMP Wed Nov …
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

```

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.