Развертывание виртуальной машины Azure с помощью DSC - передача параметра в конфигурацию

Я работаю над своим первым проектом шаблона AzureRM / DSC, настраивая шаблоны развертывания Azure, найденные здесь: https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-automation-dsc

В рамках этого я модифицировал WindowsIISServerConfig.ps1, добавив некоторые функции Windows и возможность загружать сертификат и устанавливать его. Проблема в том, что я не знаю, как передать учетные данные для сертификата в эту конфигурацию.

Вот мой код ... как передать параметр $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
    }

}

person blizz    schedule 06.06.2019    source источник


Ответы (2)


Если вы используете шаблоны, вы можете следовать этот пример. Короче говоря, вам нужно создать учетную переменную:

    {
      "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')]"
      }
    },

и ссылаться на него при компиляции он автоматически получит значение переменной, если вы сделаете this в коде:

$domainCreds = Get-AutomationPSCredential -Name 'domainCreds'

Я думаю, что в качестве альтернативы вы можете просто передать их в поле properties.parameters (description), подождите, вы говорите об учетных данных, я не уверен, что они поддерживаются.

person 4c74356b41    schedule 06.06.2019

Ваше решение кажется довольно надежным, основанным на официальном репозитории CertificateDsc: https://github.com/PowerShell/CertificateDsc/blob/dev/Examples/Resources/PfxImport/2-PfxImport_InstallPFX_Config.ps1

Были ли у вас какие-нибудь ошибки при запуске этого?

person ald4ri    schedule 06.06.2019