はじめに
そりゃそうだろうと言うのはありつつ、とりあえず試してみました。
以下、どのようにダメだったのかのログです。
チュートリアル をなぞります。
Bicep とは
こちら。
Bicep とは (プレビュー)
環境
- Azure Stack Hub 2005
- Azure CLI 2.23.0
- profile: 2019-03-01-hybrid
bash-5.1# az version
{
"azure-cli": "2.23.0",
"azure-cli-core": "2.23.0",
"azure-cli-telemetry": "1.0.6",
"extensions": {}
}
bash-5.1# az cloud list --query "[?name=='AzureStackUser']" --output table
Name Profile IsActive
-------------- ----------------- ----------
AzureStackUser 2019-03-01-hybrid True
Bicep ファイル
azuredeploy.bicep
resource stg 'Microsoft.Storage/storageAccounts@2017-10-01' = {
name: 'bicepstorage20210515'
location: 'tokyo'
sku: {
name: 'Standard_LRS'
}
kind: 'Storage'
properties: {
supportsHttpsTrafficOnly: true
}
}
チュートリアル に記載されているサンプルから、API バージョンと location, kind を環境に合わせて変更しています。
デプロイ
bash-5.1# az deployment group create --resource-group bicep --template-file azuredeploy.bicep
InvalidTemplate - 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.'.
期待通り(?)、エラーになりました。
テンプレートのバージョンがサポートされていないようです。
Bicep ファイルから ARM Template に変換
確認する為に ARM Template に変換してみます。
bash-5.1# az bicep build --file azuredeploy.bicep --outfile azuredeploy.json
以下の json が得られます。Azure Stack Hub が対応していないバージョンであることが確認できます。
azuredeploy.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.539.46024",
"templateHash": "5924258605635955393"
}
},
"functions": [],
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-10-01",
"name": "bicepstorage20210515",
"location": "tokyo",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
これをデプロイしてみます。
bash-5.1# az deployment group create --resource-group bicep --template-file azuredeploy.json
InvalidTemplate - 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.'.
Bicep ファイルからデプロイした時と同じエラーメッセージが返されました。
$schema 要素で定義されている ARM Template のバージョンを、Azure Stack Hub の対応バージョンに変更します。
azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
(省略)
}
これはデプロイできました!
bash-5.1# az deployment group create --resource-group bicep --template-file azuredeploy.json
{\ Finished ..
(省略)
}
おわりに
Azure Stack Hub で Bicep ファイルから直接デプロイする事はできませんでした。
エラーメッセージから、コンパイルされた ARM Template のバージョンが新しく、Azure Stack Hub が対応していない事が原因だと推測されます。