Azure / deployment-stacks

Contains Deployment Stacks CLI scripts and releases
MIT License
87 stars 7 forks source link

Get-AzResourceGroupDeploymentStackSnapshot return object is not being unrolled (it's returning the collection) #17

Closed brwilkinson closed 2 years ago

brwilkinson commented 2 years ago

Get-AzResourceGroupDeploymentStack only returns a single object, it functions correctly... see Get-Member shows the correct type.

Get-AzResourceGroupDeploymentStack -ResourceGroupName $rg -Name TEST01

Id                : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deploymentStacks/TEST01
Name              : TEST01
ProvisioningState : succeeded
UpdateBehavior    : purgeResources
Description       : TEST01-4
CreationTime(UTC) : 10/24/2021 10:29:42 PM
ManagedResources  : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Storage/storageAccounts/footeststorage545
                    /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Storage/storageAccounts/footeststorage5452
DeploymentId      : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deployments/TEST01-2021-10-24-23-11-00-3a73c
SnapshotId        : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deploymentStacks/TEST01/snapshots/2021-10-24-23-11-00-3a73c

Get-AzResourceGroupDeploymentStack -ResourceGroupName $rg -Name TEST01 | measure

Count             : 1

Get-AzResourceGroupDeploymentStack -ResourceGroupName $rg -Name TEST01 | get-member

   TypeName: Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStack

Name                   MemberType Definition
----                   ---------- ----------
Equals                 Method     bool Equals(System.Object obj)
GetHashCode            Method     int GetHashCode()
GetType                Method     type GetType()
ToString               Method     string ToString()
debugSetting           Property   Microsoft.Azure.Management.ResourceManager.Models.DeploymentStacksDebugSetting debugSetting {get;set;}
deploymentId           Property   string deploymentId {get;set;}
deploymentScope        Property   string deploymentScope {get;set;}
description            Property   string description {get;set;}
error                  Property   Microsoft.Azure.Management.ResourceManager.Models.ErrorResponse error {get;set;}
id                     Property   string id {get;set;}
location               Property   string location {get;set;}
locks                  Property   Microsoft.Azure.Management.ResourceManager.Models.LockSettings locks {get;set;}
managedResources       Property   System.Collections.Generic.IList[Microsoft.Azure.Management.ResourceManager.Models.ManagedResourceReference] managedResources {get;set;}
managedResourcesString Property   string managedResourcesString {get;}
name                   Property   string name {get;set;}
parameters             Property   System.Object parameters {get;set;}
parametersLink         Property   Microsoft.Azure.Management.ResourceManager.Models.DeploymentStacksParametersLink parametersLink {get;set;}
provisioningState      Property   string provisioningState {get;set;}
snapshotId             Property   string snapshotId {get;set;}
systemData             Property   Microsoft.Azure.Management.ResourceManager.Models.SystemData systemData {get;set;}
template               Property   System.Object template {get;set;}
templateLink           Property   Microsoft.Azure.Management.ResourceManager.Models.DeploymentStacksTemplateLink templateLink {get;set;}
type                   Property   string type {get;set;}
updateBehavior         Property   string updateBehavior {get;set;}

However with the snapshots it's a collection and it's not unrolling the object when it is returned.

Get-AzResourceGroupDeploymentStackSnapshot -ResourceGroupName $rg -StackName TEST01 -ov snapshot

Id                : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deploymentStacks/TEST01/snapshots/2021-10-24-22-29-43-5d167
Name              : 2021-10-24-22-29-43-5d167
ProvisioningState : succeeded
UpdateBehavior    : detachResources
CreationTime(UTC) : 10/24/2021 10:29:42 PM
DeploymentId      : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deployments/TEST01-2021-10-24-22-29-43-5d167

...
...
...

Id                : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deploymentStacks/TEST01/snapshots/2021-10-24-22-41-09-403d1
Name              : 2021-10-24-22-41-09-403d1
ProvisioningState : succeeded
UpdateBehavior    : detachResources
CreationTime(UTC) : 10/24/2021 10:41:09 PM
ManagedResources  : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Storage/storageAccounts/footeststorage54
DeploymentId      : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/TEST/providers/Microsoft.Resources/deployments/TEST01-2021-10-24-22-41-09-403d1

Get-AzResourceGroupDeploymentStackSnapshot -ResourceGroupName $rg -StackName TEST01 -ov snapshot | measure

Count             : 1

Get-AzResourceGroupDeploymentStackSnapshot -ResourceGroupName $rg -StackName TEST01 -ov snapshot | get-member

   TypeName: System.Collections.Generic.List`1[[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot, Microsoft.Azure.PowerShell.Cmdlets.ResourceManager, Version=4.3.1.0, Culture=neutral, PublicKeyToken=null]]

Name           MemberType            Definition
----           ----------            ----------
Add            Method                void Add(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), void ICollection[PSDeploymentStackSnapshot].Add(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), i… 
AddRange       Method                void AddRange(System.Collections.Generic.IEnumerable[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] collection)
AsReadOnly     Method                System.Collections.ObjectModel.ReadOnlyCollection[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] AsReadOnly()
BinarySearch   Method                int BinarySearch(int index, int count, Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item, System.Collections.Generic.IComparer[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStac… 
Clear          Method                void Clear(), void ICollection[PSDeploymentStackSnapshot].Clear(), void IList.Clear()
Contains       Method                bool Contains(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), bool ICollection[PSDeploymentStackSnapshot].Contains(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapsho… 
ConvertAll     Method                System.Collections.Generic.List[TOutput] ConvertAll[TOutput](System.Converter[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot,TOutput] converter)
CopyTo         Method                void CopyTo(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot[] array), void CopyTo(int index, Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot[] array, int arrayIndex, in… 
Equals         Method                bool Equals(System.Object obj)
Exists         Method                bool Exists(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
Find           Method                Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot Find(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
FindAll        Method                System.Collections.Generic.List[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] FindAll(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
FindIndex      Method                int FindIndex(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match), int FindIndex(int startIndex, System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymen…
FindLast       Method                Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot FindLast(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
FindLastIndex  Method                int FindLastIndex(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match), int FindLastIndex(int startIndex, System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSD… 
ForEach        Method                void ForEach(System.Action[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] action)
GetEnumerator  Method                System.Collections.Generic.List`1+Enumerator[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] GetEnumerator(), System.Collections.Generic.IEnumerator[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkMod… 
GetHashCode    Method                int GetHashCode()
GetRange       Method                System.Collections.Generic.List[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] GetRange(int index, int count)
GetType        Method                type GetType()
IndexOf        Method                int IndexOf(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), int IndexOf(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item, int index), int IndexOf(Microsoft.A… 
Insert         Method                void Insert(int index, Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), void IList[PSDeploymentStackSnapshot].Insert(int index, Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeployment… 
InsertRange    Method                void InsertRange(int index, System.Collections.Generic.IEnumerable[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] collection)
LastIndexOf    Method                int LastIndexOf(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), int LastIndexOf(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item, int index), int LastIndexOf… 
Remove         Method                bool Remove(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot item), bool ICollection[PSDeploymentStackSnapshot].Remove(Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot it… 
RemoveAll      Method                int RemoveAll(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
RemoveAt       Method                void RemoveAt(int index), void IList[PSDeploymentStackSnapshot].RemoveAt(int index), void IList.RemoveAt(int index)
RemoveRange    Method                void RemoveRange(int index, int count)
Reverse        Method                void Reverse(), void Reverse(int index, int count)
Sort           Method                void Sort(), void Sort(System.Collections.Generic.IComparer[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] comparer), void Sort(int index, int count, System.Collections.Generic.IComparer[Microsoft.Azure.…
ToArray        Method                Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot[] ToArray()
ToString       Method                string ToString()
TrimExcess     Method                void TrimExcess()
TrueForAll     Method                bool TrueForAll(System.Predicate[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot] match)
Item           ParameterizedProperty Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot Item(int index) {get;set;}
Capacity       Property              int Capacity {get;set;}
Count          Property              int Count {get;}
IsFixedSize    Property              bool IsFixedSize {get;}
IsReadOnly     Property              bool IsReadOnly {get;}
IsSynchronized Property              bool IsSynchronized {get;}
SyncRoot       Property              System.Object SyncRoot {get;}

This is not expected behavior ...

Same example with Storage Cmdlets

Get-AzStorageAccount

StorageAccountName      ResourceGroupName  PrimaryLocation SkuName        Kind      AccessTier CreationTime           ProvisioningState EnableHttpsTrafficOnly LargeFileShares
------------------      -----------------  --------------- -------        ----      ---------- ------------           ----------------- ---------------------- ---------------
aeu2brwaoap0sadiag      AEU2-BRW-AOA-RG-P0 eastus2         Standard_LRS   StorageV2 Hot        2/16/2021 2:01:09 AM   Succeeded         True
...
...
acu1brwaoad2sadiag      ACU1-BRW-AOA-RG-D2 centralus       Standard_LRS   StorageV2 Hot        9/15/2021 1:26:45 AM   Succeeded         True

Get-AzStorageAccount | measure

Count             : 14

Get-AzStorageAccount | get-member

   TypeName: Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount

Name                        MemberType Definition
----                        ---------- ----------
Equals                      Method     bool Equals(System.Object obj)
GetHashCode                 Method     int GetHashCode()
GetType                     Method     type GetType()
ToString                    Method     string ToString()
AccessTier                  Property   System.Nullable[Microsoft.Azure.Management.Storage.Models.AccessTier] AccessTier {get;set;}
AllowBlobPublicAccess       Property   System.Nullable[bool] AllowBlobPublicAccess {get;set;}
AllowCrossTenantReplication Property   System.Nullable[bool] AllowCrossTenantReplication {get;set;}
AllowSharedKeyAccess        Property   System.Nullable[bool] AllowSharedKeyAccess {get;set;}
AzureFilesIdentityBasedAuth Property   Microsoft.Azure.Commands.Management.Storage.Models.PSAzureFilesIdentityBasedAuthentication AzureFilesIdentityBasedAuth {get;set;}
BlobRestoreStatus           Property   Microsoft.Azure.Commands.Management.Storage.Models.PSBlobRestoreStatus BlobRestoreStatus {get;set;}
Context                     Property   Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext Context {get;}
CreationTime                Property   System.Nullable[datetime] CreationTime {get;set;}
CustomDomain                Property   Microsoft.Azure.Commands.Management.Storage.Models.PSCustomDomain CustomDomain {get;set;}
EnableHierarchicalNamespace Property   System.Nullable[bool] EnableHierarchicalNamespace {get;set;}
EnableHttpsTrafficOnly      Property   System.Nullable[bool] EnableHttpsTrafficOnly {get;set;}
EnableNfsV3                 Property   System.Nullable[bool] EnableNfsV3 {get;set;}
Encryption                  Property   Microsoft.Azure.Management.Storage.Models.Encryption Encryption {get;set;}
ExtendedLocation            Property   Microsoft.Azure.Commands.Management.Storage.Models.PSExtendedLocation ExtendedLocation {get;set;}
ExtendedProperties          Property   System.Collections.Generic.IDictionary[string,string] ExtendedProperties {get;}
FailoverInProgress          Property   System.Nullable[bool] FailoverInProgress {get;set;}
GeoReplicationStats         Property   Microsoft.Azure.Commands.Management.Storage.Models.PSGeoReplicationStats GeoReplicationStats {get;set;}
Id                          Property   string Id {get;set;}
Identity                    Property   Microsoft.Azure.Management.Storage.Models.Identity Identity {get;set;}
KeyCreationTime             Property   Microsoft.Azure.Commands.Management.Storage.Models.PSKeyCreationTime KeyCreationTime {get;set;}
KeyPolicy                   Property   Microsoft.Azure.Management.Storage.Models.KeyPolicy KeyPolicy {get;}
Kind                        Property   string Kind {get;set;}
LargeFileSharesState        Property   string LargeFileSharesState {get;set;}
LastGeoFailoverTime         Property   System.Nullable[datetime] LastGeoFailoverTime {get;set;}
Location                    Property   string Location {get;set;}
MinimumTlsVersion           Property   string MinimumTlsVersion {get;set;}
NetworkRuleSet              Property   Microsoft.Azure.Commands.Management.Storage.Models.PSNetworkRuleSet NetworkRuleSet {get;set;}
PrimaryEndpoints            Property   Microsoft.Azure.Management.Storage.Models.Endpoints PrimaryEndpoints {get;set;}
PrimaryLocation             Property   string PrimaryLocation {get;set;}
ProvisioningState           Property   System.Nullable[Microsoft.Azure.Management.Storage.Models.ProvisioningState] ProvisioningState {get;set;}
PublicNetworkAccess         Property   string PublicNetworkAccess {get;set;}
ResourceGroupName           Property   string ResourceGroupName {get;set;}
RoutingPreference           Property   Microsoft.Azure.Commands.Management.Storage.Models.PSRoutingPreference RoutingPreference {get;set;}
SasPolicy                   Property   Microsoft.Azure.Management.Storage.Models.SasPolicy SasPolicy {get;}
SecondaryEndpoints          Property   Microsoft.Azure.Management.Storage.Models.Endpoints SecondaryEndpoints {get;set;}
SecondaryLocation           Property   string SecondaryLocation {get;set;}
Sku                         Property   Microsoft.Azure.Commands.Management.Storage.Models.PSSku Sku {get;set;}
StatusOfPrimary             Property   System.Nullable[Microsoft.Azure.Management.Storage.Models.AccountStatus] StatusOfPrimary {get;set;}
StatusOfSecondary           Property   System.Nullable[Microsoft.Azure.Management.Storage.Models.AccountStatus] StatusOfSecondary {get;set;}
StorageAccountName          Property   string StorageAccountName {get;set;}
Tags                        Property   System.Collections.Generic.IDictionary[string,string] Tags {get;set;}

Types or returns

psdeploymentstack

TypeName: Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStack

psdeploymentstacksnapshot

TypeName: System.Collections.Generic.List`1[[Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSDeploymentStackSnapshot, Microsoft.Azure.PowerShell.Cmdlets.ResourceManager, Version=4.3.1.0, Culture=neutral, PublicKeyToken=null]]

storage

TypeName: Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount

What this breaks


# works correctly
Get-AzStorageAccount | select -last 1 

StorageAccountName ResourceGroupName PrimaryLocation SkuName      Kind      AccessTier CreationTime           ProvisioningState EnableHttpsTrafficOnly LargeFileShares
------------------ ----------------- --------------- -------      ----      ---------- ------------           ----------------- ---------------------- ---------------
footeststorage545  TEST              centralus       Standard_LRS StorageV2 Hot        10/24/2021 11:11:06 PM Succeeded         True

# does not work correctly
Get-AzResourceGroupDeploymentStackSnapshot -ResourceGroupName $rg -StackName TEST01 -ov snapshot | select -last 1

returns all of them, not the last 1

Above does not work with the snapshots, it returns ALL of them.

Other pipeline Cmdlets will also not work e.g. filtering and sorting.

e.g. works correctly with deployments, however this would not work with the snapshots.

Get-AzResourceGroupDeployment -ResourceGroupName TEST | select -first 2 -Property DeploymentName,Timestamp    

DeploymentName                   Timestamp
--------------                   ---------
TEST01-2021-10-24-23-11-00-3a73c 10/24/2021 11:11:28 PM
TEST01-2021-10-24-23-07-57-83e8f 10/24/2021 11:08:02 PM
Xynoclafe commented 2 years ago

Thanks for bringing it to our attention @brwilkinson. We are looking into it. Another clarification though - as it is right now, this problem seems to affect both deploymentstacks and snapshots cmdlets. The examples you provided for stacks makes a GET call and fetches a specific stack while the example for snapshots makes a LIST call on all the snapshots of that stack, which is why you noticed the difference in their return types and members.

brwilkinson commented 2 years ago

Oh sure thanks, I didn't test the returning multiple stacks. Thanks for the update.

Xynoclafe commented 2 years ago

@brwilkinson this release should have fixed this issue - https://github.com/Azure/deployment-stacks/releases/tag/v0.1.1 fyi -Select -first and -Select-Object -first can still cause some issues, I am still looking into that, but the return object should be unrolling now and every other operation should go about smoothly.

brwilkinson commented 2 years ago

Thanks @Xynoclafe I'll pull down the update.

bmoore-msft commented 2 years ago

@brwilkinson - did you get a chance to verify this?

brwilkinson commented 2 years ago

You can close it, I will do a round 2 of testing.

bmoore-msft commented 2 years ago

SGTM