Skip to content
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

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

Open
Smurfa opened this issue Jun 12, 2024 · 1 comment
Labels
Needs: Upvote This issue requires more votes to be considered story: resource typed params

Comments

@Smurfa
Copy link

Smurfa commented Jun 12, 2024

Bicep version
Bicep CLI version 0.28.1 (ba1e9f8)

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

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

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

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:

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
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:

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

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
  name: applicationInsightsTemp.name
}
@jeskew jeskew changed the title Using Microsoft.Insights/components as resource parameter generates invalid template Using Microsoft.Insights/components as resource-typed parameter generates invalid template Jun 14, 2024
@jeskew
Copy link
Contributor

jeskew commented Jun 14, 2024

Possibly related to #13835

@anthony-c-martin anthony-c-martin added Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Jun 19, 2024
@anthony-c-martin anthony-c-martin added this to the Committed Backlog milestone Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Upvote This issue requires more votes to be considered story: resource typed params
Projects
Status: Todo
Development

No branches or pull requests

3 participants