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?