简体   繁体   English

使用DSC进行Azure VM部署-将参数传递给配置

[英]Azure VM deployment with DSC - Passing parameter to configuration

I am working on my first AzureRM/DSC template project by customizing the Azure deployment templates found here: https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-automation-dsc 我正在通过自定义位于以下位置的Azure部署模板来处理我的第一个AzureRM / DSC模板项目: https : //github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-automation-dsc

As part of that, I modified WindowsIISServerConfig.ps1 to add some Windows features and the ability to download a certificate and install it. 作为其中的一部分,我修改了WindowsIISServerConfig.ps1以添加一些Windows功能以及下载证书和安装证书的功能。 The problem is I don't know how to pass the credential for the certificate into this configuration. 问题是我不知道如何将证书的凭据传递到此配置中。

Here is my code...how can I pass in the $certPass parameter?: 这是我的代码...如何传递$certPass参数?:

configuration WindowsIISServerConfig
{

    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $certPass
    )

    Import-DscResource -ModuleName 'xWebAdministration'
    Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'CertificateDsc'
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'    

    WindowsFeature WebServer
    {
        Ensure  = 'Present'
        Name    = 'Web-Server'
    }

    WindowsFeature WebManagement
    {
        Ensure  = 'Present'
        Name    = 'Web-Mgmt-Console'
        DependsOn = '[WindowsFeature]WebServer'
    }

    WindowsFeature WebASPNet47
    {
        Ensure  = 'Present'
        Name    = 'Web-Asp-Net45'
        DependsOn = '[WindowsFeature]WebServer'
    }

    WindowsFeature WebNetExt
    {
        Ensure  = 'Present'
        Name    = 'Web-Net-Ext45'
        DependsOn = '[WindowsFeature]WebServer'
    }

    # IIS Site Default Settings
    xWebSiteDefaults SiteDefaults
    {
        ApplyTo                 = 'Machine'
        LogFormat               = 'IIS'
        LogDirectory            = 'C:\inetpub\logs\LogFiles'
        TraceLogDirectory       = 'C:\inetpub\logs\FailedReqLogFiles'
        DefaultApplicationPool  = 'DefaultAppPool'
        AllowSubDirConfig       = 'true'
        DependsOn               = '[WindowsFeature]WebServer'
    }

    # IIS App Pool Default Settings
    xWebAppPoolDefaults PoolDefaults
    {
       ApplyTo               = 'Machine'
       ManagedRuntimeVersion = 'v4.0'
       IdentityType          = 'ApplicationPoolIdentity'
       DependsOn             = '[WindowsFeature]WebServer'
    }

    # Get SSL cert file from Azure Storage using SAS URI
    xRemoteFile CertPfx
    {
        Uri = "https://example.blob.core.windows.net/resources/cert.pfx?sp=r&st=2019-06-02T22:00:11Z&se=2019-07-03T06:00:11Z&spr=https&sv=2018-03-28&sig=xxxxxx&sr=b"
        DestinationPath = "C:\temp\cert.pfx"
    }

    # Import the PFX file which was downloaded to local path
    PfxImport ImportCertPFX
    {
        Ensure     = "Present"
        DependsOn  = "[xRemoteFile]CertPfx"
        Thumbprint = "c124bf740b256316bd756g689140d6ff3dcdd65f"
        Path       = "c:\temp\cert.pfx"
        Location   = "LocalMachine"
        Store      = "WebHosting"
        Credential = $certPass
    }

}

If you are using templates you can follow this example. 如果使用模板,则可以按照以下示例操作。 In short you need to create a credential variable: 简而言之,您需要创建一个凭证变量:

    {
      "name": "[concat(parameters('accountName'), '/', parameters('variableName')) ]",
      "type": "microsoft.automation/automationAccounts/Variables",
      "apiVersion": "2015-01-01-preview",
      "tags": { },
      "dependsOn": [ xxx ],
      "properties": {
        "isEncrypted": 0,
        "type": "[parameters('variableType')]",
        "value": "[parameters('variableValue')]"
      }
    },

and reference it when you compile it will get the variable value automatically if you do this in the code: 并在编译时引用它,如果在代码中执行此操作 ,它将自动获得变量值:

$domainCreds = Get-AutomationPSCredential -Name 'domainCreds'

I think, alternatively, you can just pass them in to the properties.parameters field ( description ), ah wait, you are talking about credentials, I'm not sure that is supported. 我认为,或者,您可以将它们传递给properties.parameters字段( description ),啊,等等,您在谈论凭据,我不确定是否支持。

You're solution seems to be pretty vaild, based on the official CertificateDsc repository: https://github.com/PowerShell/CertificateDsc/blob/dev/Examples/Resources/PfxImport/2-PfxImport_InstallPFX_Config.ps1 根据官方的CertificateDsc存储库,您的解决方案似乎无效: https : //github.com/PowerShell/CertificateDsc/blob/dev/Examples/Resources/PfxImport/2-PfxImport_InstallPFX_Config.ps1

Did you get any errors out of running this? 您从运行此程序中得到任何错误吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM