azure - 将凭证从arm模板传递给DSC脚本

标签 azure azure-resource-manager dsc azure-rm-template

我正在尝试从 ARM 模板部署具有 DSC 扩展的虚拟机。根据各种消息来源,甚至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.准备一个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.压缩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

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

  • 从 Azure 门户或输出中检查。

  • enter image description here

    关于azure - 将凭证从arm模板传递给DSC脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42514654/

    相关文章:

    azure - ARM - 仅当存储帐户不存在时才部署

    powershell - 无法在所需状态配置中运行节点和脚本

    Terraform DSC 配置与节点配置中的 Azure 自动化

    azure - 使用 Terraform 部署期间在 Azure VM 上安装 DSC 扩展的问题

    c# - 服务总线主题插入了相同 MessageId 的重复消息记录

    node.js - Visual Studio代码: Deploy to azure appears to work but no files seem to transfer

    azure - 从命令行创建服务器场(也称为应用程序服务计划)

    azure - 使用 Arm 模板创建资源组并部署资源并从 Visual Studio 进行部署

    Facebook 使用 Azure 服务登录并获取用户信息错误

    asp.net - Azure Web App(MVC 6)持续部署失败