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

[Hubs] Switch to a deployment stack

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

âš ī¸ 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 avatar Sep 16 '23 18:09 flanakin

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.

flanakin avatar Oct 05 '23 09:10 flanakin