@@ -20,6 +20,7 @@ internal sealed class ResourceExportVisitor
20
20
private const string PROPERTY_ZONES = "zones" ;
21
21
private const string PROPERTY_RESOURCES = "resources" ;
22
22
private const string PROPERTY_SUBSCRIPTIONID = "subscriptionId" ;
23
+ private const string PROPERTY_RESOURCEGROUPNAME = "resourceGroupName" ;
23
24
private const string PROPERTY_KIND = "kind" ;
24
25
private const string PROPERTY_SHAREDKEY = "sharedKey" ;
25
26
private const string PROPERTY_NETWORKPROFILE = "networkProfile" ;
@@ -128,8 +129,8 @@ private async Task<bool> ExpandResource(IResourceExportContext context, JObject
128
129
129
130
var resourceContext = new ResourceContext ( context , tenantId ) ;
130
131
131
- // Set the subscription Id .
132
- SetSubscriptionId ( resource , resourceId ) ;
132
+ // Set subscriptionId and resourceGroupName .
133
+ SetResourceIdentifiers ( resource , resourceType , resourceId ) ;
133
134
134
135
// Ignore expand of these.
135
136
if ( string . Equals ( resourceType , TYPE_VISUALSTUDIO_ACCOUNT , StringComparison . OrdinalIgnoreCase ) )
@@ -181,9 +182,16 @@ private async Task GetProperties(ResourceContext context, JObject resource, stri
181
182
resource . Add ( PROPERTY_PROPERTIES , properties ) ;
182
183
}
183
184
184
- private static void SetSubscriptionId ( JObject resource , string resourceId )
185
+ /// <summary>
186
+ /// Set <c>subscriptionId</c> and <c>resourceGroupName</c> on the resource based on the provided <c>resourceId</c>.
187
+ /// </summary>
188
+ private static void SetResourceIdentifiers ( JObject resource , string resourceType , string resourceId )
185
189
{
186
- if ( ResourceHelper . TrySubscriptionId ( resourceId , out var subscriptionId ) )
190
+ if ( ResourceHelper . TryResourceGroup ( resourceId , out var subscriptionId , out var resourceGroupName ) &&
191
+ ! string . Equals ( resourceType , TYPE_RESOURCES_RESOURCEGROUP , StringComparison . OrdinalIgnoreCase ) )
192
+ resource . Add ( PROPERTY_RESOURCEGROUPNAME , resourceGroupName ) ;
193
+
194
+ if ( ! string . IsNullOrEmpty ( subscriptionId ) )
187
195
resource . Add ( PROPERTY_SUBSCRIPTIONID , subscriptionId ) ;
188
196
}
189
197
0 commit comments