Dynamic resouce list possible to create Azure VMs?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 9 months ago.

  • Author
    Posts
  • #22740
    Profile photo of Thomas Mehl
    Thomas Mehl
    Participant

    Hi Folks,

    I have a DSC question that we are stuck with. We are dealing with a script that will need to handle a flexible list of VMs (many different possible environment configurations possible) that we need to create on Azure. We are using DSC to create the machines. The issue you guys probably have run into at some point is that when you create machines on Azure, you actually implement a resource on “localhost”, so you only have one single mof file. When you need more than one machine, you need to something that is not pretty: repeat the resources and have reoccurring properties in the one localhost node such as ServiceName1 ServiceName2 etc.

    It would be great however to be able to handle this dynamic and hence I was trying to get this to work:

    param(
    [Parameter(Mandatory,ValueFromPipeline)][string]$AllVMFileName,
    [Parameter(Mandatory,ValueFromPipeline)][PSCredential]$CredentialsToSetInsideVM
    )

    Import-Module xAzure

    Configuration cAeroAzureProvisioning
    {

    $AllVMs = get-content $AllVMFileName

    Node $AllNodes.Where{$_.NodeName -eq 'localhost'}.NodeName
    {
    $index = 0
    foreach ($vm in $AllVMs)
    {
    $index += 1
    $xAzureSubscriptionResource = 'AzureSubscriptionResource{0}' -f $index
    $xAzureStorageAccountResource = 'AzureStorageAccountResource{0}' -f $index
    $xAzureServiceResource = 'AzureServiceResource{0}' -f $index
    $xAzureVMResource = 'AzureVMResource${0}' -f $index

    xAzureSubscription $xAzureSubscriptionResource
    {
    Ensure = 'Present'
    AzureSubscriptionName = $Node.AzureSubscriptionName
    AzurePublishSettingsFile = $Node.PublishingSettingsFile
    }

    xAzureStorageAccount $xAzureStorageAccountResource
    {
    Ensure = 'Present'
    AffinityGroup = $vm.AffinityGroup
    StorageAccountName = $vm.StorageAccountName
    }

    xAzureService $xAzureServiceResource
    {
    Ensure = 'Present'
    AffinityGroup = $vm.AffinityGroup
    ServiceName = $vm.ServiceName
    }

    xAzureVM $xAzureVMResource
    {
    Ensure = 'Present'
    ImageName = $Node.ImageName
    Name = $vm.Name
    ServiceName = $vm.ServiceName
    StorageAccountName = $vm.StorageAccountName
    Credential = $CredentialsToSetInsideVM
    InstanceSize = $vm.InstanceSize
    Windows = $true
    }
    }
    }
    }

    The script starts looping and I can see that it would actually be creating a very long mof file with all machines in it, but it fails complaining that I have duplicate resource names.

    So somehow it does not recognize my dynamically generated resource names. I need to say that I am a PowerShell beginner, so It could be something simple, or I am trying something that is not possible.

    Any Ideas?

  • #22771
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Offhand, I don't think it "likes" dynamic resource names – I don't think the logic supports that. I'd have to dig into the script module to confirm, though.

    But... I'm not positive you need to do all this. The MOF that's produced as the result of the configuration script doesn't contain the computer name. The only reason you input a computer name to the configuration script, basically, is to establish the filename. I'm off the top of my head here, and I may be mixing v4 and v5, but there shouldn't be anything wrong in producing one MOF and just sending it to multiple machines, if that's what you're doing.

    Or is it that you're trying to feed in variable data for each machine, and produce what amounts to a unique MOF per host? Keep in mind you don't HAVE to write a configuration script. You only need a MOF. If you're not getting the flexibility you need from the configuration language, you could produce the MOF in other ways.

You must be logged in to reply to this topic.