Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added dependency support to azure #1450

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions providers/azure/compute/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.R
ResourceId: *snapshot.ID,
Cost: 0,
Name: *snapshot.Name,
Relations: getSnapshotRelation(snapshot),
FetchedAt: time.Now(),
Tags: tags,
CreatedAt: *snapshot.Properties.TimeCreated,
Expand All @@ -62,3 +63,29 @@ func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.R
}).Info("Fetched resources")
return resources, nil
}

func getSnapshotRelation(snp *armcompute.Snapshot) []models.Link {
var rel []models.Link

if snp.Properties.CreationData != nil {
if snp.Properties.CreationData.ImageReference != nil && snp.Properties.CreationData.ImageReference.ID != nil {
rel = append(rel, models.Link{
ResourceID: *snp.Properties.CreationData.ImageReference.ID,
Type: "Image",
Name: *snp.Properties.CreationData.ImageReference.ID,
Relation: "USES",
})
}

if snp.Properties.CreationData.SourceResourceID != nil {
rel = append(rel, models.Link{
ResourceID: *snp.Properties.CreationData.SourceResourceID,
Type: "Disk",
Name: *snp.Properties.CreationData.SourceResourceID,
Relation: "USES",
})
}

}
return rel
}
27 changes: 27 additions & 0 deletions providers/azure/compute/virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]mo
Cost: cost,
Name: *vm.Name,
FetchedAt: time.Now(),
Relations: getVmRelation(vm),
Tags: tags,
Link: fmt.Sprintf("https://portal.azure.com/#resource%s", *vm.ID),
})
Expand All @@ -87,3 +88,29 @@ func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]mo
}).Info("Fetched resources")
return resources, nil
}

func getVmRelation(vm *armcompute.VirtualMachine) []models.Link {

var rel []models.Link

if vm.Properties.StorageProfile != nil && vm.Properties.StorageProfile.DataDisks != nil {
for _, disk := range vm.Properties.StorageProfile.DataDisks {
rel = append(rel, models.Link{
ResourceID: *disk.ManagedDisk.ID,
Type: "Disk",
Name: *disk.Name,
Relation: "USES",
})
}

if vm.Properties.StorageProfile.ImageReference != nil {
rel = append(rel, models.Link{
ResourceID: *vm.Properties.StorageProfile.ImageReference.ID,
Type: "Image",
Name: *vm.Properties.StorageProfile.ImageReference.ID,
Relation: "USES",
})
}
}
return rel
}
Loading