From 7acadac4b43f57d92faadf5651922c5abf1c01e6 Mon Sep 17 00:00:00 2001 From: magodo Date: Tue, 6 Feb 2024 14:35:39 +0800 Subject: [PATCH] Fix `rg` mode not export empty resource group (#500) --- internal/meta/meta_rg.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/meta/meta_rg.go b/internal/meta/meta_rg.go index 7d90e23..5d4c910 100644 --- a/internal/meta/meta_rg.go +++ b/internal/meta/meta_rg.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/aztfexport/internal/tfaddr" "github.com/Azure/aztfexport/pkg/config" "github.com/Azure/aztfexport/pkg/log" + "github.com/magodo/armid" "github.com/magodo/azlist/azlist" ) @@ -97,7 +98,7 @@ func (meta MetaResourceGroup) queryResourceSet(ctx context.Context, rg string) ( ClientOpt: meta.azureSDKClientOpt, Parallelism: meta.parallelism, Recursive: true, - IncludeResourceGroup: true, + IncludeResourceGroup: false, ExtensionResourceTypes: extBuilder{includeRoleAssignment: meta.includeRoleAssignment}.Build(), }) if err != nil { @@ -113,5 +114,13 @@ 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, + }}, + ) + return &resourceset.AzureResourceSet{Resources: rl}, nil }