Skip to content

Support new cmdlets for subscription level deployment #6516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Aug 9, 2018

Conversation

Tiano2017
Copy link
Contributor

Description

This PR adds new cmdlets for subscription level deployment.

Checklist

@cormacpayne
Copy link
Member

@Tiano2017 when you're ready for someone from our side to review this PR, please remove the Do Not Merge and needs-revision labels and add the needs-review label to the PR

@Tiano2017 Tiano2017 changed the title <Do Not Merge>Support new cmdlets for subscription level deployment Support new cmdlets for subscription level deployment Jul 5, 2018
@cormacpayne
Copy link
Member

Corresponding cmdlet design review: https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/102

@vladimir-shcherbakov
Copy link
Contributor

@Tiano2017
Is it possible for you to re-base you commits to have only essential ones in the PR?
A possible way to do this:

git remote add upstream https://github.com/Azure/azure-powershell.git
git fetch upstream
git merge upstream/preview
git reset --soft upstream/preview
<commit your changes>
git push --force

@Tiano2017
Copy link
Contributor Author

@vladimir-shcherbakov sure I can do that, but should I do that after all issues are resolved? right now I still have CI failures which I'm trying to resolve.

@vladimir-shcherbakov
Copy link
Contributor

@Tiano2017
I think this would help you in resolving of ci-build issues.

@Tiano2017
Copy link
Contributor Author

did the rebase. seems still got the failure.

@vladimir-shcherbakov
Copy link
Contributor

@Tiano2017
Copy link
Contributor Author

@vladimir-shcherbakov I've fixed the error on help files. Can you help take another look?

@vladimir-shcherbakov
Copy link
Contributor

vladimir-shcherbakov commented Jul 20, 2018

@Tiano2017
You have a bunch of failing tests: https://azuresdkci.westus2.cloudapp.azure.com/job/powershell/6026/artifact/src/Publish/TestResults/FailingTests/

Reason to fail for most of them is Unable to find a matching HTTP request for URL .. . That means these tests need to be re-recorded

@Tiano2017
Copy link
Contributor Author

@cormacpayne can you please take another look?


[Alias("DeploymentName")]
[Parameter(Position = 0, ParameterSetName = GetAzureDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
ValueFromPipelineByPropertyName = true, HelpMessage = "The name of deployment.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 please remove the ValueFromPipelineByPropertyName property from the -Name parameter and move it to the -ResourceId parameter so users can do the following:

Get-AzureRmResource -ResourceType Microsoft.Resources/deployments | Get-AzureRmDeployment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need it on the Name parameter for some other pipeline scenarios. As for Get-AzureRmResource, I don't think it returns "deployments" as resources. Strictly speaking, "deployment" is not a resource, although we implement the APIs to be consistent with resource APIs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 this is deprecated - Piping by value is now the recommendation - if you can pipe the object associated with the cmdlet noun into the cmdlet no by-property-name piping (other than piping resourceid by property name) should be used.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Mark.. I'm not quite getting the point. Are you recommending just removing this piping support?


In reply to: 207954017 [](ancestors = 207954017)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As replied in the other comment, Get-AzureRmResource doesn't return deployments, as deployment is not a resource..


In reply to: 207688618 [](ancestors = 207688618)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ValueFromPipelineByPropertyName setting is still here. Remove. If you want to support piping from something, use a parameter set with a PSDeployment INputObject. In this case, you may not need piping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note - you should consider having a single parameter that would accept either Name or Id - then the user could pass in a fully qualified name or short name and you wouldn't need any parameter set.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.


In reply to: 208426878 [](ancestors = 208426878)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have these two parameters for Get-AzureRmResourceGroupDeployment. I think we can keep them to be consistent.


In reply to: 208427148 [](ancestors = 208427148)

public string Location { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment debug log level.")]
[ValidateSet("RequestContent", "ResponseContent", "All", "None", IgnoreCase = true)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 we recommend using PSArgumentCompleter since it allows for potential additions in the future and users don't notice a difference with the tab-completion

{
Location = Location,
DeploymentName = Name,
DeploymentMode = DeploymentMode.Incremental,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 got it, thanks for clarifying

{
WriteWarning(ProjectResources.WarnOnDeploymentDebugSetting);
}
WriteObject(ResourceManagerSdkClient.ExecuteDeploymentAtSubscriptionScope(parameters));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 you do it below for your Save-AzureRmDeployment cmdlet 😀

public string Name { get; set; }

[Alias("DeploymentId", "ResourceId")]
[Parameter(ParameterSetName = RemoveAzureDeploymentCmdlet.DeploymentIdParameterSet, Mandatory = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 the result of Get-AzureRmDeployment will be bound to the -InputObject parameter. We want to enable the scenario (as mentioned above for Get-AzureRmDeployment) where the user can pipe the result of Get-AzureRmResource to a cmdlet and have the -ResourceId bound, which is enable when you add the ValueFromPipelineByPropertyName property to this parameter and remove it from the -Name parameter.

[Parameter(ParameterSetName = RemoveAzureDeploymentCmdlet.InputObjectParameterSet, Mandatory = true,
ValueFromPipeline = true, HelpMessage = "The deployment object.")]
public PSDeployment InputObject { get; set; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 is the underlying operation long-running? If so, you might as well add the -AsJob parameter to allow users to run this cmdlet in the background (at no cost 😉)

string.IsNullOrEmpty(this.Path)
? System.IO.Path.Combine(CurrentPath(), deploymentName)
: this.TryResolvePath(this.Path),
overwrite: this.Force,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 got it, thanks for clarifying

/// Saves the deployment template to a file on disk.
/// </summary>
[Cmdlet(VerbsData.Save, "AzureRmDeploymentTemplate", SupportsShouldProcess = true,
DefaultParameterSetName = SaveAzureDeploymentTemplateCmdlet.DeploymentNameParameterSet), OutputType(typeof(PSObject))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 even if we are returning the file path, we should still have a concrete type with that path as one of its properties -- we are now generating docs for our types, which lets the user know what properties and methods are exposed on parameter and output types, and it is also best practice to use concrete .NET types in PowerShell for consistency in returned objects

/// <summary>
/// Cancel a running deployment.
/// </summary>
[Cmdlet(VerbsLifecycle.Stop, "AzureRmDeployment", SupportsShouldProcess = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 got it. Maybe we should think about adding an alias for New-AzureRmDeployment that is Start-AzureRmDeployment? Something to think about

public string Name { get; set; }

[Alias("DeploymentId", "ResourceId")]
[Parameter(ParameterSetName = StopAzureDeploymentCmdlet.DeploymentIdParameterSet, Mandatory = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017 same comment as above 😀

@@ -1391,13 +1391,13 @@ public void CancelsActiveDeployment()
public void SerializeHashtableProperlyHandlesAllDataTypes()
{
Hashtable hashtable = new Hashtable();
var password = "pass";
var pass = "pass";
hashtable.Add("key1", "string");
Copy link
Contributor

@vladimir-shcherbakov vladimir-shcherbakov Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tiano2017
The right way to avoid false positives matches is to use inline-suppressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be fine. It's a random variable, and doesn't have to be named "password".

@markcowl markcowl changed the base branch from preview to release-2018-08-10 August 7, 2018 23:10
Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have makred those places where there are still necessary changes.


[Alias("DeploymentName")]
[Parameter(Position = 0, ParameterSetName = GetAzureDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
ValueFromPipelineByPropertyName = true, HelpMessage = "The name of deployment.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ValueFromPipelineByPropertyName setting is still here. Remove. If you want to support piping from something, use a parameter set with a PSDeployment INputObject. In this case, you may not need piping.


[Alias("DeploymentName")]
[Parameter(Position = 0, ParameterSetName = GetAzureDeploymentCmdlet.DeploymentNameParameterSet, Mandatory = false,
ValueFromPipelineByPropertyName = true, HelpMessage = "The name of deployment.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note - you should consider having a single parameter that would accept either Name or Id - then the user could pass in a fully qualified name or short name and you wouldn't need any parameter set.

/// <summary>
/// Gets or sets the deployment name parameter.
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment name.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, these ValueFromPipelineByPropertyName settings should be removed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. And added DepoymentObject parameter for piping scenario.


In reply to: 208427257 [](ancestors = 208427257)

public class NewAzureDeploymentCmdlet : ResourceWithParameterCmdletBase, IDynamicParameters
{
[Alias("DeploymentName")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

: !string.IsNullOrEmpty(this.Id) ? ResourceIdUtility.GetResourceName(this.Id) : this.InputObject.DeploymentName;

ResourceManagerSdkClient.DeleteDeploymentAtSubscriptionScope(deploymentName);
WriteObject(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good reason to continue a non-conforming pattern. You should return nothing on success, unless the user supplies -PassThru

/// <summary>
/// Gets or sets the file path.
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The output path of the template file.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue, remove the ValueFromPipelineByPropertyName setting for this parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

this.Name,
() => ResourceManagerSdkClient.CancelDeploymentAtSubscriptionScope(deploymentName));

WriteObject(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need to make this meet the design guidelines now.

@markcowl markcowl dismissed cormacpayne’s stale review August 8, 2018 02:04

Marked those places that still need to change

@Tiano2017
Copy link
Contributor Author

CI job is passing now. @markcowl please let me know if there's more changes required.

@markcowl markcowl merged commit 192c1f0 into Azure:release-2018-08-10 Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants