从arm模板将凭据传递给DSC脚本

时间:2017-02-28 17:01:58

标签: azure azure-resource-manager dsc 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.".

据我所知,我的格式是正确的。我错过了什么?感谢

1 个答案:

答案 0 :(得分:2)

似乎函数尝试使用导致问题的参数。所以请尝试检查ps1文件中使用SQLSAAdminAuthCreds的函数。我不能重复您提到的问题。我为它做了一个演示,以下是我的详细步骤。

1.准备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.从Azure门户下载ARM模板和参数。

enter image description here

enter image description here   enter image description here   enter image description here

4.编辑模板和参数文件

enter image description here

  1. 尝试使用VS或Powershell部署ARM模板

  2. 从Azure门户或输出中检查它。

  3. enter image description here