Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b36fea9
Initial wrapped models for Template Specs (including versions/artifacts)
stuartko May 14, 2020
2f68b1d
Template Specs: Initial cmdlets for Get/New/Remove. Does not include …
stuartko May 15, 2020
6396d15
Initial check-in of the packaging engine for Template Specs
stuartko May 22, 2020
cd8b5d7
Template Specs: Adding Export. Adding import from file (with packaging)
stuartko May 26, 2020
7a62b3b
Removing debug console write line.
stuartko May 27, 2020
467a19a
Template Specs: Initial Get Cmdlet tests. TODO: Remove temp internal …
stuartko Jun 2, 2020
7623683
Added support for templateSpecs
Xynoclafe Jun 3, 2020
c142db5
Merge branch 'TemplateSpecs' of https://github.com/Azure/azure-powers…
Xynoclafe Jun 4, 2020
2a708b6
Template Specs: Adding basic Template Spec creation cmdlet test
stuartko Jun 5, 2020
1c5fa30
Template Specs: Adding test for removal cmdlet
stuartko Jun 5, 2020
935e8c9
Remove relativePath rewrites from TemplateSpecPackagingEngine
stuartko Jun 10, 2020
ca159f4
Adding Set-AzTemplateSpec cmdlet + updating parameter set names
stuartko Jun 12, 2020
1ea069d
Template Specs: Adding cmdlet help. Adding Set-AzTemplateSpec to exports
stuartko Jun 16, 2020
efcc11f
Fixing help file typo
stuartko Jun 16, 2020
dc201c5
Template Specs: Changing -Id to -ResourceId as default id parameter (…
stuartko Jun 18, 2020
a722fb5
Adding basic test for Set-AzTemplateSpec
stuartko Jun 25, 2020
4d57b07
Merge branch 'TemplateSpecs' of https://github.com/Azure/azure-powers…
Xynoclafe Jun 29, 2020
26114c4
Update SDK; Re-record tests; Test for templateSpec deployment
Xynoclafe Jul 1, 2020
5f70ee3
Fix test
Xynoclafe Jul 1, 2020
e7248e3
Merge from master
Xynoclafe Jul 1, 2020
b57ce0a
Dropping model suffix from templateSpec SDK
Xynoclafe Jul 3, 2020
0697053
Use latest SDK
Xynoclafe Jul 7, 2020
0bdaa99
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Jul 8, 2020
bdef829
Rerecord test
Xynoclafe Jul 8, 2020
bf7c6c8
Change SDK version
Xynoclafe Jul 13, 2020
6e8a715
rerecord tests for SDK version change
Xynoclafe Jul 15, 2020
ce80561
Modify output formatting
Xynoclafe Jul 15, 2020
f314be9
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Jul 15, 2020
08ea488
Template Specs: Fixing null reference exception
stuartko Jul 16, 2020
10a3a11
Template Specs: Adding Id to Version Model
stuartko Jul 16, 2020
5d07486
Fix for https://github.com/Azure/template-specs/issues/9
Xynoclafe Jul 20, 2020
74548a8
Check version in resource ID
Xynoclafe Jul 20, 2020
fddb529
Template Specs: Fix path issue + issue with exporting artifactless te…
stuartko Jul 21, 2020
cfa49c5
Update obsolete package
shenglol Jul 21, 2020
2dc803d
Make -TemplateSpecId work with What-If
shenglol Jul 21, 2020
509bb54
TemplateSpecs: Adding -VersionDescription to New-AzTemplateSpec and u…
stuartko Jul 24, 2020
5d4a54b
Template Specs: Fixing issue with Template Spec imports where relativ…
stuartko Jul 24, 2020
fd49e3b
Template Specs: Updating New-AzTemplateSpec to prompt on overwrite un…
stuartko Aug 3, 2020
4f4123f
Template Specs: Adding more user-friendly formating
stuartko Aug 4, 2020
35d5527
Template Specs: Fixing unpacking bug on Linux. Improving formatting f…
stuartko Aug 8, 2020
a67bd3c
Template Specs: Unifying multi/single version types for PSTemplateSpe…
stuartko Sep 22, 2020
527decc
Template Specs: Help file updates for recent return type changes
stuartko Sep 23, 2020
3acd44e
Template Specs: Rename TemplateJsonFile to TemplateJson. Warn on Temp…
stuartko Sep 24, 2020
215282a
Template Specs: Removing unnecessary localization TODOs (validate pre…
stuartko Sep 24, 2020
7e62af0
Template Specs: Unused parameter cleanup in Set-AzTemplateSpec
stuartko Sep 24, 2020
79070e6
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Sep 25, 2020
0a4f6a8
Merge branch 'TemplateSpecs' of https://github.com/Azure/azure-powers…
Xynoclafe Sep 25, 2020
0c6e8f1
Template Specs: Include parent template name in exported filename
stuartko Sep 28, 2020
e45b189
Merge branch 'TemplateSpecs' of https://github.com/Azure/azure-powers…
stuartko Sep 28, 2020
4e04352
Template Specs: Fixing missing comma in psd after merge
stuartko Sep 28, 2020
fed1053
Template Specs: Re-record of deployment test
stuartko Sep 28, 2020
b02a7fb
Template Specs: Updating changelog for upcoming Az Powershell release
stuartko Sep 28, 2020
c0b454f
Template Specs: Removing two unnecessary csproj changes kept during m…
stuartko Sep 28, 2020
11882c4
Upgrading ResourceManager package for test targets to 3.8.0-preview
stuartko Sep 28, 2020
3ee1409
Template Specs: Adding online help URLs for template spec cmdlets
stuartko Sep 28, 2020
a8ba32f
Template Specs: Adding ShouldProcess support to all applicable cmdlets
stuartko Sep 30, 2020
5112dd6
Template Specs: Reduce/fix positional parameters in Set-AzTemplateSpec
stuartko Sep 30, 2020
1dd04fc
Template Specs: Dropping a positional param
stuartko Sep 30, 2020
8e3ab8c
Taking latest merge from master + fixing conflict.
stuartko Oct 12, 2020
a26266f
Taking latest changes from master (contain fix for Peering test)
stuartko Oct 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
Expand All @@ -41,6 +45,10 @@ public abstract class ResourceWithParameterCmdletBase : ResourceManagerCmdletBas
protected const string ParameterlessTemplateFileParameterSetName = "ByTemplateFileWithNoParameters";
protected const string ParameterlessTemplateUriParameterSetName = "ByTemplateUriWithNoParameters";

protected const string TemplateSpecResourceIdParameterSetName = "ByTemplateSpecResourceId";
protected const string TemplateSpecResourceIdParameterFileParameterSetName = "ByTemplateSpecResourceIdAndParams";
protected const string TemplateSpecResourceIdParameterUriParameterSetName = "ByTemplateSpecResourceIdAndParamsUri";

protected RuntimeDefinedParameterDictionary dynamicParameters;

private Hashtable templateObject;
Expand All @@ -49,6 +57,8 @@ public abstract class ResourceWithParameterCmdletBase : ResourceManagerCmdletBas

private string templateUri;

private string templateSpecId;

protected ResourceWithParameterCmdletBase()
{
dynamicParameters = new RuntimeDefinedParameterDictionary();
Expand All @@ -68,6 +78,8 @@ protected ResourceWithParameterCmdletBase()
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A file that has the template parameters.")]
[Parameter(ParameterSetName = TemplateUriParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A file that has the template parameters.")]
[Parameter(ParameterSetName = TemplateSpecResourceIdParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A file that has the template parameters.")]
[ValidateNotNullOrEmpty]
public string TemplateParameterFile { get; set; }

Expand All @@ -77,6 +89,8 @@ protected ResourceWithParameterCmdletBase()
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.")]
[Parameter(ParameterSetName = TemplateSpecResourceIdParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
[ValidateNotNullOrEmpty]
public string TemplateParameterUri { get; set; }

Expand Down Expand Up @@ -113,12 +127,41 @@ protected ResourceWithParameterCmdletBase()
[ValidateNotNullOrEmpty]
public string TemplateUri { get; set; }

[Parameter(ParameterSetName = TemplateSpecResourceIdParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Resource ID of the templateSpec to be deployed.")]
[Parameter(ParameterSetName = TemplateSpecResourceIdParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Resource ID of the templateSpec to be deployed.")]
[Parameter(ParameterSetName = TemplateSpecResourceIdParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Resource ID of the templateSpec to be deployed.")]
[ValidateNotNullOrEmpty]
public string TemplateSpecId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Skips the PowerShell dynamic parameter processing that checks if the provided template parameter contains all necessary parameters used by the template. " +
"This check would prompt the user to provide a value for the missing parameters, but providing the -SkipTemplateParameterPrompt will ignore this prompt and " +
"error out immediately if a parameter was found not to be bound in the template. For non-interactive scripts, -SkipTemplateParameterPrompt can be provided " +
"to provide a better error message in the case where not all required parameters are satisfied.")]
public SwitchParameter SkipTemplateParameterPrompt { get; set; }

private TemplateSpecsSdkClient templateSpecsSdkClient;

/// <summary>
/// Gets or sets the Template Specs Azure sdk client wrapper
/// </summary>
public TemplateSpecsSdkClient TemplateSpecsSdkClient
{
get
{
if (this.templateSpecsSdkClient == null)
{
this.templateSpecsSdkClient = new TemplateSpecsSdkClient(DefaultContext);
}

return this.templateSpecsSdkClient;
}

set { this.templateSpecsSdkClient = value; }
}

public object GetDynamicParameters()
{
if (!this.IsParameterBound(c => c.SkipTemplateParameterPrompt))
Expand Down Expand Up @@ -185,6 +228,40 @@ public object GetDynamicParameters()
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
}
else if (!string.IsNullOrEmpty(TemplateSpecId) &&
!TemplateSpecId.Equals(templateSpecId, StringComparison.OrdinalIgnoreCase))
{
templateSpecId = TemplateSpecId;
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(templateSpecId);
if(!resourceIdentifier.ResourceType.Equals("Microsoft.Resources/templateSpecs/versions", StringComparison.OrdinalIgnoreCase))
{
throw new PSArgumentException("No version found in Resource ID");
}

var templateSpecVersion = TemplateSpecsSdkClient.GetTemplateSpec(
ResourceIdUtility.GetResourceName(templateSpecId).Split('/')[0],
ResourceIdUtility.GetResourceGroupName(templateSpecId),
resourceIdentifier.ResourceName).Versions.Single();

var templateObj = JObject.Parse(templateSpecVersion.Template);

if (string.IsNullOrEmpty(TemplateParameterUri))
{
dynamicParameters = TemplateUtility.GetTemplateParametersFromFile(
templateObj,
TemplateParameterObject,
this.ResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
else
{
dynamicParameters = TemplateUtility.GetTemplateParametersFromFile(
templateObj,
TemplateParameterObject,
TemplateParameterUri,
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
}
}

RegisterDynamicParameters(dynamicParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
using Microsoft.Azure.Commands.ResourceManager.Common;
using System;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
public class TemplateSpecCmdletBase : AzureRMCmdlet
{
private TemplateSpecsSdkClient templateSpecsSdkClient;

/// <summary>
/// Gets or sets the Template Specs Azure sdk client wrapper
/// </summary>
public TemplateSpecsSdkClient TemplateSpecsSdkClient
{
get
{
if (this.templateSpecsSdkClient == null)
{
this.templateSpecsSdkClient = new TemplateSpecsSdkClient(DefaultContext);
}

return this.templateSpecsSdkClient;
}

set { this.templateSpecsSdkClient = value; }
}

/// <summary>
/// Override method to extract inner errors.
/// </summary>
/// <param name="ex">exception</param>
protected override void WriteExceptionError(Exception ex)
{
var aggEx = ex as AggregateException;

if (aggEx != null && aggEx.InnerExceptions != null)
{
foreach (var e in aggEx.Flatten().InnerExceptions)
{
WriteExceptionError(e);
}

return;
}

base.WriteExceptionError(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class GetAzureSubscriptionDeploymentWhatIfResultCmdlet : DeploymentWhatIf
mode: DeploymentMode.Incremental,
templateUri: this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
templateObject: this.TemplateObject,
templateSpecId: TemplateSpecId,
templateParametersUri: this.TemplateParameterUri,
templateParametersObject: GetTemplateParameterObject(this.TemplateParameterObject),
resultFormat: this.ResultFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class NewAzureSubscriptionDeploymentCmdlet : DeploymentCreateCmdlet
DeploymentMode = DeploymentMode.Incremental,
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
TemplateObject = this.TemplateObject,
TemplateSpecId = TemplateSpecId,
TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
ParameterUri = this.TemplateParameterUri,
DeploymentDebugLogLevel = this.GetDeploymentDebugLogLevel(this.DeploymentDebugLogLevel),
Expand All @@ -90,6 +91,7 @@ public class NewAzureSubscriptionDeploymentCmdlet : DeploymentCreateCmdlet
mode: DeploymentMode.Incremental,
templateUri: TemplateUri ?? this.TryResolvePath(TemplateFile),
templateObject: this.TemplateObject,
templateSpecId: TemplateSpecId,
templateParametersUri: this.TemplateParameterUri,
templateParametersObject: GetTemplateParameterObject(this.TemplateParameterObject),
resultFormat: this.WhatIfResultFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class GetAzureResourceGroupDeploymentWhatIfResultCmdlet : DeploymentWhatI
resourceGroupName: this.ResourceGroupName,
templateUri: this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
templateObject: this.TemplateObject,
templateSpecId: TemplateSpecId,
templateParametersUri: this.TemplateParameterUri,
templateParametersObject: GetTemplateParameterObject(this.TemplateParameterObject),
resultFormat: this.ResultFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NewAzureResourceGroupDeploymentCmdlet : DeploymentCreateCmdlet
{
[Alias("DeploymentName")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The name of the deployment it's going to create. If not specified, defaults to the template file name when a template file is provided; defaults to the current time when a template object is provided, e.g. \"20131223140835\".")]
HelpMessage = "The name of the deployment it's going to create. If not specified, defaults to the template file name when a template file is provided; defaults to the current time when a template object is provided, e.g. \"20131223140835\".")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand Down Expand Up @@ -87,6 +87,7 @@ public class NewAzureResourceGroupDeploymentCmdlet : DeploymentCreateCmdlet
DeploymentMode = Mode,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateObject = TemplateObject,
TemplateSpecId = TemplateSpecId,
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
ParameterUri = TemplateParameterUri,
DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(DeploymentDebugLogLevel),
Expand All @@ -107,6 +108,7 @@ public class NewAzureResourceGroupDeploymentCmdlet : DeploymentCreateCmdlet
resourceGroupName: this.ResourceGroupName,
templateUri: this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
templateObject: this.TemplateObject,
templateSpecId: TemplateSpecId,
templateParametersUri: this.TemplateParameterUri,
templateParametersObject: this.GetTemplateParameterObject(this.TemplateParameterObject),
resultFormat: this.WhatIfResultFormat,
Expand Down
Loading