finops-toolkit icon indicating copy to clipboard operation
finops-toolkit copied to clipboard

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

Open flanakin opened this issue 2 years ago â€ĸ 2 comments

📝 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.

flanakin avatar Sep 19 '23 16:09 flanakin

@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.

Springstone avatar Sep 22 '23 10:09 Springstone

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

prjelesi avatar Oct 02 '23 08:10 prjelesi