Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.25k stars 754 forks source link

Intellisense Support for VM DSC Extension Parameters #945

Open ld0614 opened 3 years ago

ld0614 commented 3 years ago

A common requirement with Azure is to deploy a Virtual Machine and then provide a level of one-off configuration to the operating system. This is typically done through either the Custom Script Extension or the DSC Extension. The DSC extension supports configuration arguments to pass variables in at runtime. Currently in ARM (and bicep) templates it is the developers job to manually ensure that the arguments provided match up with both the parameter names and parameter types defined in the DSC Configuration. This can often lead to long retry attempts as DSC is often one of the last things to fail at deployment time.

An example Extension template would be:

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(parameters('VMName'),'/Microsoft.Powershell.DSC')]",
    "apiVersion": "2020-06-01",
    "location": "[resourceGroup().location]",
    "properties": {
      "publisher": "Microsoft.Powershell",
      "type": "DSC",
      "typeHandlerVersion": "2.77",
      "autoUpgradeMinorVersion": true,
      "settings": {
        "configuration": {
          "url": "[concat(parameters('_artifactsLocation'), '/DSC/DSC.zip')]",
          "script": "ConfigureVM.ps1",
          "function": "BasicVM"
        },
        "configurationArguments": {
            "VMName": "[parameters('VMName')]",
            "EnableVerboseLogging": false,
            "ConsoleURL": "www.test.local"
        }
      },
      "protectedSettings": {
        "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
      }
    }
  }

With associated DSC:

configuration BasicVM
{
    param
    (    
        [Parameter(mandatory = $true)]
        [string]$VMName,

        [Parameter()]
        [bool]$EnableVerboseMsiLogging = $false,

        [Parameter(Mandatory = $true)]
        [String]
        $ConsoleURL
    )

    Node localhost
    {
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
            ConfigurationMode = "ApplyOnly"
        }

        //Config Goes Here
    }
}

What I would like to see is the automatic reading of defined DSC file parameters in a similar way to the way that bicep picks up module parameters and enables IntelliSense and compile-time checking of parameters. This would also possibly enable easier support for things like PowerShell credential objects (not the most intuitive to add to an ARM Template) and possibly even warning about having a secure string as an unprotected setting.

I appreciate that this task means understanding another language (PowerShell) however I believe that querying the PowerShell Abstract Syntax Tree or relying on the parser already written for PowerShell 7 (which is also MIT licensed, Microsoft owned and written in c#) should reduce the development needed. Alternatively, I don't know about how VS Code Extensions work but would it be possible to just rely on the PowerShell extension to expose sufficient data to the bicep extension?

alex-frankel commented 3 years ago

This would be great if we could build a generic extensibility point for any non-.bicep file. We will have a chat with the powershell team to see if they have any thoughts about this. Not likely to get to this soon.