问题描述
我是新来的。希望有人可以帮助我。
我正在使用New-AzResourceGroupDeployment cmdlet通过Azure臂模板部署基本的networkInterface(作为测试)。我正在使用json模板文件和json参数文件:
createNic.json 和 createNic.parameters.json
从我的PC本地引用两个json文件时,我能够成功传递NicName参数,并使用NicName创建networkInterfaces。
像这样:
我想通过使用存储Blob SAS令牌存储和引用来自我的Azure Blob存储的两个json文件来部署networkInterfaces。
只要不包含
,我的powershell部署代码就可以正常工作-NicName'My-Test-Nic'
我的New-AzResourceGroupDeployment cmdlet中的参数。当我这样做时,会收到以下错误消息:
New-AzResourceGroupDeployment:找不到与参数名称“ NicName”匹配的参数
我还通过将SAS令牌和URL粘贴到浏览器中来验证它们是否可以访问。
如果我不包括'-NicName'参数。 networkInterface使用模板json文件中的默认值在我的测试资源组中成功创建了
。我的Powershell部署代码:
$secret = (Get-AzkeyvaultSecret -VaultName 'xxxx-xxx-key-vault' -Name 'xxstorageaccount').SecretValueText
$StorageContext = New-AzStorageContext -StorageAccountName 'xxstorageaccount' -StorageAccountKey $secret
$templateuri = New-AzStorageBlobSASToken `
-Container 'json-container-templates' `
-Context $StorageContext `
-Blob 'createNic.json' `
-Permission rw `
-ExpiryTime (Get-Date).AddHours(2.0) -FullUri
Write-Host 'templateuri'
$templateuri
$TemplateParameterUri = New-AzStorageBlobSASToken `
-Container 'json-container-templates' `
-Context $StorageContext `
-Blob 'createNic.parameters.json' `
-Permission rw `
-ExpiryTime (Get-Date).AddHours(2.0) -FullUri
Write-Host 'TemplateParameterUri'
$TemplateParameterUri
New-AzResourceGroupDeployment `
-Name 'CreateNic' `
-ResourceGroupName 'TestRG' `
-TemplateUri $templateuri `
-TemplateParameterUri $TemplateParameterUri `
-NicName 'My-Test-Nic'
我的createNic Json代码:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
"NicName": {
"type": "String"
},"virtualNetworks_xx_xxx_VNET_externalid": {
"type": "String"
}
},"variables": {},"resources": [
{
"type": "Microsoft.Network/networkInterfaces","apiVersion": "2020-05-01","name": "[parameters('NicName')]","location": "northcentralus","tags": {
"displayName": "VM-Nic"
},"properties": {
"ipConfigurations": [
{
"name": "ipconfig1","properties": {
"privateIPAddress": "10.150.16.36","privateIPAllocationMethod": "Dynamic","subnet": {
"id": "[concat(parameters('virtualNetworks_xx_xxx_VNET_externalid'),'/subnets/xxx-xx-Pool')]"
},"primary": true,"privateIPAddressversion": "IPv4"
}
}
],"dnsSettings": {
"dnsServers": []
},"enableAcceleratednetworking": false,"enableIPForwarding": false
}
}
]
}
我的createNic参数Json代码:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#","parameters": {
"NicName": {
"value": "My-Test-Nic"
},"virtualNetworks_xx_xxx_VNET_externalid": {
"value": "/subscriptions/xxx-xxx-xxx-xxx-xx/resourceGroups/xx-xxx-Networking/providers/Microsoft.Network/virtualNetworks/xx-xxx-VNET"
}
}
}
解决方法
如果您查看here,则可以看到PowerShell的代码段,其中Author传递了自定义参数。
$paramObject = @{
'webAppName' = 'AdbPluralsightWebApp'
'sqlDbName' = 'webappdb'
}
$parameters = @{
'Name' = 'ContosoWebAppDeployment'
'ResourceGroupName' = 'ContosoWebApp'
'TemplateFile' = 'C:\\armtemplate.json'
'TemplateParameterObject' = $paramObject
'Verbose' = $true
}
New-AzResourceGroupDeployment @parameters