Skip to content

Commit

Permalink
feat: Add lock support to avm/res/insights/component (App Insights)…
Browse files Browse the repository at this point in the history
… module (#4264)

## Description

The PR adds support for the `lock` property to the
`avm/res/insights/component` module.

Resolves #3944 

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.insights.component](https://github.com/krbar/bicep-registry-modules/actions/workflows/avm.res.insights.component.yml/badge.svg?branch=users%2Fkrbar%2FappInsightsUpdate)](https://github.com/krbar/bicep-registry-modules/actions/workflows/avm.res.insights.component.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [x] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [x] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [x] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [x] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
krbar authored Jan 22, 2025
1 parent 248befb commit 9e9b912
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
53 changes: 53 additions & 0 deletions avm/res/insights/component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This component deploys an Application Insights instance.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Insights/components` | [2020-02-02](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2020-02-02/components) |
| `microsoft.insights/components/linkedStorageAccounts` | [2020-03-01-preview](https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/2020-03-01-preview/components/linkedStorageAccounts) |
Expand Down Expand Up @@ -137,6 +138,10 @@ module component 'br/public:avm/res/insights/component:<version>' = {
forceCustomerStorageForProfiler: true
linkedStorageAccountResourceId: '<linkedStorageAccountResourceId>'
location: '<location>'
lock: {
kind: 'CanNotDelete'
name: 'myCustomLockName'
}
roleAssignments: [
{
name: '8aacced3-3fce-41bc-a416-959df1acec57'
Expand Down Expand Up @@ -216,6 +221,12 @@ module component 'br/public:avm/res/insights/component:<version>' = {
"location": {
"value": "<location>"
},
"lock": {
"value": {
"kind": "CanNotDelete",
"name": "myCustomLockName"
}
},
"roleAssignments": {
"value": [
{
Expand Down Expand Up @@ -281,6 +292,10 @@ param disableLocalAuth = true
param forceCustomerStorageForProfiler = true
param linkedStorageAccountResourceId = '<linkedStorageAccountResourceId>'
param location = '<location>'
param lock = {
kind: 'CanNotDelete'
name: 'myCustomLockName'
}
param roleAssignments = [
{
name: '8aacced3-3fce-41bc-a416-959df1acec57'
Expand Down Expand Up @@ -462,6 +477,7 @@ param tags = {
| [`kind`](#parameter-kind) | string | The kind of application that this component refers to, used to customize UI. This value is a freeform string, values should typically be one of the following: web, ios, other, store, java, phone. |
| [`linkedStorageAccountResourceId`](#parameter-linkedstorageaccountresourceid) | string | Linked storage account resource ID. |
| [`location`](#parameter-location) | string | Location for all Resources. |
| [`lock`](#parameter-lock) | object | The lock settings of the service. |
| [`publicNetworkAccessForIngestion`](#parameter-publicnetworkaccessforingestion) | string | The network access type for accessing Application Insights ingestion. - Enabled or Disabled. |
| [`publicNetworkAccessForQuery`](#parameter-publicnetworkaccessforquery) | string | The network access type for accessing Application Insights query. - Enabled or Disabled. |
| [`retentionInDays`](#parameter-retentionindays) | int | Retention period in days. |
Expand Down Expand Up @@ -699,6 +715,42 @@ Location for all Resources.
- Type: string
- Default: `[resourceGroup().location]`

### Parameter: `lock`

The lock settings of the service.

- Required: No
- Type: object

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`kind`](#parameter-lockkind) | string | Specify the type of lock. |
| [`name`](#parameter-lockname) | string | Specify the name of lock. |

### Parameter: `lock.kind`

Specify the type of lock.

- Required: No
- Type: string
- Allowed:
```Bicep
[
'CanNotDelete'
'None'
'ReadOnly'
]
```

### Parameter: `lock.name`

Specify the name of lock.

- Required: No
- Type: string

### Parameter: `publicNetworkAccessForIngestion`

The network access type for accessing Application Insights ingestion. - Enabled or Disabled.
Expand Down Expand Up @@ -896,6 +948,7 @@ This section gives you an overview of all local-referenced module files (i.e., o
| Reference | Type |
| :-- | :-- |
| `br/public:avm/utl/types/avm-common-types:0.3.0` | Remote reference |
| `br/public:avm/utl/types/avm-common-types:0.5.1` | Remote reference |

## Data Collection

Expand Down
15 changes: 15 additions & 0 deletions avm/res/insights/component/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ param kind string = ''
@description('Optional. Location for all Resources.')
param location string = resourceGroup().location

import { lockType } from 'br/public:avm/utl/types/avm-common-types:0.5.1'
@description('Optional. The lock settings of the service.')
param lock lockType?

import { roleAssignmentType } from 'br/public:avm/utl/types/avm-common-types:0.3.0'
@description('Optional. Array of role assignments to create.')
param roleAssignments roleAssignmentType[]?
Expand Down Expand Up @@ -181,6 +185,17 @@ resource appInsights_roleAssignments 'Microsoft.Authorization/roleAssignments@20
}
]

resource appInsights_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: appInsights
}

resource appInsights_diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [
for (diagnosticSetting, index) in (diagnosticSettings ?? []): {
name: diagnosticSetting.?name ?? '${name}-diagnosticSettings'
Expand Down
53 changes: 52 additions & 1 deletion avm/res/insights/component/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.32.4.45862",
"templateHash": "15805665300877328710"
"templateHash": "8234774084915355769"
},
"name": "Application Insights",
"description": "This component deploys an Application Insights instance."
Expand Down Expand Up @@ -134,6 +134,36 @@
}
}
},
"lockType": {
"type": "object",
"properties": {
"name": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. Specify the name of lock."
}
},
"kind": {
"type": "string",
"allowedValues": [
"CanNotDelete",
"None",
"ReadOnly"
],
"nullable": true,
"metadata": {
"description": "Optional. Specify the type of lock."
}
}
},
"metadata": {
"description": "An AVM-aligned type for a lock.",
"__bicep_imported_from!": {
"sourceTemplate": "br:mcr.microsoft.com/bicep/avm/utl/types/avm-common-types:0.5.1"
}
}
},
"roleAssignmentType": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -325,6 +355,13 @@
"description": "Optional. Location for all Resources."
}
},
"lock": {
"$ref": "#/definitions/lockType",
"nullable": true,
"metadata": {
"description": "Optional. The lock settings of the service."
}
},
"roleAssignments": {
"type": "array",
"items": {
Expand Down Expand Up @@ -442,6 +479,20 @@
"appInsights"
]
},
"appInsights_lock": {
"condition": "[and(not(empty(coalesce(parameters('lock'), createObject()))), not(equals(tryGet(parameters('lock'), 'kind'), 'None')))]",
"type": "Microsoft.Authorization/locks",
"apiVersion": "2020-05-01",
"scope": "[format('Microsoft.Insights/components/{0}', parameters('name'))]",
"name": "[coalesce(tryGet(parameters('lock'), 'name'), format('lock-{0}', parameters('name')))]",
"properties": {
"level": "[coalesce(tryGet(parameters('lock'), 'kind'), '')]",
"notes": "[if(equals(tryGet(parameters('lock'), 'kind'), 'CanNotDelete'), 'Cannot delete resource or child resources.', 'Cannot delete or modify the resource or child resources.')]"
},
"dependsOn": [
"appInsights"
]
},
"appInsights_diagnosticSettings": {
"copy": {
"name": "appInsights_diagnosticSettings",
Expand Down
4 changes: 4 additions & 0 deletions avm/res/insights/component/tests/e2e/max/main.test.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ module testDeployment '../../../main.bicep' = {
workspaceResourceId: diagnosticDependencies.outputs.logAnalyticsWorkspaceResourceId
}
]
lock: {
kind: 'CanNotDelete'
name: 'myCustomLockName'
}
roleAssignments: [
{
name: '8aacced3-3fce-41bc-a416-959df1acec57'
Expand Down
2 changes: 1 addition & 1 deletion avm/res/insights/component/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.4",
"version": "0.5",
"pathFilters": [
"./main.json"
]
Expand Down

0 comments on commit 9e9b912

Please sign in to comment.