Azure / Azure/bicep

Bicep & Azure Stack Hub (2008)

Open
#2,451 4 comments 3 reactions 0 assignees View on GitHub
documentation enhancement
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Azure Stack Hub version**
1.2008.23.108

**Bicep version**
Bicep CLI version 0.3.255 (589f0375df)

**PowerShell version**
5.1.17763.1007

**Az PowerShell Module version**
0.10.0-preview (required for Azure Stack Hub, though some sub-modules (e.g. az.accounts) have been updated.

**Describe the bug**
Running a Bicep template against Azure Stack Hub (2008) fails with both the Azure CLI and with PowerShell due to schema limitations or mismatch with Azure Stack Hub.

**To Reproduce Deployment Failure (PowerShell)**

* Create a simple Bicep template (such as the following) and save as `hello.bicep`
```Bicep
param yourName string
var hello = 'Hello World! - Hi'
output helloWorld string = '${hello} ${yourName}'
```

* Setup PowerShell so you are connected to the Azure Stack Hub. See the following:

[Install PowerShell Az module for Azure Stack Hub](tinyurl.com/35wmr2m6)
[Connect to Azure Stack Hub with PowerShell as a user](https://tinyurl.com/faebue8p)

* Run the following command to create an ARM template from the Bicep template

>We need to do this because of the version of PowerShell Az module required for Azure Stack Hub is old so we can't use
Bicep directly (see above).

```
bicep build C:\temp\hello.bicep
```

* This creates an ARM template `C:\Temp\hello.json` like this:

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.3.255.40792",
"templateHash": "15080053196542757413"
}
},
"parameters": {
"yourName": {
"type": "string"
}
},
"functions": [],
"variables": {
"hello": "Hello World! - Hi"
},
"resources": [],
"outputs": {
"helloWorld": {
"type": "string",
"value": "[format('{0} {1}', variables('hello'), parameters('yourName'))]"
}
}
}
```

* Run the following PowerShell to deploy the ARM template that was created:
```PowerShell
$helloSplat = @{
Name = 'HelloBicep'
ResourceGroupName = 'BicepTesting'
TemplateFile = 'C:\temp\hello.json'
YourName = 'John Doe'
}
New-AzResourceGroupDeployment @helloSplat
```
* The following error is generated

```text
New-AzResourceGroupDeployment : Deployment template validation failed: 'Template schema 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#' is not supported. Supported versions are '2014-04-01-preview,2015-01-01,2018-05-01'. Please see https://aka.ms/arm-template for usage details.'.
At line:9 char:1
+ New-AzResourceGroupDeployment @helloSplat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzResourceGroupDeployment], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
```

* Updating the line in the ARM template as follows fixes the problem with the ARM template:

From: `"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",`

To: `"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",`

> NOTE: I have not tested with other schema versions (there are several mentioned in the error text)

> NOTE: Results when using Azure CLI are similar.

> NOTE: Working with an Azure Stack Hub in an offline environment also introduces an issue with Bicep, Bicep attempts to update when it runs and fails when there is no internet access. I haven't captured exact details on this one to reproduce.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the deployment with the documented hello.bicep, generated hello.json, Azure Stack Hub, and the PowerShell command; compare the generated $schema with the versions listed in the deployment error. Check the Azure CLI result as well, and consider the offline update failure separately. Done means the generated template can deploy against the supported Azure Stack Hub schema versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.