/// <summary> /// Create/register a new extension /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="subscription">Guid of the subscription</param> /// <param name="resourceGroupName">Resource group (name) containing the virtual machine</param> /// <param name="virtualMachineName">Name of the virtual machine to create the extension into</param> /// <param name="extensionName">Name of the extension</param> /// <param name="location">Azure data center geo location short/internal name (eg: "westus")</param> /// <param name="properties">Properties of the extension</param> /// <param name="tags">Tags (optional)</param> /// <returns>VMExtension object if successful, else NULL</returns> public static async Task <VMExtension?> Create(string bearerToken, Guid subscription, string resourceGroupName, string virtualMachineName, string extensionName, string location, VMExtensionProperties properties, Dictionary <string, string>?tags = null) { if (subscription == Guid.Empty) { throw new ArgumentNullException(nameof(subscription)); } if (string.IsNullOrWhiteSpace(resourceGroupName)) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (string.IsNullOrWhiteSpace(virtualMachineName)) { throw new ArgumentNullException(nameof(virtualMachineName)); } if (string.IsNullOrWhiteSpace(extensionName)) { throw new ArgumentNullException(nameof(extensionName)); } if (string.IsNullOrWhiteSpace(location)) { throw new ArgumentNullException(nameof(location)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // avoid carrying junk around VMExtensionProperties requestProperties = new VMExtensionProperties() { ForceUpdateMode = properties.ForceUpdateMode, InstallNewerMinorVersionIfAvailable = properties.InstallNewerMinorVersionIfAvailable, InstanceView = null, ProtectedSettings = properties.ProtectedSettings, PublisherName = properties.PublisherName, Settings = properties.Settings, Type = properties.Type, TypeHandlerVersion = properties.TypeHandlerVersion }; return(await CreateOrUpdate( bearerToken, new VMExtension() { Location = location, Name = extensionName, Properties = requestProperties, ResourceId = $"/{subscription.ToString("d")}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/extensions/{extensionName}", Tags = tags, Type = "virtualMachines/extensions" } )); }
/// <summary> /// Create/register a new extension /// </summary> /// <param name="bearerToken">Authorization bearer token</param> /// <param name="extensionName">Name of the extension</param> /// <param name="location">Azure data center geo location short/internal name (eg: "westus")</param> /// <param name="properties">Properties of the extension</param> /// <param name="tags">Tags (optional)</param> /// <returns>VMExtension object if successful, else NULL</returns> public static async Task <VMExtension?> Create(string bearerToken, string virtualMachineResourceUri, string extensionName, string location, VMExtensionProperties properties, Dictionary <string, string>?tags = null) { if (string.IsNullOrWhiteSpace(virtualMachineResourceUri)) { throw new ArgumentNullException(nameof(virtualMachineResourceUri)); } if (string.IsNullOrWhiteSpace(extensionName)) { throw new ArgumentNullException(nameof(extensionName)); } if (string.IsNullOrWhiteSpace(location)) { throw new ArgumentNullException(nameof(location)); } if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // avoid carrying junk around VMExtensionProperties requestProperties = new VMExtensionProperties() { ForceUpdateMode = properties.ForceUpdateMode, InstallNewerMinorVersionIfAvailable = properties.InstallNewerMinorVersionIfAvailable, InstanceView = null, ProtectedSettings = properties.ProtectedSettings, PublisherName = properties.PublisherName, Settings = properties.Settings, Type = properties.Type, TypeHandlerVersion = properties.TypeHandlerVersion }; return(await CreateOrUpdate( bearerToken, new VMExtension() { Location = location, Name = extensionName, Properties = requestProperties, ResourceId = virtualMachineResourceUri, Tags = tags, Type = "virtualMachines/extensions" } )); }