と(長期的に)人生を容易にするための試みでは十分に文書properties.templateLinkとは反対に、私は、properties.templateを使用しようとしています。前者は、child.jsonテンプレートファイルの内容をparent.jsonテンプレートにテンプレートのパラメータとして渡すことで、ドキュメントをほとんど作成していません。 Microsoft.Resources/deploymentsのためのMSのドキュメントからAzureのネストされたテンプレートの展開:使用するテンプレート要素(ないtemplateLink)のPowerShell
:私の親テンプレートで
The template content. You use this element when you want to pass the template syntax directly in the request rather than link to an existing template. It can be a JObject or well-formed JSON string. Use either the templateLink property or the template property, but not both.
、私はパラメータchildTemplates
を宣言し、properties.templateでそれを参照しています:
"parameters": {
"childTemplates": {
"type": "object",
"metadata": {
"description": "Child template"
}
}
}
other stuff...
"resources": [
{
"name": "[concat('linkedTemplate-VM-Net-',copyIndex(1))]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-06-01",
"dependsOn": [],
"copy": {
"name": "interate",
"count": "[parameters('vmQty')]"
},
"properties": {
"mode": "Incremental",
"template": "[parameters('childTemplates')]",
"parameters": {
"sharedVariables": { "value": "[variables('sharedVariables')]" },
"sharedTemplate": { "value": "[variables('sharedTemplate')]" },
"artifactsLocationSasToken": { "value": "[parameters('artifactsLocationSasToken')]" },
"adminPassword": { "value": "[parameters('adminPassword')]" },
"copyIndexValue": { "value": "[copyIndex(1)]" }
},
"debugSetting": {
"detailLevel": "both"
}
}
}
],
私はその後、子テンプレートを渡します
$TemplateFileLocation = "C:\Temp\templates\parent.json"
$JsonChildTemplate = Get-Content -Raw (Join-Path ($TemplateFileLocation | Split-Path -Parent) "nestedtemplates\child.json") | ConvertFrom-Json
$TemplateParameters = @{
childTemplates = $JsonChildTemplate
...Other parameters...
}
New-AzureRmResourceGroupDeployment -TemplateParameterObject $TemplateParameters
:
New-AzureRmResourceGroupDeployment -TemplateParameterObject
に親テンプレートを展開します
これは、次のエラーを生成します。私は$JsonChildTemplate
を見れば
Code : InvalidTemplate
Message : The nested deployment 'linkedTemplate-VM-Net-1' failed validation: 'Required property '$schema' not found in JSON. Path 'properties.template'.'.
Target :
Details :
、それは私を与える:$schema
があるよう
$schema : https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
contentVersion : 1.0.0.0
parameters : @{sharedVariables=; sharedTemplate=; vhdStorageAccountName=; artifactsLocationSasToken=; adminPassword=; copyIndexValue=}
variables : @{seqNo=[padleft(add(parameters('copyIndexValue'),3),3,'0')]; nicName=[concat('NIC-',parameters('sharedVariables').role,'-', variables('seqNo'),'-01')];
subnetRef=[parameters('sharedVariables').network.subnetRef]; ipConfigName=[concat('ipconfig-', variables('seqNo'))]}
resources : {@{apiVersion=2016-03-30; type=Microsoft.Network/networkInterfaces; name=[variables('nicName')]; location=[resourceGroup().location]; tags=; dependsOn=System.Object[];
properties=}}
outputs : @{nicObject=; vmPrivateIp=; vmNameSuffix=; vmPrivateIpArray=}
私には、それが見えます。
同じエラーで| ConvertFrom-Json
を削除してみました。上記
、私は最新のAPIのバージョンを示していますが、私はバグがあります念のために、そのような2016年9月1日のように他の人と試してみました。ソリューションのための私の検索で
は、私がGitHubの上this問題を発見しました。返信は$schema
とcontentVersion
を削除することですが、これはエラーが発生したときに飛んでいます。
Function Get-ChildTemplate
{
$TemplateFileLocation = "C:\Temp\templates\nestedtemplates\child.json"
$json = Get-Content -Raw -Path $TemplateFileLocation | ConvertFrom-Json
$NewJson = @()
$NewJson += $json.parameters
$NewJson += $json.variables
$NewJson += $json.resources
$NewJson += $json.outputs
Return $NewJson | ConvertTo-Json
}
$JsonChildTemplate = Get-ChildTemplate
$TemplateParameters = @{
childTemplates = $JsonChildTemplate
...Other parameters...
}
$JsonChildTemplate
リターン:
[
{
"sharedVariables": {
"type": "object",
"metadata": "@{description=Object of variables from master template}"
}...
私の推測では、私がNew-AzureRmResourceGroupDeployment
にchild.jsonの内容を渡して何か間違ったことを行っているということです私は次のようにこれを試してみました。それは、私がやろうとしていることを実際に行うことはできません。
P.S.
get-command New-AzureRmResourceGroupDeployment
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet New-AzureRmResourceGroupDeployment 4.1.0 AzureRM.Resources
ありがとうございました。 'json()'関数は、(私の無意味なアプローチのために)扱います。はい、私はウォルターのコメントに気づきました。彼はそれ以来、完全に異なるパラメータを参照しています。 – woter324