Search code examples
powershellazuredsc

Bootstrap DSC extension for a Azure Arm template


I have a ARM template which executes a Desired State Configuration extension in order to install and configure IIS. However I need to install and configure some areas which require me to already have other tools installed.

arm template

{
        "name": "Microsoft.Powershell.DSC",
        "properties": {
            "publisher": "Microsoft.Powershell",
            "type": "DSC",
            "typeHandlerVersion": "2.20",
            "autoUpgradeMinorVersion": true,
            "forceUpdateTag":"v.4.2",                                   
            "settings": {                                       
                "wmfVersion": "latest",
                "configuration": {
                    "url": "[concat(variables('dscArtifactsLocation'), '/', variables('dscExtensionArchiveFolder'),'/IISInstall.ps1.zip')]",
                    "script": "IISInstall.ps1",
                    "function": "IISInstall"
                },
                "configurationArguments": {
                    "nodeName": "localhost"
                }
            },
            "protectedSettings": {
                "configurationUrlSasToken": "?TOKEN"
            }
        }
    }

IISInstall.ps1

   Node $nodeName
    { 
        WindowsFeature IIS 
        { 
            Ensure = "Present" 
            Name = "Web-Server"                       
        } 

        WindowsFeature AspNet45
        {
            Ensure = "Present"
            Name= "Web-Asp-Net45"
        }
    }

for example i want to be able to use xWebAdministration but this requires me to have installed it first before i can call

Import-DscResource -ModuleName xWebAdministration

Additionally I need to Install IISUrlRewrite v2, the plan is to use chocolately but this also needs installing before I can use it to install programs. Is it possible to "bootstrap" the DSC execution?


Solution

  • It seems this this functionality isn't currently supported as scaleset extensions run in parallel. possibly the preferred option is to implement the bootstrap in a powershell script run via a custom script extension

    You could create several seperate powershell scripts stored in blobstorage and call them seperated with && here is an example for adding a new HDD to a scaleset instance via powershell before deploying dotnet.core.

    { "name": "[concat(variables('vmNodeTypeAppName'),'_InitializeVM')]", "properties": { "publisher": "Microsoft.Compute", "settings": { "fileUris": ["https://dot.net/v1/dotnet-install.ps1"] }, "typeHandlerVersion": "1.8", "autoUpgradeMinorVersion": true, "protectedSettings": { "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -Command \"Get-Disk | Where partitionstyle -eq 'raw' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -DriveLetter F -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel DataDisk -Confirm:$false\" && powershell.exe -ExecutionPolicy Unrestricted -File dotnet-install.ps1 -SharedRuntime" }, "type": "CustomScriptExtension" } }