From 59fec8130566fbade12efbf5f97067e056f20cb1 Mon Sep 17 00:00:00 2001 From: dwas01 Date: Mon, 23 Sep 2019 17:40:31 +1200 Subject: [PATCH] application.inisights module updates --- .../application.insights.akv.secrects.ps1 | 223 ------------------ ...application.insights.continuous.export.ps1 | 21 +- .../2.0/Tests/output.tests.ps1 | 18 +- .../2.0/Tests/test.parameters.json | 5 +- Modules/ApplicationInsights/2.0/deploy.json | 104 +------- Modules/ApplicationInsights/2.0/readme.md | 18 +- 6 files changed, 27 insertions(+), 362 deletions(-) delete mode 100644 Modules/ApplicationInsights/2.0/Scripts/application.insights.akv.secrects.ps1 diff --git a/Modules/ApplicationInsights/2.0/Scripts/application.insights.akv.secrects.ps1 b/Modules/ApplicationInsights/2.0/Scripts/application.insights.akv.secrects.ps1 deleted file mode 100644 index c8821ff..0000000 --- a/Modules/ApplicationInsights/2.0/Scripts/application.insights.akv.secrects.ps1 +++ /dev/null @@ -1,223 +0,0 @@ -<# - .NOTES - ============================================================================================== - Copyright(c) Microsoft Corporation. All rights reserved. - - Microsoft Consulting Services - AzureCAT - VDC Toolkit (v2.0) - - File: application.insights.akv.secrects.ps1 - - Purpose: Set Application Insights KeyVault Secrets Automation Script - - Version: 2.0.0.0 - 1st September 2019 - Azure Virtual Datacenter Development Team - ============================================================================================== - - .SYNOPSIS - Set Application Insights KeyVault Secrets Automation Script - - .DESCRIPTION - Set Application Insights KeyVault Secrets Automation Script - - Deployment steps of the script are outlined below. - 1) Set Azure KeyVault Parameters - 2) Set Application Insights Parameters - 3) Create Azure KeyVault Secret - - .PARAMETER keyVaultName - Specify the Azure KeyVault Name parameter. - - .PARAMETER appInsightsName - Specify the Application Insights Name output parameter. - - .PARAMETER appInsightsResourceId - Specify the Application Insights Resource Id output parameter. - - .PARAMETER appInsightsResourceGroup - Specify the Application Insights ResourceGroup output parameter. - - .PARAMETER appInsightsKey - Specify the Application Insights Instrumentation Key output parameter. - - .PARAMETER appInsightsAppId - Specify the Application Insights AppId output parameter. - - .PARAMETER appInsightsStorageAccountName - Specify the Application Storage Account Name output parameter. - - .EXAMPLE - Default: - C:\PS>.\application.insights.akv.secrects.ps1 - -keyVaultName "$(keyVaultName)" - -appInsightsName "$(appInsightsName)" - -appInsightsResourceId "$(appInsightsResourceId)" - -appInsightsResourceGroup "$(appInsightsResourceGroup)" - -appInsightsKey "$(appInsightsKey)" - -appInsightsAppId "$(appInsightsAppId)" - -appInsightsStorageAccountName "$(appInsightsStorageAccountName)" -#> - -#Requires -Version 5 -#Requires -Module Az.KeyVault -#Requires -Module Az.ApplicationInsights -#Requires -Module Az.Resources - -[CmdletBinding()] -param -( - [Parameter(Mandatory = $false)] - [string]$keyVaultName, - - [Parameter(Mandatory = $false)] - [string]$appInsightsName, - - [Parameter(Mandatory = $false)] - [string]$appInsightsResourceId, - - [Parameter(Mandatory = $false)] - [string]$appInsightsResourceGroup, - - [Parameter(Mandatory = $false)] - [string]$appInsightsKey, - - [Parameter(Mandatory = $false)] - [string]$appInsightsAppId, - - [Parameter(Mandatory = $false)] - [string]$appInsightsStorageAccountName -) - -#region - KeyVault Parameters -if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['keyVaultName'])) -{ - Write-Output "KeyVault Name : $keyVaultName" - $kVSecretParameters = @{ } - - #region - Analysis Services Parameters - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsName'])) - { - Write-Output "Application Insights Name: $appInsightsName" - $kVSecretParameters.Add("AppInsights--Name", $($appInsightsName)) - - #region - Application Insights - ApiKey - $paramGetAzResource = @{ - ResourceType = "Microsoft.Insights/components" - ResourceName = $appInsightsName - } - $resource = Get-AzResource @paramGetAzResource - - $paramGetAzResource = @{ - ResourceId = $resource.Id - } - $resource = Get-AzResource @paramGetAzResource - - $Random = (Get-Random -Minimum 10000 -Maximum 99999) - $paramNewAzApplicationInsightsApiKey = @{ - ResourceGroupName = $resource.ResourceGroupName - Name = $resource.Name - Description = $resource.Name + "-apikey$Random" - Permissions = @("ReadTelemetry", "WriteAnnotations") - ErrorAction = 'SilentlyContinue' - } - $apiInfo = New-AzApplicationInsightsApiKey @paramNewAzApplicationInsightsApiKey - $apiKey = $apiInfo.ApiKey - - if ( -not [string]::IsNullOrEmpty($apiKey)) - { - Write-Output "Application Insights apiKey: $apiKey" - $kVSecretParameters.Add("AppInsights--APIKey", $($apiKey)) - } - else - { - Write-Output "Application Insights apiKey: []" - } - #endregion - } - else - { - Write-Output "Application Insights Name: []" - } - - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsResourceId'])) - { - Write-Output "Application Insights ResourceId: $appInsightsResourceId" - $kVSecretParameters.Add("AppInsights--ResourceId", $($appInsightsResourceId)) - } - else - { - Write-Output "Application Insights ResourceId: []" - } - - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsResourceGroup'])) - { - Write-Output "Application Insights ResourceGroup: $appInsightsResourceGroup" - $kVSecretParameters.Add("AppInsights--ResourceGroup", $($appInsightsResourceGroup)) - } - else - { - Write-Output "Application Insights ResourceGroup: []" - } - - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsKey'])) - { - Write-Output "Application Insights (OPS) Instrumentation Key: $appInsightsOpsKey" - $kVSecretParameters.Add("AppInsights--InstrumentationKey", $($appInsightsKey)) - } - else - { - Write-Output "Application Insights Instrumentation Key: []" - } - - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsAppId'])) - { - Write-Output "Application Insights AppId: $appInsightsAppId" - $kVSecretParameters.Add("AppInsights--AppId", $($appInsightsAppId)) - } - else - { - Write-Output "Application Insights AppId: []" - } - - if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsStorageAccountName'])) - { - Write-Output "Application Insights Storage Account Name $appInsightsStorageAccountName" - $kVSecretParameters.Add("AppInsights--StorageAccountName", $($appInsightsStorageAccountName)) - } - else - { - Write-Output "Application Insights Storage Account Name []" - } - #endregion - - #region - Set Azure KeyVault Secret - $kVSecretParameters.Keys | ForEach-Object { - $key = $psitem - $value = $kVSecretParameters.Item($psitem) - - if (-not [string]::IsNullOrWhiteSpace($value)) - { - Write-Output "KeyVault Secret: $key : $value" - - $value = $kVSecretParameters.Item($psitem) - - Write-Output "Setting Secret for $key" - $paramSetAzKeyVaultSecret = @{ - VaultName = $keyVaultName - Name = $key - SecretValue = (ConvertTo-SecureString $value -AsPlainText -Force) - Verbose = $true - ErrorAction = 'SilentlyContinue' - } - Set-AzKeyVaultSecret @paramSetAzKeyVaultSecret - } - else - { - Write-Output "KeyVault Secret: []" - } - } - #endregion -} -else -{ - Write-Output "KeyVault Name: []" -} -#endregion \ No newline at end of file diff --git a/Modules/ApplicationInsights/2.0/Scripts/application.insights.continuous.export.ps1 b/Modules/ApplicationInsights/2.0/Scripts/application.insights.continuous.export.ps1 index 5d6bcd6..ea2319d 100644 --- a/Modules/ApplicationInsights/2.0/Scripts/application.insights.continuous.export.ps1 +++ b/Modules/ApplicationInsights/2.0/Scripts/application.insights.continuous.export.ps1 @@ -25,16 +25,17 @@ .PARAMETER appInsightsName Specify the Azure Application Insights Name parameter. - .PARAMETER appInsightsStorageAccountName - Specify the Application Insights Storage Account Name output parameter. + .PARAMETER storageAccountName + Specify the Storage Account Name parameter. .EXAMPLE Default: C:\PS>.\application.insights.continuous.export.ps1 -appInsightsName "$(appInsightsName)" - -appInsightsStorageAccountName "$(appInsightsStorageAccountName)" + -storageAccountName "$(storageAccountName)" #> + #Requires -Version 5 #Requires -Module Az.ApplicationInsights #Requires -Module Az.Storage @@ -47,12 +48,12 @@ param [string]$appInsightsName, [Parameter(Mandatory = $true)] - [string]$appInsightsStorageAccountName + [string]$storageAccountName ) #region - Application Insights Continuous Export Configuration -Write-Output "Application Insights Name: $appInsightsName" -Write-Output "Application Insight Storage Account Name: $appInsightsStorageAccountName" +Write-Output "Application Insights Name: $appInsightsName" +Write-Output "Storage Account Name: $storageAccountName" $paramGetAzResource = @{ ResourceType = "Microsoft.Insights/components" @@ -71,7 +72,7 @@ if (-not ($continuousExport)) { $paramGetAzResource = @{ ResourceType = "Microsoft.Storage/storageAccounts" - ResourceName = $appInsightsStorageAccountName + ResourceName = $storageAccountName } $resource = Get-AzResource @paramGetAzResource @@ -85,11 +86,11 @@ if (-not ($continuousExport)) ResourceId = $resource.ResourceId Force = $true } - $appInsightsStoragekey = (Invoke-AzResourceAction @paramInvokeAzResourceAction).keys[0].value + $storagekey = (Invoke-AzResourceAction @paramInvokeAzResourceAction).keys[0].value $paramNewAzStorageContext = @{ - StorageAccountName = $appInsightsStorageAccountName - StorageAccountKey = $appInsightsStoragekey + StorageAccountName = $storageAccountName + StorageAccountKey = $storagekey } $context = New-AzStorageContext @paramNewAzStorageContext diff --git a/Modules/ApplicationInsights/2.0/Tests/output.tests.ps1 b/Modules/ApplicationInsights/2.0/Tests/output.tests.ps1 index 357495a..5a43dfa 100644 --- a/Modules/ApplicationInsights/2.0/Tests/output.tests.ps1 +++ b/Modules/ApplicationInsights/2.0/Tests/output.tests.ps1 @@ -36,9 +36,6 @@ .PARAMETER appInsightsAppId Specify the Application Insights AppId output parameter. - .PARAMETER appInsightsStorageAccountName - Specify the Application Storage Account Name output parameter. - .EXAMPLE Default: C:\PS>.\output.tests.ps1 @@ -47,7 +44,6 @@ -appInsightsResourceGroup "$(appInsightsResourceGroup)" -appInsightsKey "$(appInsightsKey)" -appInsightsAppId "$(appInsightsAppId)" - -appInsightsStorageAccountName "$(appInsightsStorageAccountName)" #> #Requires -Version 5 @@ -68,10 +64,7 @@ param [string]$appInsightsKey, [Parameter(Mandatory = $false)] - [string]$appInsightsAppId, - - [Parameter(Mandatory = $false)] - [string]$appInsightsStorageAccountName + [string]$appInsightsAppId ) #region - Application Insights Output Tests @@ -120,13 +113,4 @@ else { Write-Output "Application Insights AppId: []" } - -if (-not [string]::IsNullOrWhiteSpace($PSBoundParameters['appInsightsStorageAccountName'])) -{ - Write-Output "Application Insights Storage Account Name: $($appInsightsStorageAccountName)" -} -else -{ - Write-Output "Application Insights Storage Account Name: []" -} #endregion \ No newline at end of file diff --git a/Modules/ApplicationInsights/2.0/Tests/test.parameters.json b/Modules/ApplicationInsights/2.0/Tests/test.parameters.json index f9369a7..9fffb96 100644 --- a/Modules/ApplicationInsights/2.0/Tests/test.parameters.json +++ b/Modules/ApplicationInsights/2.0/Tests/test.parameters.json @@ -4,10 +4,7 @@ "parameters": { "appInsightsName": { "value": "testappInsightsName" - }, - "storageAccountName": { - "value": "teststorageAccountName" - }, + }, "cuaId": { "value": "00000000-0000-0000-0000-000000000000" } diff --git a/Modules/ApplicationInsights/2.0/deploy.json b/Modules/ApplicationInsights/2.0/deploy.json index 42fc4ed..6f19c58 100644 --- a/Modules/ApplicationInsights/2.0/deploy.json +++ b/Modules/ApplicationInsights/2.0/deploy.json @@ -27,29 +27,6 @@ "description": "Optional. Location for all Resources" } }, - "storageAccountName": { - "type": "string", - "metadata": { - "description": "Required. Storage Account Name" - } - }, - "storageAccountsku": { - "type": "string", - "allowedValues": [ - "Standard_LRS", - "Standard_GRS", - "Standard_RAGRS", - "Standard_ZRS", - "Premium_LRS", - "Premium_ZRS", - "Standard_GZRS", - "Standard_RAGZRS" - ], - "defaultValue": "Standard_GRS", - "metadata": { - "description": "Optional. Storage Account sku type" - } - }, "cuaId": { "type": "string", "defaultValue": "", @@ -57,47 +34,18 @@ "description": "Optional. Customer Usage Attribution id (GUID). This GUID must be previously registered" } }, - "tagEnvironment": { - "type": "string", + "tagValues": { + "type": "object", "defaultValue": "", "metadata": { - "description": "Optional. The name of the Environment" - } - }, - "tagProject": { - "type": "string", - "defaultValue": "", - "metadata": { - "description": "Optional. The name of the project" - } - }, - "tagApplication": { - "type": "string", - "defaultValue": "", - "metadata": { - "description": "Optional. The name of the application" - } - }, - "tagOwner": { - "type": "string", - "defaultValue": "", - "metadata": { - "description": "Optional. The business owner for the application" - } - }, - "tagOwnerEmail": { - "type": "string", - "defaultValue": "", - "metadata": { - "description": "Optional. The Email address of the business owner for the application" + "description": "Optional. Azure Resource Tags object" } } }, "variables": { "appInsightsName": "[parameters('appInsightsName')]", "appInsightsresourceId": "[resourceId('Microsoft.Insights/components',parameters('appInsightsName'))]", - "apiVersion": "[providers('Microsoft.Insights','components').apiVersions[0]]", - "storageAccountName": "[parameters('storageAccountName')]", + "appInsightsApiVersion": "[providers('Microsoft.Insights','components').apiVersions[0]]", "pidName": "[concat('pid-',parameters('cuaId'))]" }, "resources": [ @@ -117,39 +65,14 @@ }, { "type": "Microsoft.Insights/components", - "apiVersion": "[providers('Microsoft.Insights','components').apiVersions[0]]", - "name": "[parameters('appInsightsName')]", + "apiVersion": "[variables('appInsightsApiVersion')]", + "name": "[variables('appInsightsName')]", "location": "[parameters('location')]", - "tags": { - "Environment": "[parameters('tagEnvironment')]", - "Application": "[parameters('tagApplication')]", - "Project": "[parameters('tagProject')]", - "Owner": "[parameters('tagOwner')]", - "OwnerEmail": "[parameters('tagOwnerEmail')]" - }, + "tags": "[if(empty(parameters('tagValues')), json('null'), parameters('tagValues'))]", "properties": { "ApplicationId": "[parameters('appInsightsName')]", "Application_Type": "[parameters('appInsightsType')]" } - }, - { - "type": "Microsoft.Storage/storageAccounts", - "apiVersion": "[providers('Microsoft.Storage','storageAccounts').apiVersions[0]]", - "name": "[parameters('storageAccountName')]", - "location": "[resourceGroup().location]", - "tags": { - "Environment": "[parameters('tagEnvironment')]", - "Application": "[parameters('tagApplication')]", - "Project": "[parameters('tagProject')]", - "Owner": "[parameters('tagOwner')]", - "OwnerEmail": "[parameters('tagOwnerEmail')]" - }, - "sku": { - "name": "[parameters('storageAccountSku')]" - }, - "properties": { - "supportsHttpsTrafficOnly": true - } } ], "outputs": { @@ -176,23 +99,16 @@ }, "appInsightsKey": { "type": "string", - "value": "[reference(variables('appInsightsresourceId'),variables('apiVersion')).instrumentationKey]", + "value": "[reference(variables('appInsightsresourceId'),variables('appInsightsApiVersion')).instrumentationKey]", "metadata": { "description": "Application Insights Resource Instrumentation Key" } }, "appInsightsAppId": { "type": "string", - "value": "[reference(variables('appInsightsresourceId'),variables('apiVersion')).AppId]", + "value": "[reference(variables('appInsightsresourceId'),variables('appInsightsApiVersion')).AppId]", "metadata": { - "description": "Application Insights Paalication Id" - } - }, - "appInsightsStorageAccountName": { - "type": "string", - "value": "[variables('storageAccountName')]", - "metadata": { - "description": "Application Insights Logging Storage Account Name" + "description": "Application Insights Application Id" } } } diff --git a/Modules/ApplicationInsights/2.0/readme.md b/Modules/ApplicationInsights/2.0/readme.md index b6433ac..d4918cc 100644 --- a/Modules/ApplicationInsights/2.0/readme.md +++ b/Modules/ApplicationInsights/2.0/readme.md @@ -6,9 +6,7 @@ This module deploys Application Insights. The following Resources are deployed. -+ **Microsoft.Insights/components** -+ **Microsoft.Storage/storageAccount** - ++ **Microsoft.Insights/components** ## Parameters @@ -17,14 +15,8 @@ The following Resources are deployed. | `appInsightsName` || **Required** | Name of the Application Insights | `appInsightsType` | web | **Optional** | Application type | `location` | resourceGroup().location | **Optional** | Location for all Resources -| `storageAccountName` || **Required** | Storage Account Name -| `storageAccountType` | Standard_GRS | **Optional** | Storage Account sku type | `cuaId` || **Optional** | Customer Usage Attribution Id (GUID). This GUID must be previously registered -| `tagEnvironment` || **Optional** | The name of the Environment -| `tagProject` || **Optional** | The name of the project -| `tagApplication` || **Optional** | The name of the application -| `tagOwner` || **Optional** | The business owner for the application -| `tagOwnerEmail` || **Optional** | The Email address of the business owner for the application +| `tagValues` || **Optional** | Optional. Azure Resource Tags object ## Outputs @@ -34,14 +26,12 @@ The following Resources are deployed. | `appInsightsResourceId` | Application Insights Resource Id | `appInsightsResourceGroup` | Application Insights ResourceGroup | `appInsightsKey` | Application Insights Resource Instrumentation Key -| `appInsightsAppId` | Application Insights Paalication Id -| `appInsightsStorageAccountName` | Application Insights Logging Storage Account Name +| `appInsightsAppId` | Application Insights Application Id ## Scripts | Output Name | Description | | :- | :- | -| `application.insights.akv.secrects.ps1` | Set Application Insights KeyVault Secrets Automation Script | `application.insights.continuous.export.ps1` | Configures Application Insights Continuous Export Configuration ## Considerations @@ -50,4 +40,4 @@ The following Resources are deployed. ## Additional resources -[Microsoft Insights template reference](https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/allversions) \ No newline at end of file +[Microsoft Insights template reference](https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/allversions)