Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.23k stars 748 forks source link

BCP135: Scope "resource" is not valid for Microsoft.Insights/diagnosticSettings #2366

Closed smokedlinq closed 3 years ago

smokedlinq commented 3 years ago

Bicep version Bicep CLI version 0.3.255 (589f0375df)

Describe the bug Trying to enable diagnosticSettings for the Microsoft.ApiManagement/service, it won't build with a scope set to the APIM resource, error message is:

Error BCP135: Scope "resource" is not valid for this resource type. Permitted scopes: "managementGroup".

I've always tried to use a module and the reference scope, so I'm pretty sure it isn't tied to the Microsoft.ApiManagement/service resource specifically but something with the Microsoft.Insights/diagnosticSettings resource type.

To Reproduce

param resourceId string
param workspaceId string

var resource = reference(resourceId)

resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2020-01-01-preview' = {
  scope: resource
  name: 'diagnostic-settings-to-log-analytics'
  properties: {
    workspaceId: workspaceId
    logs: [
      {
        category: 'GatewayLogs'
        enabled: true
        retentionPolicy: {
          enabled: true
          days: 0
        }
      }
    ]
  }
}

Additional context The full/old way of doing it works but bicep complains about it and suggests to use the scope feature instead.

smokedlinq commented 3 years ago

Switching the version to 2017-05-01-preview seems to resolve this. Intellisense is giving back the 2020-01-01-preview version which I just selected the most recent.

alex-frankel commented 3 years ago

@anthony-c-martin - I think you answered a similar question yesterday. Looks like in their most recent swagger they changed the valid scopes where this could be deployed. Anthony - did we open an issue in the swagger repo?

anthony-c-martin commented 3 years ago

Related to #2327. I'm not 100% clear whether this should be a Bicep fix or a swagger fix (or both). Seems like we could do a better job with the error message, and it's also perfectly valid (although perhaps unusual) to only increment the API version for a resource at a particular scope...

alex-frankel commented 3 years ago

it's also perfectly valid (although perhaps unusual) to only increment the API version for a resource at a particular scope...

Good point - should we somehow union all the scopes that are valid for all api versions?

alex-frankel commented 3 years ago

Going to close this and track with #2327. We will reach out to the Diagnostics team to see if this was an intentional change or is a bug.