From 1cb689ad95ff00aae4f6cc0a41b63e8f98f0cd20 Mon Sep 17 00:00:00 2001
From: Aditya Thebe <contact@adityathebe.com>
Date: Tue, 21 May 2024 19:05:38 +0545
Subject: [PATCH] fix: use subscription as the root for azure scrapers

---
 db/update.go            |  2 +-
 scrapers/azure/azure.go | 16 +---------------
 2 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/db/update.go b/db/update.go
index 8a5bd59a..65fedb04 100644
--- a/db/update.go
+++ b/db/update.go
@@ -839,7 +839,7 @@ func setConfigPaths(ctx api.ScrapeContext, tree graph.Graph[string, string], roo
 
 func isTreeRoot(configType string) bool {
 	switch configType {
-	case "AWS::::Account", "Kubernetes::Cluster", "Azure::Tenant":
+	case "AWS::::Account", "Kubernetes::Cluster", "Azure::Subscription":
 		return true
 	}
 
diff --git a/scrapers/azure/azure.go b/scrapers/azure/azure.go
index a7cb69b2..cfd27adb 100644
--- a/scrapers/azure/azure.go
+++ b/scrapers/azure/azure.go
@@ -35,7 +35,6 @@ const (
 	ConfigTypePrefix         = "Azure::"
 	defaultActivityLogMaxage = time.Hour * 24 * 7
 
-	ResourceTypeTenant       = "Tenant"
 	ResourceTypeSubscription = "Subscription"
 )
 
@@ -137,15 +136,6 @@ func (azure Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults {
 		azure.config = &config
 		azure.cred = cred
 
-		// Craft a result for the tenant.
-		results = append(results, v1.ScrapeResult{
-			ID:          config.TenantID,
-			Type:        getARMType(lo.ToPtr(ResourceTypeTenant)),
-			BaseScraper: config.BaseScraper,
-			ConfigClass: "Tenant",
-			Config:      map[string]any{"id": config.TenantID},
-		})
-
 		// We fetch resource groups first as they are used to fetch further resources
 		results = append(results, azure.fetchResourceGroups()...)
 		results = append(results, azure.fetchVirtualMachines()...)
@@ -186,12 +176,8 @@ func (azure Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults {
 			// Set parents where missing
 			if results[i].ParentExternalID == "" {
 				switch results[i].Type {
-				case getARMType(lo.ToPtr(ResourceTypeTenant)):
-					continue // root
-
 				case getARMType(lo.ToPtr(ResourceTypeSubscription)):
-					results[i].ParentExternalID = config.TenantID
-					results[i].ParentType = getARMType(lo.ToPtr(ResourceTypeTenant))
+					continue // root
 
 				default:
 					subscriptionID := strings.Split(results[i].ID, "/")[2]