将凭据从 arm 模板传递给 DSC 脚本
Passing credentials to DSC script from arm template
我正在尝试使用 ARM 模板的 DSC 扩展部署 VM。根据各种消息来源,甚至 this SO question, 我正在按照正确的方式将凭据对象传递给我的脚本:
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.19",
"autoUpgradeMinorVersion": true,
"settings": {
"modulesUrl": "[concat(parameters('_artifactsLocation'), '/', variables('ConfigureRSArchiveFolder'), '/', variables('ConfigureRSArchiveFileName'), '/', parameters('_artifactsLocationSasToken'))]",
"configurationFunction": "[variables('rsConfigurationConfigurationFunction')]",
"properties": {
"SQLSAAdminAuthCreds": {
"UserName": "[parameters('SSRSvmAdminUsername')]",
"Password": "PrivateSettingsRef:SAPassword"
}
}
},
"protectedSettings": {
"Items": {
"SAPassword": "[parameters('SSRSvmAdminPassword')]"
}
}
}
但是,当我部署它时,我收到此错误消息:
Error message: "The DSC Extension received an incorrect input: The password element of
argument 'SQLSAAdminAuthCreds' to configuration 'PrepareSSRSServer' does not
match the required format. It should be as follows
{
"UserName" : "MyUserName",
"Password" : "PrivateSettingsRef:MyPassword"
}.
Please correct the input and retry executing the extension.".
据我所知,我的格式是正确的。我错过了什么?谢谢
似乎函数尝试使用导致问题的参数。因此,请尝试检查 ps1 文件中使用 SQLSAAdminAuthCreds 的函数。我无法重现您提到的问题。我做了个demo,下面是我的详细步骤。
1.Prepare 一个 ps1 文件,我从 article
获取演示代码
configuration Main
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$SQLSAAdminAuthCreds
)
Node localhost {
User LocalUserAccount
{
Username = $SQLSAAdminAuthCreds.UserName
Password = $SQLSAAdminAuthCreds
Disabled = $false
Ensure = "Present"
FullName = "Local User Account"
Description = "Local User Account"
PasswordNeverExpires = $true
}
}
}
2.Zip ps1 文件
3.Download 来自 Azure 门户的 ARM 模板和参数。
4.Edit模板和参数文件
尝试用VS或Powershell部署ARM模板
从 Azure 门户或输出中检查它。
我正在尝试使用 ARM 模板的 DSC 扩展部署 VM。根据各种消息来源,甚至 this SO question, 我正在按照正确的方式将凭据对象传递给我的脚本:
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.19",
"autoUpgradeMinorVersion": true,
"settings": {
"modulesUrl": "[concat(parameters('_artifactsLocation'), '/', variables('ConfigureRSArchiveFolder'), '/', variables('ConfigureRSArchiveFileName'), '/', parameters('_artifactsLocationSasToken'))]",
"configurationFunction": "[variables('rsConfigurationConfigurationFunction')]",
"properties": {
"SQLSAAdminAuthCreds": {
"UserName": "[parameters('SSRSvmAdminUsername')]",
"Password": "PrivateSettingsRef:SAPassword"
}
}
},
"protectedSettings": {
"Items": {
"SAPassword": "[parameters('SSRSvmAdminPassword')]"
}
}
}
但是,当我部署它时,我收到此错误消息:
Error message: "The DSC Extension received an incorrect input: The password element of
argument 'SQLSAAdminAuthCreds' to configuration 'PrepareSSRSServer' does not
match the required format. It should be as follows
{
"UserName" : "MyUserName",
"Password" : "PrivateSettingsRef:MyPassword"
}.
Please correct the input and retry executing the extension.".
据我所知,我的格式是正确的。我错过了什么?谢谢
似乎函数尝试使用导致问题的参数。因此,请尝试检查 ps1 文件中使用 SQLSAAdminAuthCreds 的函数。我无法重现您提到的问题。我做了个demo,下面是我的详细步骤。
1.Prepare 一个 ps1 文件,我从 article
获取演示代码configuration Main
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$SQLSAAdminAuthCreds
)
Node localhost {
User LocalUserAccount
{
Username = $SQLSAAdminAuthCreds.UserName
Password = $SQLSAAdminAuthCreds
Disabled = $false
Ensure = "Present"
FullName = "Local User Account"
Description = "Local User Account"
PasswordNeverExpires = $true
}
}
}
2.Zip ps1 文件
3.Download 来自 Azure 门户的 ARM 模板和参数。
4.Edit模板和参数文件
尝试用VS或Powershell部署ARM模板
从 Azure 门户或输出中检查它。