-
Notifications
You must be signed in to change notification settings - Fork 30
Provision Azure Managed Grafana workspace #6304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cdc0c92
fb7997d
e13fb60
03b5d4f
4a5ed6d
ec7b956
28e0eda
a5805d6
5424b0c
e0004fc
0ef9267
0382325
e8a9e30
aa6018d
ac429bd
5683982
340831d
c76bcc4
eed1aed
90cdefc
f533797
a074e78
7fc2c34
2273352
b5ea9ca
ccc335f
6ff2dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| parameters: | ||
| - name: ServiceConnectionName | ||
| type: string | ||
| - name: ServiceConnectionClientId | ||
| type: string | ||
| - name: ServiceConnectionId | ||
| type: string | ||
| - name: DeploymentEnvironment | ||
| type: string | ||
| - name: GrafanaWorkspaceName | ||
| type: string | ||
| - name: GrafanaKeyVault | ||
| type: string | ||
| - name: GrafanaVariableGroup | ||
| type: string | ||
|
|
||
| stages: | ||
| - stage: ProvisionGrafana | ||
| displayName: 'Provision Grafana Infrastructure' | ||
| dependsOn: | ||
| - predeploy | ||
| - approval | ||
| jobs: | ||
| - template: /eng/provision-grafana.yaml@self | ||
| parameters: | ||
| DeploymentEnvironment: ${{ parameters.DeploymentEnvironment }} | ||
| ServiceConnectionName: ${{ parameters.ServiceConnectionName }} | ||
| GrafanaResourceGroup: 'monitoring-managed' | ||
| GrafanaWorkspaceName: ${{ parameters.GrafanaWorkspaceName }} | ||
| GrafanaLocation: 'westus2' | ||
| GrafanaKeyVault: ${{ parameters.GrafanaKeyVault }} | ||
| GrafanaVariableGroup: ${{ parameters.GrafanaVariableGroup }} |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any thoughts about using this file (or at least this pattern) to also deploy all the things necessary for Grafana? Like the keyvaults, identities and their permissions?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None currently. I can start working on this |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Azure Managed Grafana Workspace Bicep Template | ||
| @description('The Azure region where the Grafana workspace will be deployed') | ||
| param location string | ||
|
|
||
| @description('The name of the Grafana workspace') | ||
| param grafanaWorkspaceName string | ||
|
|
||
| @description('The pricing tier for the Grafana workspace') | ||
| @allowed([ | ||
| 'Standard' | ||
| 'Essential' | ||
| ]) | ||
| param skuName string = 'Standard' | ||
|
|
||
| // Azure Managed Grafana Workspace | ||
| resource grafanaWorkspace 'Microsoft.Dashboard/grafana@2023-09-01' = { | ||
| name: grafanaWorkspaceName | ||
| location: location | ||
| sku: { | ||
| name: skuName | ||
| } | ||
| identity: { | ||
| type: 'SystemAssigned' | ||
| } | ||
| properties: { | ||
| deterministicOutboundIP: 'Enabled' | ||
| apiKey: 'Enabled' | ||
| autoGeneratedDomainNameLabelScope: 'TenantReuse' | ||
| zoneRedundancy: 'Disabled' | ||
| publicNetworkAccess: 'Enabled' | ||
| grafanaIntegrations: { | ||
| azureMonitorWorkspaceIntegrations: [] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Output the Grafana workspace details | ||
| output grafanaWorkspaceId string = grafanaWorkspace.id | ||
| output grafanaWorkspaceName string = grafanaWorkspace.name | ||
| output grafanaWorkspaceUrl string = grafanaWorkspace.properties.endpoint | ||
| output grafanaPrincipalId string = grafanaWorkspace.identity.principalId | ||
| output grafanaTenantId string = grafanaWorkspace.identity.tenantId | ||
| output grafanaWorkspaceLocation string = grafanaWorkspace.location |
haruna99 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Azure Managed Grafana Deployment Script | ||
| # This script deploys an Azure Managed Grafana workspace using Bicep | ||
|
|
||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$SubscriptionId, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$ResourceGroupName, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$Location, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$GrafanaWorkspaceName, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [string]$DeploymentName = "grafana-deployment-$(Get-Date -Format 'yyyyMMdd-HHmmss')", | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [switch]$WhatIf = $false | ||
| ) | ||
|
|
||
| # Set error action preference | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| Write-Host "=======================================" -ForegroundColor Cyan | ||
| Write-Host "Azure Managed Grafana Deployment Script" -ForegroundColor Cyan | ||
| Write-Host "=======================================" -ForegroundColor Cyan | ||
|
|
||
| try { | ||
| # Check if Azure CLI is installed | ||
| Write-Host "Checking Azure CLI installation..." -ForegroundColor Yellow | ||
| az version 2>$null | Out-Null | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Azure CLI is not installed or not in PATH. Please install Azure CLI first." | ||
| } | ||
| Write-Host "✓ Azure CLI is installed" -ForegroundColor Green | ||
|
|
||
| # Check if user is logged in | ||
| Write-Host "Checking Azure authentication..." -ForegroundColor Yellow | ||
| $account = az account show 2>$null | ConvertFrom-Json | ||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "Not logged in to Azure. Please login..." -ForegroundColor Yellow | ||
| az login | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to login to Azure" | ||
| } | ||
| } | ||
| Write-Host "✓ Authenticated as: $($account.user.name)" -ForegroundColor Green | ||
|
|
||
| # Set the subscription | ||
| Write-Host "Setting subscription to: $SubscriptionId" -ForegroundColor Yellow | ||
| az account set --subscription $SubscriptionId | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to set subscription. Please check if the subscription ID is correct and you have access." | ||
| } | ||
| Write-Host "✓ Subscription set successfully" -ForegroundColor Green | ||
|
|
||
| # Check if resource group exists, create if it doesn't | ||
| Write-Host "Checking if resource group '$ResourceGroupName' exists..." -ForegroundColor Yellow | ||
| az group show --name $ResourceGroupName 2>$null | Out-Null | ||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "Resource group doesn't exist. Creating..." -ForegroundColor Yellow | ||
| az group create --name $ResourceGroupName --location $Location | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Failed to create resource group" | ||
| } | ||
| Write-Host "✓ Resource group created successfully" -ForegroundColor Green | ||
| } else { | ||
| Write-Host "✓ Resource group already exists" -ForegroundColor Green | ||
| } | ||
|
|
||
| # Get the Bicep file path | ||
| $bicepFile = Join-Path $PSScriptRoot "azure-managed-grafana.bicep" | ||
| if (!(Test-Path $bicepFile)) { | ||
| throw "Bicep file not found at: $bicepFile" | ||
| } | ||
| Write-Host "✓ Bicep file found: $bicepFile" -ForegroundColor Green | ||
|
|
||
| # Prepare deployment parameters | ||
| $parameters = @{ | ||
| location = $Location | ||
| grafanaWorkspaceName = $GrafanaWorkspaceName | ||
| skuName = "Standard" | ||
| } | ||
|
|
||
| # Convert parameters to string format for Azure CLI | ||
| $paramString = ($parameters.GetEnumerator() | ForEach-Object { "$($_.Key)=`"$($_.Value)`"" }) -join " " | ||
|
|
||
| # Run deployment | ||
| if ($WhatIf) { | ||
| Write-Host "Running what-if deployment..." -ForegroundColor Yellow | ||
| $cmd = "az deployment group what-if --resource-group $ResourceGroupName --template-file `"$bicepFile`" --parameters $paramString" | ||
| Write-Host "Command: $cmd" -ForegroundColor Gray | ||
| Invoke-Expression $cmd | ||
| } else { | ||
| Write-Host "Starting deployment..." -ForegroundColor Yellow | ||
| Write-Host "Deployment name: $DeploymentName" -ForegroundColor Gray | ||
| Write-Host "Resource group: $ResourceGroupName" -ForegroundColor Gray | ||
| Write-Host "Grafana workspace name: $GrafanaWorkspaceName" -ForegroundColor Gray | ||
|
|
||
| $cmd = "az deployment group create --resource-group $ResourceGroupName --name $DeploymentName --template-file `"$bicepFile`" --parameters $paramString" | ||
| Write-Host "Command: $cmd" -ForegroundColor Gray | ||
|
|
||
| $result = Invoke-Expression $cmd | ConvertFrom-Json | ||
|
|
||
| if ($LASTEXITCODE -eq 0) { | ||
| Write-Host "=======================================" -ForegroundColor Green | ||
| Write-Host "✓ Deployment completed successfully!" -ForegroundColor Green | ||
| Write-Host "=======================================" -ForegroundColor Green | ||
|
|
||
| # Display outputs | ||
| if ($result.properties.outputs) { | ||
| Write-Host "Deployment Outputs:" -ForegroundColor Cyan | ||
| $result.properties.outputs | ConvertTo-Json -Depth 3 | Write-Host | ||
| } | ||
|
|
||
| # Get the Grafana workspace details | ||
| Write-Host "`nGrafana Workspace Details:" -ForegroundColor Cyan | ||
| $grafana = az grafana show --name $GrafanaWorkspaceName --resource-group $ResourceGroupName | ConvertFrom-Json | ||
| Write-Host "Workspace Name: $($grafana.name)" -ForegroundColor White | ||
| Write-Host "Workspace URL: $($grafana.properties.endpoint)" -ForegroundColor White | ||
| Write-Host "Location: $($grafana.location)" -ForegroundColor White | ||
| Write-Host "SKU: $($grafana.sku.name)" -ForegroundColor White | ||
| Write-Host "System Managed Identity: $($grafana.identity.principalId)" -ForegroundColor White | ||
| } else { | ||
| throw "Deployment failed" | ||
| } | ||
| } | ||
| } | ||
| catch { | ||
| Write-Host "=======================================" -ForegroundColor Red | ||
| Write-Host "❌ Error occurred during deployment:" -ForegroundColor Red | ||
| Write-Host $_.Exception.Message -ForegroundColor Red | ||
| Write-Host "=======================================" -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
|
|
||
| Write-Host "`n🎉 Script completed successfully!" -ForegroundColor Green | ||
| Write-Host "You can now access your Grafana workspace and configure it as needed." -ForegroundColor Yellow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these service connections? Tell me more about them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GrafanaWorkspaceName is the name of the Grafana instance in azure.
The GrafanaKeyVault, GrafanaVariableGroup and ServiceConnectionClientId are not in use and can be deleted.