I think the most flexible way of using Azure DSC is keeping the configurations generic with composite configurations that are added to your Modules directory in the Azure Automation Account. Then defining your environment with a master configuration (eg - WebServerRole gets IIS config, base server, etc./App server gets base server, application config, etc./ and so forth). Then I can deploy those configurations to any machine regardless of their server name.
If you’re using Azure templates for the build of the environment, it’s even easier that way. I let my template handle the naming of the systems based on parameterized inputs from my user, and then use complex variables to make the decisions on how the systems should be named. All I care about at that point is what role my server is, and then assign a configuration to it. Like so:
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2016-04-30-preview",
"copy": {
"count": "[variables('VMConfigReference').webServer.instanceCount]",
"name": "webServerConfig"
},
"name": "[concat(variables('VMConfigReference').webServer.Name,0,copyIndex(1),'/webServerConfig')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines',concat(variables('VMConfigReference').webServer.Name,0,copyIndex(1)))]",
"[resourceId('Microsoft.Compute/virtualMachines/extensions',concat(variables('VMConfigReference').webServer.Name,0,copyIndex(1)),'OMSExtension')]"
],
"location": "[resourceGroup().Location]",
"properties": {
"type": "DSC",
"publisher": "Microsoft.Powershell",
"typeHandlerVersion": "[variables('dscLocalConfigurationManager').dscExtensionVersion]",
"settings": {
"modulesUrl": "[variables('dscLocalConfigurationManager').modulesURI]",
"configurationFunction": "[variables('dscLocalConfigurationManager').configurationFunction]",
"Properties": [
{
"Name": "RegistrationKey",
"Value": {
"UserName": "PLACEHOLDER_DONOTUSE",
"Password": "PrivateSettingsRef:registrationKeyPrivate"
},
"TypeName": "System.Management.Automation.PSCredential"
},
{
"Name": "RegistrationUrl",
"Value": "[parameters('automationRegistrationUrl')]",
"TypeName": "System.String"
},
{
"Name": "NodeConfigurationName",
"Value": "CompositeConfig.webserver",
"TypeName": "System.String"
},
{
"Name": "ConfigurationMode",
"Value": "[variables('dscLocalConfigurationManager').configurationMode]",
"TypeName": "System.String"
},
{
"Name": "RebootNodeIfNeeded",
"Value": "[variables('dscLocalConfigurationManager').rebootNodeIfNeeded]",
"TypeName": "System.Boolean"
},
{
"Name": "ActionAfterReboot",
"Value": "[variables('dscLocalConfigurationManager').actionAfterReboot]",
"TypeName": "System.String"
},
{
"Name": "AllowModuleOverwrite",
"Value": "[variables('dscLocalConfigurationManager').allowModuleOverwrite]",
"TypeName": "System.Boolean"
}
],
"wmfVersion": "5.1"
},
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"Items": {
"registrationKeyPrivate": "[parameters('automationRegistrationKey')]"
}
}
}
},
I can’t tell you what the machine name will be at runtime, but I know it’s a webserver and will be getting my webserver configuration from Azure Automation DSC once it comes up.