在ARM模板中使用Powershell传递参数并使用秘密值的解决方法如下:
secretValue
,用于存储秘密值。"parameters": {
"secretValue": {
"type": "securestring"
}
}
New-AzDeployment
命令来部署ARM模板,并传递参数。在传递秘密值参数时,需要使用ConvertTo-SecureString
函数将明文转换为安全字符串。$secretValue = "mysecretpassword" | ConvertTo-SecureString -AsPlainText -Force
New-AzDeployment -Name "exampleDeployment" `
-Location "eastus" `
-TemplateFile "path/to/template.json" `
-TemplateParameterObject @{
"secretValue" = $secretValue
}
parameters('secretValue')
来引用传递的参数,并进行相应的操作。例如,可以将秘密值传递给虚拟机的密码参数。"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"name": "myVM",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "18.04-LTS",
"version": "latest"
}
},
"osProfile": {
"computerName": "myVM",
"adminUsername": "adminuser",
"adminPassword": "[parameters('secretValue')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', 'myNIC')]"
}
]
}
}
}
]
通过以上步骤,你可以在ARM模板中使用Powershell传递参数并使用秘密值。这样可以更加安全地管理和传递敏感信息。