Skip to content

Commit

Permalink
RG mode: uses azlist with rg included, with special handling for em…
Browse files Browse the repository at this point in the history
…pty rg (#574)
  • Loading branch information
magodo authored Nov 11, 2024
1 parent 986322f commit 6478cf6
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/meta/meta_rg.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (meta MetaResourceGroup) queryResourceSet(ctx context.Context, rg string) (
ClientOpt: meta.azureSDKClientOpt,
Parallelism: meta.parallelism,
Recursive: true,
IncludeResourceGroup: false,
IncludeResourceGroup: true,
ExtensionResourceTypes: extBuilder{includeRoleAssignment: meta.includeRoleAssignment}.Build(),
}
lister, err := azlist.NewLister(opt)
Expand All @@ -117,13 +117,16 @@ func (meta MetaResourceGroup) queryResourceSet(ctx context.Context, rg string) (
rl = append(rl, res)
}

// Especially, adding the resoruce group itself to the resource set
rl = append(rl,
resourceset.AzureResource{Id: &armid.ResourceGroup{
SubscriptionId: meta.subscriptionId,
Name: meta.resourceGroup,
}},
)
// Especially, if there is no resource within the resource group, the azlist will return an empty list.
// In this case, we'll have to add the resource group manually.
if len(rl) == 0 {
rl = append(rl,
resourceset.AzureResource{Id: &armid.ResourceGroup{
SubscriptionId: meta.subscriptionId,
Name: meta.resourceGroup,
}},
)
}

return &resourceset.AzureResourceSet{Resources: rl}, nil
}

0 comments on commit 6478cf6

Please sign in to comment.