Azure / Azure/bicep

Using Microsoft.Insights/components as resource-typed parameter generates invalid template

Open
#14,307 1 comment 1 reaction 0 assignees View on GitHub
Needs: Upvote story: resource typed params
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.28.1 (ba1e9f8c1e)

**Describe the bug**
Using `resourceTypedParamsAndOutputs` I have a template and a couple of modules which utilize parameters of type `resource`. It works for all other resource types I use except for the Application Insights resource `Microsoft.Insights/components@2020-02-02` which generates the following issue:

```
'The template resource 'Microsoft.Web/sites/foo-func-test' reference to 'Microsoft.Insights/components/foo-appi-test' requires an API version. Please see https://aka.ms/arm-syntax for usage details.'.
```

**To Reproduce**
The following is a shortened version of the pipeline:

main.bicep
```bicep
targetScope = 'subscription'

resource resourceGroup 'Microsoft.Resources/resourceGroups@2024-03-01' = {
name: 'foo-rg-test'
location: 'euwest'
}

module logAnalyticsWorkspace 'logAnalyticsWorkspace.bicep' = {
name: 'foo-log-test'
scope: resourceGroup
params: {
name: 'foo-log-test'
}
}

module functionApplicationInsights 'applicationInsights.bicep' = {
name: 'foo-appi-test'
scope: resourceGroup
params: {
name: 'foo-appi-test'
logAnalyticsWorkspaceId: logAnalyticsWorkspace.outputs.logAnalyticsWorkspace.id
}
}

module functionAppHostingPlan 'appServicePlan.bicep' = {
name: 'foo-asp-test'
scope: resourceGroup
params: {
name: 'foo-asp-test'
kind: 'functionapp'
sku: 'Y1'
}
}

module functionApp 'functionApp.bicep' = {
name: 'foo-func-test'
scope: resourceGroup
params: {
name: 'foo-func-test'
appServicePlan: functionAppHostingPlan.outputs.appServicePlan
applicationInsights: functionApplicationInsights.outputs.applicationInsights
}
}
```

functionApp.bicep
```bicep
param name string
param appServicePlan resource 'Microsoft.Web/serverfarms@2023-12-01'
param applicationInsights resource 'Microsoft.Insights/components@2020-02-02'

resource functionApp 'Microsoft.Web/sites@2023-12-01' = {
name: name
location: 'euwest'
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
enabled: true
serverFarmId: appServicePlan.id
httpsOnly: true
clientAffinityEnabled: false
publicNetworkAccess: 'Enabled'
redundancyMode: 'None'
siteConfig: {
minTlsVersion: '1.2'
http20Enabled: true
ftpsState: 'Disabled'
netFrameworkVersion: 'v8.0'
appSettings: [
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsights.properties.ConnectionString
}
// omitted storage config
]
}
}
}

output functionApp resource = functionApp
```

applicationInsights.bicep
```bicep
param name string
param logAnalyticsWorkspaceId string

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: name
location: 'euwest'
kind: 'web'
properties: {
Application_Type: 'web'
RetentionInDays: 90
WorkspaceResourceId: logAnalyticsWorkspaceId
}
}

output applicationInsights resource = applicationInsights
```

**Additional context**
Other modules needed for provisioning app service plans and log analytics workspace:

```bicep
param name string
param sku string
param kind string

resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = {
name: name
location: 'euwest'
sku: {
name: sku
}
kind: kind
}

output appServicePlan resource = appServicePlan
```

```bicep
param name string

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
name: name
location: 'euwest'
properties: {
retentionInDays: 30
sku: {
name: 'PerGB2018'
}
workspaceCapping: {
dailyQuotaGb: -1
}
}
}

output logAnalyticsWorkspace resource = logAnalyticsWorkspace
```

Doing the following adjustment to `functionApp.bicep` seems to work however:

```bicep
param applicationInsightsTemp resource 'Microsoft.Insights/components@2020-02-02'

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: applicationInsightsTemp.name
}
```

Contributor guide

Open the contributing guide

Research direction

Start with main.bicep, functionApp.bicep, and applicationInsights.bicep, focusing on resourceTypedParamsAndOutputs and the resource-typed Application Insights parameter. Reproduce with Bicep CLI 0.28.1 and inspect the generated template around the Microsoft.Web/sites reference. Done means the generated template is valid without requiring the existing-resource workaround, while preserving the other resource-typed parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.