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
282 stars 93 forks source link

[Hubs] Switch to a deployment stack #334

Open flanakin opened 1 year ago

flanakin commented 1 year ago

⚠ī¸ Problem

Resources are being left behind as we move from one version to the next when using Azure deployment templates.

🛠ī¸ Solution

Switch to deployment stacks, which can clean up removed resources.

ℹī¸ Additional context

See https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-stacks?tabs=azure-powershell

🙋‍♀ī¸ 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 commented 12 months ago

Deployment stacks require a JSON template, so here's how I tested this...

  1. cd src/scripts
  2. ./Build-Toolkit finops-hub
  3. cd ../../release/finops-hub
  4. bicep build main.bicep
  5. mv main.bicep ../../src/templates/finops-hub/test
  6. In VS Code, edit the finops-hub/test/main.bicep file to be:

    targetScope = 'resourceGroup'
    
    param uniqueName string = 'ftk-hub-localtest1'
    param location string = 'westus2'
    
    resource stack 'Microsoft.Resources/deploymentStacks@2022-08-01-preview' = {
     name: 'stack-test'
     properties: {
       deploymentScope: resourceGroup().id
       description: 'FinOps hub'
       template: loadJsonContent('./main.json')
       parameters: {
         hubName: uniqueName
         location: location
       }
       actionOnUnmanage: {
         resources: 'delete'
       }
       denySettings: {
         mode: 'denyWriteAndDelete'
       }
     }
    }
    
    output hubName string = stack.id
  7. cd ../../src/scripts
  8. ./Deploy-Toolkit finops-hub -Test

Deployment is spinning forever, but if you look at the operation details in the deployment, you can see this error: Resource Provider has encountered an internal server error. Diagnostic information: timestamp '2023-10-05 09:16:09Z', request ID '5646a3c6-a259-43f0-8932-e4caf9b465e1', request correlation ID '02ef0d4d-6b56-4721-b9fc-3fe8c8465719'.

We'll need to try again in a future release. Seems it's not ready yet.