1

Is it possible to apply multiple DSC configurations to one vm through Azure Resource Manager?

Currently I am using something like this:

    {
      "apiVersion": "2015-06-15",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', variables('vm_name'))]"
      ],
      "location": "[resourceGroup().location]",
      "name": "DSCSetup",
      "properties": {
        "publisher": "Microsoft.Powershell",
        "type": "DSC",
        "typeHandlerVersion": "2.20",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "modulesUrl": "[concat('https://', variables('sa_name'), '.blob.core.windows.net/.../dsc.ps1.zip')]",
          "configurationFunction": "dsc.ps1\\Main",
          "properties": {
            "MachineName": "[variables('vm_name')]",
            "UserName": "[parameters('vm_user')]"
          }
        },
        "protectedSettings": {}
      },
      "type": "extensions"
    }

If not, can you merge multiple DSCs automatically?

Scenario is:

  • Have multiple DSCs
  • One DSC for IIS + ASP.Net
  • One DSC to create Site1
  • Another DSC to create Site2
  • In Dev deploy Site1 and Site2 to one machine
  • In Production deploy to seperate machines, maybe even in Availability Sets ...
  • (Be prepared to use seperate containers in the future)
david
  • 859
  • 1
  • 13
  • 23

2 Answers2

3

There are some approaches to this, one simple and useful that I use is Nested Configurations to mix all DSC configurations to a single one.

You are creating Configurations without any specific node. Then create Configurations with nodes that group needed configurations.

This simple example may serve as a guide about what I'm talking about. See [MS doc]]1 for more details.

Configuration WindowsUpdate
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Service ModulesInstaller {
        Name = "TrustedInstaller"
        DisplayName = "Windows Modules Installer"
        StartupType = "Disabled"
        State = "Stopped"
    }

}

Configuration ServerManager
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Registry DoNotOpenServerManagerAtLogon {
        Ensure = "Present"
        Key = "HKLM:\SOFTWARE\Microsoft\ServerManager"
        ValueName = "DoNotOpenServerManagerAtLogon"
        ValueData = 1
        DependsOn = "[Registry]NoAutoUpdate"
    }       
}


Configuration VMConfig
{
    Node localhost
    {
        WindowsUpdate NestedConfig1 {}
        
        ServerManager NestedConfig2 {}
    }
}

With this approach it is easy for me on each DSC extension to call for the machine entry Configuration that is just a composition of the configuration I want to apply.

"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.20",
"configuration": {
    "url": "[concat(parameters('_artifactsLocation'), '/Configuration.zip')]",
    "script": "Configuration.ps1",
    "function": "VMConfig"
}

Another approach will be to execute multiple ARM DSC extensions to the same machine. The trick here is to use the same name always as only one DSC extension can be executed.

The caveat with this approach is that the previous configuration on the machine is overwritten. From the functional perspective the result may be the same but if you want the DSC local manager to correct wrong configuration it will be possible only for the latest one.

guillem
  • 2,768
  • 2
  • 30
  • 44
  • Did you mean to call `VMConfig` instead of `FrontEndVM`? There is no `FrontEndVM` configuration to call in your example. – NightOwl888 Oct 30 '20 at 15:52
  • FrontEndVM was a function that references all the required resources for one server, I copied this example from a complex setting I used and I referenced the wrong function. Thanks for catching this – guillem Oct 31 '20 at 21:34
1

DSC only allows for a single configuration at the moment, so if you deployed 2 DSC extensions to the same VM (I'm not sure it will actually work) the second config would overwrite the first.

You could probably stack DSC and CustomScript but since DSC can run script, I'm not sure why you'd ever need to do that...

What's your scenario?

bmoore-msft
  • 8,376
  • 20
  • 22
  • I wanted to seperate the DSCs by "Features", so one would be IIS + ASP.NET, next will create the IIS website. Then I could reuse the same IIS + ASP.NET DSC for two VMs and simply extend them for the two IIS websites. Btw: It is not allowed to apply multiple DSC extensions, that I tried ... – david Nov 17 '16 at 06:47
  • Hmmm... I'd like to understand your scenario a bit more, I think it makes sense, though having trouble wrapping my head around it. If you're up for a chat, please email me - bmoore @ microsoft... – bmoore-msft Nov 17 '16 at 14:58