Skip to content

Commit

Permalink
Update Test Deployments to allow the user to specify a deployment name (
Browse files Browse the repository at this point in the history
#15082)

* Update TestAzureSubscriptionDeploymentCmdlet.cs

* For TestAzureSubscriptionDeployment - If deployment name is null, then generate the name, otherwise, pass the deployment name

* Allow to specify deployment name for validate on management group, subscription, and tenant deployments

* changelog Allow naming the deployment when testing deployments [#11497]

* change help message

* Update-MarkdownHelpModule

Co-authored-by: Jonathan Reynes <[email protected]>
  • Loading branch information
jontreynes and jontreynes authored May 28, 2021
1 parent f0a6be6 commit 37e7adc
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
[Cmdlet(VerbsDiagnostic.Test, AzureRMConstants.AzureRMPrefix + "ManagementGroupDeployment", DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
public class TestAzureManagementGroupDeploymentCmdlet : TestDeploymentCmdletBase
{
[Alias("DeploymentName")]
[Parameter(Mandatory = false,
HelpMessage = "The name of the deployment it's going to test. If not specified, defaults to the template file name when a template file is provided")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = true, HelpMessage = "The management group id.")]
[ValidateNotNullOrEmpty]
public string ManagementGroupId { get; set; }
Expand All @@ -44,6 +50,7 @@ protected override void OnProcessRecord()
ScopeType = DeploymentScopeType.ManagementGroup,
ManagementGroupId = this.ManagementGroupId,
Location = this.Location,
DeploymentName = this.Name,
QueryString = QueryString,
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
TemplateObject = this.TemplateObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
[Alias("Test-AzSubscriptionDeployment")]
public class TestAzureSubscriptionDeploymentCmdlet : TestDeploymentCmdletBase
{
[Alias("DeploymentName")]
[Parameter(Mandatory = false,
HelpMessage = "The name of the deployment it's going to test. If not specified, defaults to the template file name when a template file is provided")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = true, HelpMessage = "The location to store deployment data.")]
[LocationCompleter("Microsoft.Resources/resourceGroups")]
[ValidateNotNullOrEmpty]
Expand All @@ -40,6 +46,7 @@ protected override void OnProcessRecord()
{
ScopeType = DeploymentScopeType.Subscription,
Location = Location,
DeploymentName = this.Name,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateObject = TemplateObject,
QueryString = QueryString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
public class TestAzureTenantDeploymentCmdlet : TestDeploymentCmdletBase
{
[Alias("DeploymentName")]
[Parameter(Mandatory = false,
HelpMessage = "The name of the deployment it's going to test. If not specified, defaults to the template file name when a template file is provided")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = true, HelpMessage = "The location to store deployment data.")]
[LocationCompleter("Microsoft.Resources/resourceGroups")]
[ValidateNotNullOrEmpty]
Expand All @@ -40,6 +46,7 @@ protected override void OnProcessRecord()
{
ScopeType = DeploymentScopeType.Tenant,
Location = this.Location,
DeploymentName = this.Name,
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
TemplateObject = this.TemplateObject,
QueryString = QueryString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,9 @@ private void CancelDeploymentAtResourceGroup(List<PSDeployment> deployments, str
/// <returns>The validation errors if there's any, or empty list otherwise.</returns>
public virtual List<PSResourceManagerError> ValidateDeployment(PSDeploymentCmdletParameters parameters)
{
parameters.DeploymentName = GenerateDeploymentName(parameters);
if (parameters.DeploymentName == null){
parameters.DeploymentName = GenerateDeploymentName(parameters);
}
Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode, null);

var validationInfo = this.GetTemplateValidationResult(parameters, deployment);
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Allow naming the deployment when testing deployments [#11497]

## Version 4.1.0
* Changed `-IdentifierUris` in `New-AzADApplication` to optional parameter
Expand Down
118 changes: 70 additions & 48 deletions src/Resources/Resources/help/Test-AzManagementGroupDeployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,107 +14,114 @@ Validates a deployment at a management group.

### ByTemplateFileWithNoParameters (Default)
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateFile <String> [-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateFile <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateObjectAndParameterObject
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterObject <Hashtable> -TemplateObject <Hashtable> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterObject <Hashtable> -TemplateObject <Hashtable>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateFileAndParameterObject
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterObject <Hashtable> -TemplateFile <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterObject <Hashtable> -TemplateFile <String>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateUriAndParameterObject
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterObject <Hashtable> -TemplateUri <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterObject <Hashtable> -TemplateUri <String>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateSpecResourceIdAndParamsObject
```
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterObject <Hashtable> -TemplateSpecId <String>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateObjectAndParameterFile
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterFile <String> -TemplateObject <Hashtable> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterFile <String> -TemplateObject <Hashtable>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateFileAndParameterFile
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterFile <String> -TemplateFile <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterFile <String> -TemplateFile <String> [-SkipTemplateParameterPrompt]
[-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateUriAndParameterFile
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterFile <String> -TemplateUri <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterFile <String> -TemplateUri <String> [-SkipTemplateParameterPrompt]
[-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateSpecResourceIdAndParams
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterFile <String> -TemplateSpecId <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterFile <String> -TemplateSpecId <String>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateObjectAndParameterUri
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterUri <String> -TemplateObject <Hashtable> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterUri <String> -TemplateObject <Hashtable>
[-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateFileAndParameterUri
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterUri <String> -TemplateFile <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterUri <String> -TemplateFile <String> [-SkipTemplateParameterPrompt]
[-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateUriAndParameterUri
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterUri <String> -TemplateUri <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterUri <String> -TemplateUri <String> [-SkipTemplateParameterPrompt]
[-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateSpecResourceIdAndParamsUri
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateParameterUri <String> -TemplateSpecId <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateParameterUri <String> -TemplateSpecId <String> [-SkipTemplateParameterPrompt]
[-Pre] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateObjectWithNoParameters
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateObject <Hashtable> [-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateObject <Hashtable> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateUriWithNoParameters
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateUri <String> [-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateUri <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

### ByTemplateSpecResourceId
```
Test-AzManagementGroupDeployment -ManagementGroupId <String> -Location <String> [-QueryString <String>]
-TemplateSpecId <String> [-SkipTemplateParameterPrompt] [-Pre] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Test-AzManagementGroupDeployment [-Name <String>] -ManagementGroupId <String> -Location <String>
[-QueryString <String>] -TemplateSpecId <String> [-SkipTemplateParameterPrompt] [-Pre]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -185,6 +192,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the deployment it's going to test. If not specified, defaults to the template file name when a template file is provided
```yaml
Type: System.String
Parameter Sets: (All)
Aliases: DeploymentName

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Pre
When set, indicates that the cmdlet should use pre-release API versions when automatically determining which version to use.
Expand Down Expand Up @@ -282,7 +304,7 @@ A hash table which represents the parameters.
```yaml
Type: System.Collections.Hashtable
Parameter Sets: ByTemplateObjectAndParameterObject, ByTemplateFileAndParameterObject, ByTemplateUriAndParameterObject
Parameter Sets: ByTemplateObjectAndParameterObject, ByTemplateFileAndParameterObject, ByTemplateUriAndParameterObject, ByTemplateSpecResourceIdAndParamsObject
Aliases:

Required: True
Expand Down Expand Up @@ -312,7 +334,7 @@ Resource ID of the templateSpec to be deployed.
```yaml
Type: System.String
Parameter Sets: ByTemplateSpecResourceIdAndParams, ByTemplateSpecResourceIdAndParamsUri, ByTemplateSpecResourceId
Parameter Sets: ByTemplateSpecResourceIdAndParamsObject, ByTemplateSpecResourceIdAndParams, ByTemplateSpecResourceIdAndParamsUri, ByTemplateSpecResourceId
Aliases:

Required: True
Expand Down Expand Up @@ -352,4 +374,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## NOTES
## RELATED LINKS
## RELATED LINKS
Loading

0 comments on commit 37e7adc

Please sign in to comment.