Skip to content

Commit d205f78

Browse files
authored
Merge pull request Azure#11268 from jagilber/get-azure-resource-cmdlet-cs
Resources/GetAzureResourceCmdlet.cs fix Azure#11267 get-azresource to use actual apiVersion of resource with parameter set -ResourceGroupName -Name -ExpandProperties -ResourceType
2 parents 0c3118b + 3fb25d1 commit d205f78

File tree

5 files changed

+42608
-1
lines changed

5 files changed

+42608
-1
lines changed

src/Resources/ResourceManager/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ private bool ShouldConstructResourceId(out string resourceId)
226226
ResourceGroupName,
227227
ResourceType,
228228
Name);
229+
230+
this.DefaultApiVersion = DetermineApiVersion(resourceId).Result;
231+
229232
return true;
230233
}
231234

@@ -626,4 +629,4 @@ private bool IsResourceGroupLevelQuery()
626629
this.ResourceType != null;
627630
}
628631
}
629-
}
632+
}

src/Resources/Resources.Test/ScenarioTests/ResourceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ public void TestGetResourceWithExpandProperties()
138138
TestRunner.RunTestScript("Test-GetResourceExpandProperties");
139139
}
140140

141+
[Fact]
142+
[Trait(Category.AcceptanceType, Category.CheckIn)]
143+
public void TestGetResourceByNameAndType()
144+
{
145+
TestRunner.RunTestScript("Test-GetResourceByNameAndType");
146+
}
147+
141148
[Fact]
142149
[Trait(Category.AcceptanceType, Category.CheckIn)]
143150
public void TestGetResourceByIdAndProperties()

src/Resources/Resources.Test/ScenarioTests/ResourceTests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,42 @@ function Test-GetResourceExpandProperties
561561
}
562562
}
563563

564+
<#
565+
.SYNOPSIS
566+
Tests getting a resource by id, name, type, and its properties ensuring default resource api version is *not* used.
567+
#>
568+
function Test-GetResourceByNameAndType
569+
{
570+
# Setup
571+
$rgname = Get-ResourceGroupName
572+
$rname = Get-ResourceName
573+
$location = "West US"
574+
$resourceType = "Microsoft.Resources/deployments"
575+
$apiVersionWithType = "2019-10-01"
576+
$templateFile = "sampleTemplate.json"
577+
$templateParameterFile = "sampleTemplateParams.json"
578+
579+
try
580+
{
581+
# Test
582+
New-AzResourceGroup -Name $rgname -Location $location
583+
$deployment = New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile $templateFile -TemplateParameterFile $templateParameterFile
584+
585+
Assert-AreEqual Succeeded $deployment.ProvisioningState
586+
587+
$specifiedVersion = get-azresource -ResourceGroupName $rgname -Name $rname -ResourceType $resourceType -ExpandProperties -apiversion $apiVersionWithType
588+
Assert-NotNull $specifiedVersion.type
589+
590+
$unspecifiedVersion = get-azresource -ResourceGroupName $rgname -Name $rname -ResourceType $resourceType -ExpandProperties
591+
Assert-NotNull $unspecifiedVersion.type
592+
Assert-AreEqual $specifiedVersion.Type $unspecifiedVersion.Type
593+
}
594+
finally
595+
{
596+
Clean-ResourceGroup $rgname
597+
}
598+
}
599+
564600
<#
565601
.SYNOPSIS
566602
Tests getting a resource by id and its properties

0 commit comments

Comments
 (0)