Azure / ALZ-Bicep

This repository contains the Azure Landing Zones (ALZ) Bicep modules that help deliver and deploy the Azure Landing Zone conceptual architecture in a modular approach. https://aka.ms/alz/docs
MIT License
762 stars 514 forks source link

🪲 Bug Report - Resource provider registration error #594

Closed sebassem closed 1 year ago

sebassem commented 1 year ago

Describe the bug

Deploying the accelerator with a customer on new subscriptions, we got an error that the Microsoft.Insights provider is not registered on the subscription. Maybe adding a `Register-AzResourceProvider command in the Deploy-ALZMGDiagnosticSettings.ps1 script would prevent issues proactively.

To Reproduce

Steps to reproduce the behaviour:

  1. Deploy ALZ accelerator
  2. Run the alz-bicep-1-core action

Expected behaviour

The pipeline completes without errors.

Screenshots 📷

MicrosoftTeams-image

Correlation ID

A correlation ID really helps us investigate your issue further. Please provide one if possible. Details on how to find a correlation ID can be found here: Correlation ID and support

Additional context

We are using the Azure Devops pipelines

jtracey93 commented 1 year ago

Thanks @sebassem for raising, for now can you add this to the Deploy-ALZMGDiagnosticSettings.ps1 script as a workaround and also feel free to PR into this repo?

Select-AzSubscription -SubscriptionId '<Management Sub ID Here>'
Register-AzResourceProvider -ProviderNamespace 'Microsoft.Insights'

Wrap this in some logic to check if it is already assigned or not before trying to register

jtracey93 commented 1 year ago

@sebassem let us know if you want to add this in a PR or not, as if not we will find someone to get it done :)

cc: @oZakari

sebassem commented 1 year ago

@sebassem let us know if you want to add this in a PR or not, as if not we will find someone to get it done :)

cc: @oZakari

Yes Will submit one shortly

bojanmisic commented 1 year ago

Jumping in on this one, struggling whole morning :(.

We are having a new tenant, experienced problems from here - referenced #470 and #565, waited out a couple of hours, but I still can't get past this step:

New-AzManagementGroupDeployment: /home/vsts/work/1/s/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1:25
Line |
  25 |  New-AzManagementGroupDeployment @inputObject
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | 10:37:12 - The deployment
     | 'alz-MGDiagnosticSettings-20230801T1008197137Z' failed with error(s).
     | Showing 2 out of 2 error(s). Status Message: 
     | (Code:InvalidAuthenticationToken)  Status Message: At least one resource
     | deployment operation failed. Please list deployment operations for
     | details. Please see https://aka.ms/arm-deployment-operations for usage
     | details. (Code: DeploymentFailed)  - {   "code":
     | "InvalidAuthenticationToken",   "message": "" } (Code:Conflict)  
     | CorrelationId: d3c179ab-0978-4715-897a-4f856329646a

Whole log here:

2023-08-01T10:36:16.4222411Z ##[section]Starting: Custom Management Group Diagnostic Settings
2023-08-01T10:36:16.4226832Z ==============================================================================
2023-08-01T10:36:16.4226952Z Task         : Azure PowerShell
2023-08-01T10:36:16.4227034Z Description  : Run a PowerShell script within an Azure environment
2023-08-01T10:36:16.4227125Z Version      : 5.225.1
2023-08-01T10:36:16.4227183Z Author       : Microsoft Corporation
2023-08-01T10:36:16.4227251Z Help         : https://aka.ms/azurepowershelltroubleshooting
2023-08-01T10:36:16.4227347Z ==============================================================================
2023-08-01T10:36:16.8686276Z Generating script.
2023-08-01T10:36:16.8760634Z [command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command . '/home/vsts/work/_temp/c1bab709-7425-4692-b44c-f0437ab6fc35.ps1'
2023-08-01T10:36:16.8831350Z File saved!
2023-08-01T10:36:17.5035969Z ##[command]Import-Module -Name /usr/share/az_9.3.0/Az.Accounts/2.12.4/Az.Accounts.psd1 -Global
2023-08-01T10:36:18.3233241Z ##[command]Clear-AzContext -Scope Process
2023-08-01T10:36:18.4845149Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2023-08-01T10:36:18.5515519Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant REDACTED -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2023-08-01T10:36:24.9195910Z VERBOSE: Using Bicep v0.19.5
2023-08-01T10:36:28.6177600Z WARNING: /home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/modules/mgDiagSettings/mgDiagSettings.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/bicepconfig.json).
2023-08-01T10:36:28.6179265Z /home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/modules/mgDiagSettings/mgDiagSettings.bicep(15,59) : Warning use-recent-api-versions: Use more recent API version for 'Microsoft.Insights/diagnosticSettings'. '2021-05-01-preview' is 822 days old, should be no more than 730 days old, or the most recent. Acceptable versions: 2016-09-01 [https://aka.ms/bicep/linter/use-recent-api-versions]
2023-08-01T10:36:28.6180572Z /home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/orchestration/mgDiagSettingsAll/mgDiagSettingsAll.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/bicepconfig.json).
2023-08-01T10:36:28.6227819Z /home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/CRML/customerUsageAttribution/cuaIdManagementGroup.bicep(1,1) : Info Bicep Linter Configuration: Custom bicepconfig.json file found (/home/vsts/work/1/s/upstream-releases/v0.16.0/infra-as-code/bicep/bicepconfig.json).
2023-08-01T10:36:28.6431082Z VERBOSE: 
2023-08-01T10:36:31.0216693Z VERBOSE: 10:36:31 - Template is valid.
2023-08-01T10:36:32.0903148Z VERBOSE: 10:36:32 - Create template deployment 'alz-MGDiagnosticSettings-20230801T1008197137Z'
2023-08-01T10:36:32.0917702Z VERBOSE: 10:36:32 - Checking deployment status in 5 seconds
2023-08-01T10:36:42.9017865Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-decommissioned' provisioning status is running
2023-08-01T10:36:42.9019971Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9027795Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform' provisioning status is running
2023-08-01T10:36:42.9029178Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9030190Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9037384Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones-corp' provisioning status is running
2023-08-01T10:36:42.9037912Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9038962Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9039473Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones' provisioning status is running
2023-08-01T10:36:42.9039974Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9040448Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9041298Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform-connectivity' provisioning status is running
2023-08-01T10:36:42.9041865Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9042328Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw' provisioning status is running
2023-08-01T10:36:42.9042762Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9043245Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9043724Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-sandbox' provisioning status is running
2023-08-01T10:36:42.9045185Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9045700Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9053630Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones-online' provisioning status is running
2023-08-01T10:36:42.9055334Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9055933Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9058313Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform-identity' provisioning status is running
2023-08-01T10:36:42.9058955Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9059448Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9059930Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform-management' provisioning status is running
2023-08-01T10:36:42.9060453Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:42.9060921Z VERBOSE: 10:36:42 - Resource Microsoft.Insights/diagnosticSettings 'toLa' provisioning status is succeeded
2023-08-01T10:36:42.9061427Z VERBOSE: 10:36:42 - Resource Microsoft.Resources/deployments 'pid-f49c8dfb-c0ce-4ee0-b316-5e4844474dd0-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:43.0353191Z VERBOSE: 10:36:43 - Checking deployment status in 8 seconds
2023-08-01T10:36:57.0322647Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is running
2023-08-01T10:36:57.0323808Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0324932Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0325583Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0326283Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0326833Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0327327Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0327797Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0328283Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0328770Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.0329236Z VERBOSE: 10:36:57 - Resource Microsoft.Resources/deployments 'pid-f49c8dfb-c0ce-4ee0-b316-5e4844474dd0-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:36:57.1405637Z VERBOSE: 10:36:57 - Checking deployment status in 10 seconds
2023-08-01T10:37:12.3815611Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-decommissioned' provisioning status is succeeded
2023-08-01T10:37:12.3817411Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'pid-5d17f1c2-f17b-4426-9712-0cd2652c4435-lvjmfv5dzfznm' provisioning status is succeeded
2023-08-01T10:37:12.3818405Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform' provisioning status is succeeded
2023-08-01T10:37:12.3842840Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones-corp' provisioning status is succeeded
2023-08-01T10:37:12.3848480Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones' provisioning status is succeeded
2023-08-01T10:37:12.3849366Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw' provisioning status is succeeded
2023-08-01T10:37:12.3850008Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-sandbox' provisioning status is succeeded
2023-08-01T10:37:12.3850661Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-landingzones-online' provisioning status is succeeded
2023-08-01T10:37:12.3852884Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform-identity' provisioning status is succeeded
2023-08-01T10:37:12.3853603Z VERBOSE: 10:37:12 - Resource Microsoft.Resources/deployments 'mg-diag-set-rbw-platform-management' provisioning status is succeeded
2023-08-01T10:37:12.6682234Z New-AzManagementGroupDeployment: /home/vsts/work/1/s/pipeline-scripts/Deploy-ALZMGDiagnosticSettings.ps1:25
2023-08-01T10:37:12.6686450Z Line |
2023-08-01T10:37:12.6687378Z   25 |  New-AzManagementGroupDeployment @inputObject
2023-08-01T10:37:12.6687685Z      |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-08-01T10:37:12.6687985Z      | 10:37:12 - The deployment
2023-08-01T10:37:12.6688328Z      | 'alz-MGDiagnosticSettings-20230801T1008197137Z' failed with error(s).
2023-08-01T10:37:12.6688614Z      | Showing 2 out of 2 error(s). Status Message: 
2023-08-01T10:37:12.6688946Z      | (Code:InvalidAuthenticationToken)  Status Message: At least one resource
2023-08-01T10:37:12.6722259Z      | deployment operation failed. Please list deployment operations for
2023-08-01T10:37:12.6722771Z      | details. Please see https://aka.ms/arm-deployment-operations for usage
2023-08-01T10:37:12.6723116Z      | details. (Code: DeploymentFailed)  - {   "code":
2023-08-01T10:37:12.6723446Z      | "InvalidAuthenticationToken",   "message": "" } (Code:Conflict)  
2023-08-01T10:37:12.6725757Z      | CorrelationId: d3c179ab-0978-4715-897a-4f856329646a
2023-08-01T10:37:12.6726016Z 
2023-08-01T10:37:12.7779959Z ##[error]PowerShell exited with code '1'.
2023-08-01T10:37:12.7804143Z ##[section]Finishing: Custom Management Group Diagnostic Settings
bojanmisic commented 1 year ago

Found this in deployment log:

{
  "code": "DeploymentFailed",
  "target": "/providers/Microsoft.Management/managementGroups/rbw-platform-identity/providers/Microsoft.Resources/deployments/mg-diag-set-rbw-platform-identity",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
  "details": [
    {
      "code": "InvalidAuthenticationToken",
      "target": "/providers/Microsoft.Management/managementGroups/rbw-platform-identity/providers/Microsoft.Resources/deployments/mg-diag-set-rbw-platform-identity",
      "message": ""
    }
  ]
}

So, I figured out maybe I need to register Microsoft.Management provider as well:

Register-AzResourceProvider -ProviderNamespace 'Microsoft.Management'

So, this did the trick! :) Just FYI, maybe this needs to be added to the script as well.

oZakari commented 1 year ago

Included with release v0.16.1