diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs index 458e4a3106c1..51043c6f6dfd 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs @@ -278,6 +278,26 @@ public Dictionary ParseTemplateParameterFileCon return parameters; } + public Dictionary ParseTemplateParameterContent(string templateParameterContent) + { + Dictionary parameters = new Dictionary(); + + if (!string.IsNullOrEmpty(templateParameterContent)) + { + try + { + parameters = JsonConvert.DeserializeObject>(templateParameterContent); + } + catch (JsonSerializationException) + { + parameters = new Dictionary( + JsonConvert.DeserializeObject(templateParameterContent).Parameters); + } + } + + return parameters; + } + private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(string templateContent, Hashtable templateParameterObject, string templateParameterFilePath, string[] staticParameters) { RuntimeDefinedParameterDictionary dynamicParameters = new RuntimeDefinedParameterDictionary(); @@ -315,6 +335,11 @@ private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(stri var parametersFromFile = ParseTemplateParameterFileContents(templateParameterFilePath); UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromFile)); } + if (templateParameterFilePath != null && Uri.IsWellFormedUriString(templateParameterFilePath, UriKind.Absolute)) + { + var parametersFromUri = ParseTemplateParameterContent(GeneralUtilities.DownloadFile(templateParameterFilePath)); + UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromUri)); + } return dynamicParameters; } diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs index e8379a084db6..b3b090b326ed 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs @@ -329,12 +329,41 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame Deployment deployment = new Deployment { Properties = new DeploymentProperties { - Mode = deploymentMode, - Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity), - Parameters = GetDeploymentParameters(parameters.TemplateParameterObject) + Mode = deploymentMode } }; + if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute)) + { + deployment.Properties.TemplateLink = new TemplateLink + { + Uri = new Uri(parameters.TemplateFile) + }; + } + else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity)) + { + deployment.Properties.TemplateLink = new TemplateLink + { + Uri = new Uri(GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity)) + }; + } + else + { + deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile); + } + + if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute)) + { + deployment.Properties.ParametersLink = new ParametersLink + { + Uri = new Uri(parameters.ParameterUri) + }; + } + else + { + deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject); + } + return deployment; } diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs index 07585cd05981..33ceac142058 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs @@ -32,10 +32,13 @@ public abstract class ResourceWithParameterBaseCmdlet : ResourcesBaseCmdlet protected const string BaseParameterSetName = "Default"; protected const string GalleryTemplateParameterObjectParameterSetName = "Deployment via Gallery and template parameters object"; protected const string GalleryTemplateParameterFileParameterSetName = "Deployment via Gallery and template parameters file"; + protected const string GalleryTemplateParameterUriParameterSetName = "Deployment via Gallery and template parameters uri"; protected const string TemplateFileParameterObjectParameterSetName = "Deployment via template file and template parameters object"; protected const string TemplateFileParameterFileParameterSetName = "Deployment via template file and template parameters file"; + protected const string TemplateFileParameterUriParameterSetName = "Deployment via template file template parameters uri"; protected const string TemplateUriParameterObjectParameterSetName = "Deployment via template uri and template parameters object"; protected const string TemplateUriParameterFileParameterSetName = "Deployment via template uri and template parameters file"; + protected const string TemplateUriParameterUriParameterSetName = "Deployment via template uri and template parameters uri"; protected const string ParameterlessTemplateFileParameterSetName = "Deployment via template file without parameters"; protected const string ParameterlessGalleryTemplateParameterSetName = "Deployment via Gallery without parameters"; protected const string ParameterlessTemplateUriParameterSetName = "Deployment via template uri without parameters"; @@ -71,10 +74,21 @@ protected ResourceWithParameterBaseCmdlet() [ValidateNotNullOrEmpty] public string TemplateParameterFile { get; set; } + [Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")] + [Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")] + [Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")] + [ValidateNotNullOrEmpty] + public string TemplateParameterUri { get; set; } + [Parameter(ParameterSetName = GalleryTemplateParameterObjectParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")] [Parameter(ParameterSetName = GalleryTemplateParameterFileParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")] + [Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")] [Parameter(ParameterSetName = ParameterlessGalleryTemplateParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")] [ValidateNotNullOrEmpty] @@ -84,6 +98,8 @@ protected ResourceWithParameterBaseCmdlet() Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")] [Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")] + [Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")] [Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")] [ValidateNotNullOrEmpty] @@ -93,17 +109,21 @@ protected ResourceWithParameterBaseCmdlet() Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")] [Parameter(ParameterSetName = TemplateUriParameterFileParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")] + [Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName, + Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")] [Parameter(ParameterSetName = ParameterlessTemplateUriParameterSetName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")] [ValidateNotNullOrEmpty] public string TemplateUri { get; set; } [Parameter(ParameterSetName = TemplateFileParameterObjectParameterSetName, - Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")] + Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")] [Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName, - Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")] + Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")] + [Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName, + Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")] [Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName, - Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")] + Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")] [ValidateNotNullOrEmpty] public string StorageAccountName { get; set; } @@ -141,31 +161,64 @@ public object GetDynamicParameters() !GalleryTemplateIdentity.Equals(galleryTemplateName, StringComparison.OrdinalIgnoreCase)) { galleryTemplateName = GalleryTemplateIdentity; - dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery( - GalleryTemplateIdentity, - TemplateParameterObject, - this.TryResolvePath(TemplateParameterFile), - MyInvocation.MyCommand.Parameters.Keys.ToArray()); + if(string.IsNullOrEmpty(TemplateParameterUri)) + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery( + GalleryTemplateIdentity, + TemplateParameterObject, + this.TryResolvePath(TemplateParameterFile), + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } + else + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery( + GalleryTemplateIdentity, + TemplateParameterObject, + TemplateParameterUri, + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } } else if (!string.IsNullOrEmpty(TemplateFile) && !TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase)) { templateFile = TemplateFile; - dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( - this.TryResolvePath(TemplateFile), - TemplateParameterObject, - this.TryResolvePath(TemplateParameterFile), - MyInvocation.MyCommand.Parameters.Keys.ToArray()); + if (string.IsNullOrEmpty(TemplateParameterUri)) + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( + this.TryResolvePath(TemplateFile), + TemplateParameterObject, + this.TryResolvePath(TemplateParameterFile), + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } + else + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( + this.TryResolvePath(TemplateFile), + TemplateParameterObject, + TemplateParameterUri, + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } } else if (!string.IsNullOrEmpty(TemplateUri) && !TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase)) { templateUri = TemplateUri; - dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( - TemplateUri, - TemplateParameterObject, - this.TryResolvePath(TemplateParameterFile), - MyInvocation.MyCommand.Parameters.Keys.ToArray()); + if (string.IsNullOrEmpty(TemplateParameterUri)) + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( + TemplateUri, + TemplateParameterObject, + this.TryResolvePath(TemplateParameterFile), + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } + else + { + dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile( + TemplateUri, + TemplateParameterObject, + TemplateParameterUri, + MyInvocation.MyCommand.Parameters.Keys.ToArray()); + } } return dynamicParameters; diff --git a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs index 8d9c9c3d913e..c1b8f40081fd 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs @@ -26,6 +26,8 @@ public class ValidatePSResourceGroupDeploymentParameters public Hashtable TemplateParameterObject { get; set; } + public string ParameterUri { get; set; } + public string TemplateVersion { get; set; } public string StorageAccountName { get; set; } diff --git a/src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs index 3edb04bcd9d9..acf6650971c9 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs @@ -56,6 +56,7 @@ public override void ExecuteCmdlet() GalleryTemplateIdentity = GalleryTemplateIdentity, TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile), TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject), + ParameterUri = TemplateParameterUri, TemplateVersion = TemplateVersion, StorageAccountName = StorageAccountName }; diff --git a/src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs b/src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs index e6cd93adced3..d1b743791b85 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs @@ -46,6 +46,7 @@ public override void ExecuteCmdlet() GalleryTemplateIdentity = GalleryTemplateIdentity, TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile), TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject), + ParameterUri = TemplateParameterUri, TemplateVersion = TemplateVersion, StorageAccountName = StorageAccountName };