diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj index 8652d99f0341..945ebfa9d4d7 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj @@ -120,6 +120,7 @@ + diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/Resource.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/Resource.cs index dbe87b7521d0..777e0354038a 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/Resource.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/Resource.cs @@ -47,6 +47,13 @@ public class Resource [JsonProperty(Required = Required.Default)] public string Type { get; set; } + /// + /// Gets or sets the resource sku. + /// + [JsonProperty(Required = Required.Default)] + public ResourceSku Sku { get; set; } + + /// /// Gets or sets the kind of the resource definition. /// diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/ResourceSku.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/ResourceSku.cs new file mode 100644 index 000000000000..ae79227e562d --- /dev/null +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/ResourceSku.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// 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. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources +{ + using Newtonsoft.Json; + + /// + /// The resource sku object. + /// + public class ResourceSku + { + /// + /// Gets or sets the sku name. + /// + [JsonProperty(Required = Required.Always)] + public string Name { get; set; } + + /// + /// Gets or sets the sku tier. + /// + [JsonProperty(Required = Required.Default)] + public string Tier { get; set; } + + /// + /// Gets or sets the sku size. + /// + [JsonProperty(Required = Required.Default)] + public string Size { get; set; } + + /// + /// Gets or sets the sku family. + /// + [JsonProperty(Required = Required.Default)] + public string Family { get; set; } + + /// + /// Gets or sets the sku capacity. + /// + [JsonProperty(Required = Required.Default)] + public int? Capacity { get; set; } + } +} + diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/NewAzureResourceCmdlet.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/NewAzureResourceCmdlet.cs index 20ae91629c14..ab8ce0bf43c1 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/NewAzureResourceCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/NewAzureResourceCmdlet.cs @@ -60,6 +60,14 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase [ValidateNotNullOrEmpty] public Hashtable PlanObject { get; set; } + /// + /// Gets or sets the plan object. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")] + [ValidateNotNullOrEmpty] + public Hashtable SkuObject { get; set; } + + /// /// Gets or sets the tags. /// @@ -174,6 +182,7 @@ private Resource GetResource() Location = this.Location, Kind = this.Kind, Plan = this.PlanObject.ToDictionary(addValueLayer: false).ToJson().FromJson(), + Sku = this.SkuObject.ToDictionary(addValueLayer: false).ToJson().FromJson(), Tags = TagsHelper.GetTagsDictionary(this.Tag), Properties = this.Properties.ToResourcePropertiesBody(), }; diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/SetAzureResourceCmdlet.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/SetAzureResourceCmdlet.cs index e77d64b07c89..cdb94e6ff6dd 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/SetAzureResourceCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/SetAzureResourceCmdlet.cs @@ -53,6 +53,15 @@ public sealed class SetAzureResourceCmdlet : ResourceManipulationCmdletBase [ValidateNotNullOrEmpty] public Hashtable Plan { get; set; } + /// + /// Gets or sets the plan object. + /// + [Alias("SkuObject")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")] + [ValidateNotNullOrEmpty] + public Hashtable Sku { get; set; } + + /// /// Gets or sets the tags. /// @@ -165,6 +174,7 @@ private JToken GetResourceBody() { Kind = this.Kind, Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson(), + Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson(), Tags = TagsHelper.GetTagsDictionary(this.Tag), Properties = this.Properties.ToResourcePropertiesBody(), }.ToJToken(); @@ -176,6 +186,7 @@ private JToken GetResourceBody() { Kind = this.Kind ?? resource.Kind, Plan = this.Plan.ToDictionary(addValueLayer: false).ToJson().FromJson() ?? resource.Plan, + Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson() ?? resource.Sku, Tags = TagsHelper.GetTagsDictionary(this.Tag) ?? resource.Tags, Location = resource.Location, Properties = this.Properties == null ? resource.Properties : this.Properties.ToResourcePropertiesBody(), @@ -194,7 +205,7 @@ private JToken GetResourceBody() /// private bool ShouldUsePatchSemantics() { - return this.UsePatchSemantics || (this.Tag != null && this.Plan == null && this.Properties == null && this.Kind == null); + return this.UsePatchSemantics || ((this.Tag != null || this.Sku != null) && this.Plan == null && this.Properties == null && this.Kind == null); } /// diff --git a/src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1 b/src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1 index 1443513b2ef7..88612b3bb834 100644 --- a/src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1 +++ b/src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1 @@ -27,9 +27,9 @@ function Test-CreatesNewSimpleResource $resourceType = "Microsoft.Sql/servers" # Test - New-AzureRmResourceGroup -Name $rgname -Location $rglocation - $actual = New-AzureRmResource -Name $rname -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion - $expected = Get-AzureRmResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion + New-AzureRMResourceGroup -Name $rgname -Location $rglocation + $actual = New-AzureRMResource -Name $rname -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion + $expected = Get-AzureRMResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType -ApiVersion $apiversion $list = Get-AzureRmResource -ResourceGroupName $rgname @@ -38,7 +38,8 @@ function Test-CreatesNewSimpleResource Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName Assert-AreEqual $expected.ResourceType $actual.ResourceType Assert-AreEqual 1 @($list).Count - Assert-AreEqual $expected.Name $list[0].Name + Assert-AreEqual $expected.Name $list[0].Name + Assert-AreEqual $expected.Sku $actual.Sku } <# @@ -258,12 +259,14 @@ function Test-SetAResource $resourceType = "Providers.Test/statefulResources" # Test - New-AzureRmResourceGroup -Name $rgname -Location $rglocation - $resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -ApiVersion $apiversion -Force - Set-AzureRmResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force + New-AzureRMResourceGroup -Name $rgname -Location $rglocation + $resource = New-AzureRMResource -Name $rname -Location $rglocation -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force + Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force + Set-AzureRMResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -SkuObject @{ Name = "A1" } -Force $modifiedResource = Get-AzureRmResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType # Assert Assert-AreEqual $modifiedResource.Properties.key2 "value2" + Assert-AreEqual $modifiedResource.Sku.Name "A1" } \ No newline at end of file