Looking for an example on how to use the VirtualMa...
# general
q
Looking for an example on how to use the VirtualMachineExtension in C#, Azure Native.
Copy code
new AzureNative.Compute.VirtualMachineExtension($"{vmName}​-VMExtensions", new AzureNative.Compute.VirtualMachineExtensionArgs()
            {
                VmName = vmName,
                ResourceGroupName = resourceGroup.Name,
                AutoUpgradeMinorVersion = true,
                Publisher = "Microsoft.Powershell",
                Type = "DSC",
                TypeHandlerVersion = "2.73",
                Settings = Output.Tuple(hostPool.Name, hostPool.RegistrationInfo).Apply((tuple) =>
                {
                    return JsonConvert.SerializeObject(new
                    {
                        modulesUrl = "<https://storageblobname.blob.core.windows.net/galleryartifacts/Configuration_5-5-2021.zip>",
                        configurationFunction = "Configuration.ps1\\AddSessionHost",
                        properties = new
                        {
                            hostPoolName = tuple.Item1,
                            registrationInfoToken = tuple.Item2.Token,
                            aadJoin = false,
                        }
                    }​);
                })
            }​);
which results in this error:
error: azure-native:compute:VirtualMachineExtension resource 'somename-vm-01-VMExtensions' has a problem: 'settings' should be of type '' but got a string
although the documentation says about the settings property:
Json formatted public settings for the extension.
I verified that the string that I am using for the settings property has the exact syntax as when I export the VirtualMachineExtension from the Azure Portal. Looking documentation or an example on how to use the VirtualMachineExtension for DSC extension. Can't find an example anywhere using my Google Fu.
Found the solution. Documentation could be more clear on this topic. But this is the correct code:
Copy code
Settings = Output.Tuple(hostPool.Name, hostPool.RegistrationInfo).Apply((tuple) =>
                                            {
                                                return new Dictionary<string, object>
                                                {
                                                    { "modulesUrl", "<https://somestorageblob.blob.core.windows.net/galleryartifacts/Configuration_5-5-2021.zip>" },
                                                    { "configurationFunction", "Configuration.ps1\\AddSessionHost" },
                                                    { "properties", new Dictionary<string, object>
                                                        {
                                                            { "hostPoolName", tuple.Item1 },
                                                            { "registrationInfoToken", tuple.Item2.Token },
                                                            { "aadJoin", false },
                                                        }
                                                    }
                                                };
                                            }
                                        )
            });
🙌 1