microsoft / finops-toolkit

Tools and resources to help you adopt and implement FinOps capabilities that automate and extend the Microsoft Cloud.
https://aka.ms/finops/toolkit
MIT License
304 stars 104 forks source link

[PowerShell] Get-FinOpsHub – Get all resources based on name #341

Open flanakin opened 1 year ago

flanakin commented 1 year ago

📝 Scenario

As a hub admin, I need to get metadata about a hub instance with all dependant resources in order to manage delete all resources

💎 Solution

Update Get-FinOpsHub command to get all related resources.

Synopsis, syntax, description, and parameters stay the same. The only thing that changes is the output.

ℹ️ Additional info

Use the following code to get any addtional resources that were not identified via the tag:

$kv = $hub.Resources | Where-Object ResourceType -eq "Microsoft.KeyVault/vaults"
$uniqueId = $kv[0].Substring($kv[0].LastIndexOf("-") + 1)

$resources = Get-AzResource -ResourceGroupName $ResourceGroup | Where-Object Name -like "*$uniqueId*"

The output object should look this:

{
  // ID is added as a cm-resource-parent tag to all deployed resources as part of the bicep code
  Id: "/subscriptions/.../resourceGroups/.../providers/Microsoft.Cloud/hubs/...",

  // Type and name can be parsed out of the ID
  Type: "Microsoft.Cloud/hubs",
  Name: "...",

  // Location would be pulled from the resources
  Location: "...",

  // Version pulled from settings.json
  Version: "0.0.1",

  // Resources determined at runtime via tags or with the unique deployment id in the name
  Resources: [
    { ... },
    { ... },
    { ... },
    ...
  ],
}

🙋‍♀️ Ask for the community

We could use your help:

  1. Please vote this issue up (👍) to prioritize it.
  2. Leave comments to help us solidify the vision.
Springstone commented 1 year ago

@aromano2 wrote a handy module to extract the unique identifier from all the resources as part of the hub. I've implemented this in the remove-finopshub module, so this is no longer required for delete.

prjelesi commented 1 year ago

@flanakin i just sync with @Springstone - just to confirm that we are doing this?